diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/CleanSuperFlatListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/CleanSuperFlatListener.java index e4019045e..e3de001b5 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/CleanSuperFlatListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/CleanSuperFlatListener.java @@ -3,6 +3,9 @@ */ package world.bentobox.bentobox.listeners.flags; +import java.util.HashSet; +import java.util.Set; + import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; @@ -13,6 +16,7 @@ import org.bukkit.event.world.ChunkLoadEvent; import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.flags.FlagListener; import world.bentobox.bentobox.lists.Flags; +import world.bentobox.bentobox.util.Pair; /** * Cleans super-flat world chunks or normal nether chunks if they generate accidentally @@ -21,17 +25,26 @@ import world.bentobox.bentobox.lists.Flags; * */ public class CleanSuperFlatListener extends FlagListener { + + private Set> regeneratedChunk = new HashSet<>(); + @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onChunkLoad(ChunkLoadEvent e) { BentoBox plugin = BentoBox.getInstance(); World world = e.getWorld(); + if (regeneratedChunk.contains(new Pair(e.getChunk().getX(), e.getChunk().getZ()))) { + Flags.CLEAN_SUPER_FLAT.setSetting(world, false); + plugin.logError("World generator for " + world.getName() + " is broken and superflat regen cannot occur!!! Disabling regen."); + return; + } if (!e.getChunk().getBlock(0, 0, 0).getType().equals(Material.BEDROCK) || !Flags.CLEAN_SUPER_FLAT.isSetForWorld(world) || (world.getEnvironment().equals(Environment.NETHER) && (!plugin.getIWM().isNetherGenerate(world) || !plugin.getIWM().isNetherIslands(world))) || (world.getEnvironment().equals(Environment.THE_END) && (!plugin.getIWM().isEndGenerate(world) || !plugin.getIWM().isEndIslands(world)))) { return; } + // This deprecation is OK because all it means is that things like tree leaves may not be the same in the chunk when it is generated world.regenerateChunk(e.getChunk().getX(), e.getChunk().getZ()); plugin.logWarning("Regenerating superflat chunk in " + world.getName() + " at blocks " + (e.getChunk().getX() << 4) + "," + (e.getChunk().getZ() << 4)); diff --git a/src/main/java/world/bentobox/bentobox/util/Pair.java b/src/main/java/world/bentobox/bentobox/util/Pair.java index aa6e55e6d..09b8cac74 100644 --- a/src/main/java/world/bentobox/bentobox/util/Pair.java +++ b/src/main/java/world/bentobox/bentobox/util/Pair.java @@ -1,6 +1,13 @@ package world.bentobox.bentobox.util; +/** + * Class to store pairs of objects, e.g. coordinates + * @author tastybento + * + * @param the x part of the pair + * @param the z part of the pair + */ public class Pair { public final X x; public final Z z;