From b99631f1bd727b52efb149c78fb3cf6a27ac2c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Mon, 24 Feb 2020 14:00:45 +0100 Subject: [PATCH] Fix regen. Fixes #2692 --- .../plotsquared/bukkit/BukkitMain.java | 4 ++-- .../bukkit/generator/BukkitPlotGenerator.java | 11 ++++++++++- .../plotsquared/plot/generator/HybridGen.java | 7 ++++++- .../plotsquared/plot/util/world/OperationUtil.java | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 413d520af..e893d9122 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -646,7 +646,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain } return new BukkitPlotGenerator(world, gen); } else { - return new BukkitPlotGenerator(PlotSquared.get().IMP.getDefaultGenerator()); + return new BukkitPlotGenerator(world, PlotSquared.get().IMP.getDefaultGenerator()); } } @@ -802,7 +802,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain @Override public GeneratorWrapper wrapPlotGenerator(@Nullable final String world, @NonNull final IndependentPlotGenerator generator) { - return new BukkitPlotGenerator(generator); + return new BukkitPlotGenerator(world, generator); } @Override public List, Boolean>> getPluginIds() { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 6742167ce..ffa585ff6 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -12,6 +12,7 @@ import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; import com.sk89q.worldedit.math.BlockVector2; +import lombok.Getter; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; @@ -34,10 +35,13 @@ public class BukkitPlotGenerator extends ChunkGenerator private List populators; private boolean loaded = false; - public BukkitPlotGenerator(IndependentPlotGenerator generator) { + @Getter private final String levelName; + + public BukkitPlotGenerator(String name, IndependentPlotGenerator generator) { if (generator == null) { throw new IllegalArgumentException("Generator may not be null!"); } + this.levelName = name; this.plotGenerator = generator; this.platformGenerator = this; this.populators = new ArrayList<>(); @@ -51,6 +55,7 @@ public class BukkitPlotGenerator extends ChunkGenerator throw new IllegalArgumentException("ChunkGenerator: " + cg.getClass().getName() + " is already a BukkitPlotGenerator!"); } + this.levelName = world; this.full = false; this.platformGenerator = cg; this.plotGenerator = new DelegatePlotGenerator(cg, world); @@ -172,6 +177,10 @@ public class BukkitPlotGenerator extends ChunkGenerator return; } PlotArea area = PlotSquared.get().getPlotArea(world.getName(), null); + if (area == null && (area = PlotSquared.get().getPlotArea(this.levelName, null)) == null) { + throw new IllegalStateException("Cannot regenerate chunk that does not belong to a plot area." + + " Location: " + loc + ", world: " + world); + } try { this.plotGenerator.generateChunk(result, area); } catch (Throwable e) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java index 7fbf5c0ae..5efd5b6d4 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java @@ -7,8 +7,10 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotArea; import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue; +import com.google.common.base.Preconditions; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; +import org.jetbrains.annotations.NotNull; public class HybridGen extends IndependentPlotGenerator { @@ -34,7 +36,10 @@ public class HybridGen extends IndependentPlotGenerator { } } - @Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) { + @Override public void generateChunk(@NotNull ScopedLocalBlockQueue result, @NotNull PlotArea settings) { + Preconditions.checkNotNull(result, "result cannot be null"); + Preconditions.checkNotNull(settings, "settings cannot be null"); + HybridPlotWorld hpw = (HybridPlotWorld) settings; // Biome result.fillBiome(hpw.PLOT_BIOME); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java index 2cb336f52..9b2294a49 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/world/OperationUtil.java @@ -86,7 +86,7 @@ public class OperationUtil { return weWorld; } - private static EditSession createEditSession(PlotPlayer plotPlayer) { + private static EditSession createEditSession(PlotPlayer plotPlayer) { Actor actor = plotPlayer.toActor(); World weWorld = getWorld(plotPlayer, actor); return createEditSession(weWorld, actor); @@ -100,7 +100,7 @@ public class OperationUtil { return createEditSession(world, actor, getSession(actor)); } - private static EditSession createEditSession(World world, Actor actor, LocalSession session) { + private static EditSession createEditSession(World world, Actor actor, LocalSession session) { EditSession editSession; Player player = actor.isPlayer() ? (Player) actor : null; editSession = WorldEdit.getInstance().getEditSessionFactory()