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.plotsquared.core.PlotSquared;
022import com.plotsquared.core.plot.PlotArea;
023import com.plotsquared.core.plot.PlotId;
024import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
025import com.plotsquared.core.setup.PlotAreaBuilder;
026import com.sk89q.worldedit.world.biome.BiomeType;
027import org.checkerframework.checker.nullness.qual.NonNull;
028
029/**
030 * This class allows for implementation independent world generation.
031 * - Sponge/Bukkit API
032 * Use the specify method to get the generator for that platform.
033 */
034public abstract class IndependentPlotGenerator {
035
036    /**
037     * Get the name of this generator.
038     *
039     * @return generator name
040     */
041    public abstract String getName();
042
043    /**
044     * Generate chunk block data
045     *
046     * @param result   Queue to write to
047     * @param settings PlotArea (settings)
048     * @param biomes   If biomes should be generated
049     * @since 7.0.0
050     */
051    public abstract void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings, boolean biomes);
052
053    /**
054     * Populate a chunk-queue with tile entities, entities, etc.
055     *
056     * @param result  Queue to write to
057     * @param setting PlotArea (settings)
058     * @since 7.0.0
059     */
060    public void populateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea setting) {
061    }
062
063    /**
064     * Return a new PlotArea object.
065     *
066     * @param world world name
067     * @param id    (May be null) Area name
068     * @param min   Min plot id (may be null)
069     * @param max   Max plot id (may be null)
070     * @return new plot area
071     */
072    public abstract PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max);
073
074    /**
075     * If any additional setup options need to be changed before world creation.
076     * - e.g. If setup doesn't support some standard options
077     *
078     * @param builder the area builder to modify
079     */
080    public void processAreaSetup(PlotAreaBuilder builder) {
081    }
082
083    /**
084     * It is preferred for the PlotArea object to do most of the initialization necessary.
085     *
086     * @param area area
087     */
088    public abstract void initialize(PlotArea area);
089
090    /**
091     * Get the generator for your specific implementation (bukkit/sponge).<br>
092     * - e.g. YourIndependentGenerator.&lt;ChunkGenerator&gt;specify() - Would return a ChunkGenerator object<br>
093     *
094     * @param <T>   world
095     * @param world ChunkGenerator Implementation
096     * @return Chunk generator
097     */
098    @SuppressWarnings("unchecked")
099    public <T> GeneratorWrapper<T> specify(final @NonNull String world) {
100        return (GeneratorWrapper<T>) PlotSquared.platform().wrapPlotGenerator(world, this);
101    }
102
103    /**
104     * Get the biome to be generated at a specific point
105     *
106     * @param settings PlotArea settings to provide biome
107     * @param x        World x position
108     * @param y        World y position
109     * @param z        World z position
110     * @return Biome type to be generated
111     * @since 7.0.0
112     */
113    public abstract BiomeType getBiome(PlotArea settings, int x, int y, int z);
114
115    @Override
116    public String toString() {
117        return getName();
118    }
119
120}