PlotSquared/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java

63 lines
2.5 KiB
Java
Raw Normal View History

/*
* PlotSquared, a land and world management plugin for Minecraft.
* Copyright (C) IntellectualSites <https://intellectualsites.com>
* Copyright (C) IntellectualSites team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-04-11 02:19:18 +02:00
package com.plotsquared.bukkit.generator;
2016-02-10 19:59:51 +01:00
import com.plotsquared.core.PlotSquared;
2020-04-15 21:26:54 +02:00
import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.queue.QueueCoordinator;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.SideEffectSet;
2016-02-10 19:59:51 +01:00
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.checkerframework.checker.nullness.qual.NonNull;
2016-02-10 19:59:51 +01:00
2016-02-19 17:55:00 +01:00
import java.util.Random;
2016-02-10 19:59:51 +01:00
public class BukkitAugmentedGenerator extends BlockPopulator {
2018-08-10 17:01:10 +02:00
2016-02-10 19:59:51 +01:00
private static BukkitAugmentedGenerator generator;
2016-02-19 17:55:00 +01:00
2016-02-10 19:59:51 +01:00
public static BukkitAugmentedGenerator get(World world) {
2016-02-19 17:55:00 +01:00
for (BlockPopulator populator : world.getPopulators()) {
if (populator instanceof BukkitAugmentedGenerator) {
return (BukkitAugmentedGenerator) populator;
2016-02-10 19:59:51 +01:00
}
}
if (generator == null) {
generator = new BukkitAugmentedGenerator();
}
world.getPopulators().add(generator);
return generator;
}
@Override
public void populate(@NonNull World world, @NonNull Random random, @NonNull Chunk source) {
QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(BukkitAdapter.adapt(world));
// The chunk is already loaded and we do not want to load the chunk in "fully" by using any PaperLib methods.
queue.setForceSync(true);
queue.setSideEffectSet(SideEffectSet.none());
queue.setBiomesEnabled(false);
queue.setChunkObject(source);
AugmentedUtils.generateChunk(world.getName(), source.getX(), source.getZ(), queue);
queue.enqueue();
2016-02-10 19:59:51 +01:00
}
2016-02-10 19:59:51 +01:00
}