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.bukkit.generator; 020 021import com.plotsquared.core.PlotSquared; 022import com.plotsquared.core.generator.AugmentedUtils; 023import com.plotsquared.core.queue.QueueCoordinator; 024import com.sk89q.worldedit.bukkit.BukkitAdapter; 025import com.sk89q.worldedit.util.SideEffectSet; 026import org.bukkit.Chunk; 027import org.bukkit.World; 028import org.bukkit.generator.BlockPopulator; 029import org.checkerframework.checker.nullness.qual.NonNull; 030 031import java.util.Random; 032 033public class BukkitAugmentedGenerator extends BlockPopulator { 034 035 private static BukkitAugmentedGenerator generator; 036 037 public static BukkitAugmentedGenerator get(World world) { 038 for (BlockPopulator populator : world.getPopulators()) { 039 if (populator instanceof BukkitAugmentedGenerator) { 040 return (BukkitAugmentedGenerator) populator; 041 } 042 } 043 if (generator == null) { 044 generator = new BukkitAugmentedGenerator(); 045 } 046 world.getPopulators().add(generator); 047 return generator; 048 } 049 050 @Override 051 public void populate(@NonNull World world, @NonNull Random random, @NonNull Chunk source) { 052 QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(BukkitAdapter.adapt(world)); 053 // The chunk is already loaded and we do not want to load the chunk in "fully" by using any PaperLib methods. 054 queue.setForceSync(true); 055 queue.setSideEffectSet(SideEffectSet.none()); 056 queue.setBiomesEnabled(false); 057 queue.setChunkObject(source); 058 AugmentedUtils.generateChunk(world.getName(), source.getX(), source.getZ(), queue); 059 queue.enqueue(); 060 } 061 062}