001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.generator;
020
021import com.google.inject.Inject;
022import com.plotsquared.core.location.Location;
023import com.plotsquared.core.plot.PlotArea;
024import com.plotsquared.core.plot.PlotId;
025import com.plotsquared.core.plot.world.PlotAreaManager;
026import com.plotsquared.core.plot.world.SinglePlotArea;
027import com.plotsquared.core.plot.world.SinglePlotAreaManager;
028import com.plotsquared.core.queue.ScopedQueueCoordinator;
029import com.sk89q.worldedit.world.biome.BiomeTypes;
030import com.sk89q.worldedit.world.block.BlockTypes;
031import org.checkerframework.checker.nullness.qual.NonNull;
032
033public class SingleWorldGenerator extends IndependentPlotGenerator {
034
035    private static final Location bedrock1 = Location.at("", 0, 0, 0);
036    private static final Location bedrock2 = Location.at("", 15, 0, 15);
037    private static final Location dirt1 = Location.at("", 0, 1, 0);
038    private static final Location dirt2 = Location.at("", 15, 2, 15);
039    private static final Location grass1 = Location.at("", 0, 3, 0);
040    private static final Location grass2 = Location.at("", 15, 3, 15);
041
042    private final PlotAreaManager plotAreaManager;
043
044    @Inject
045    public SingleWorldGenerator(final @NonNull PlotAreaManager plotAreaManager) {
046        this.plotAreaManager = plotAreaManager;
047    }
048
049    @Override
050    public String getName() {
051        return "PlotSquared:single";
052    }
053
054    @Override
055    public void generateChunk(ScopedQueueCoordinator result, PlotArea settings) {
056        SinglePlotArea area = (SinglePlotArea) settings;
057        if (area.VOID) {
058            Location min = result.getMin();
059            if (min.getX() == 0 && min.getZ() == 0) {
060                result.setBlock(0, 0, 0, BlockTypes.BEDROCK.getDefaultState());
061            }
062        } else {
063            result.setCuboid(bedrock1, bedrock2, BlockTypes.BEDROCK.getDefaultState());
064            result.setCuboid(dirt1, dirt2, BlockTypes.DIRT.getDefaultState());
065            result.setCuboid(grass1, grass2, BlockTypes.GRASS_BLOCK.getDefaultState());
066        }
067        result.fillBiome(BiomeTypes.PLAINS);
068    }
069
070    @Override
071    public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
072        return ((SinglePlotAreaManager) this.plotAreaManager).getArea();
073    }
074
075    @Override
076    public void initialize(PlotArea area) {
077    }
078
079}