From e4a6bd0ca58ec6e976cdbaca714a272259687e0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 7 Apr 2020 20:56:43 +0200 Subject: [PATCH 1/3] Don't try to remove players. Fixes #2742. --- .../bukkit/listeners/EntitySpawnListener.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java index 0c5ce4fd3..5fade4edb 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java @@ -39,7 +39,7 @@ public class EntitySpawnListener implements Listener { private static boolean hasPlotArea = false; private static String areaName = null; - public static void testNether(Entity entity) { + public static void testNether(final Entity entity) { @NotNull World world = entity.getWorld(); if (world.getEnvironment() != World.Environment.NETHER && world.getEnvironment() != World.Environment.THE_END) { @@ -48,15 +48,15 @@ public class EntitySpawnListener implements Listener { test(entity); } - public static void testCreate(Entity entity) { + public static void testCreate(final Entity entity) { @NotNull World world = entity.getWorld(); - if (areaName == world.getName()) { - } else { + if (!areaName.equals(world.getName())) { areaName = world.getName(); hasPlotArea = PlotSquared.get().hasPlotArea(areaName); } - if (!hasPlotArea) + if (!hasPlotArea) { return; + } test(entity); } @@ -76,15 +76,21 @@ public class EntitySpawnListener implements Listener { if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) { try { ignoreTP = true; - PaperLib.teleportAsync(entity,origin); + PaperLib.teleportAsync(entity, origin); } finally { ignoreTP = false; } + if (entity.getType() == EntityType.PLAYER) { + return; + } if (entity.getLocation().getWorld().equals(world)) { entity.remove(); } } } else { + if (entity.getType() == EntityType.PLAYER) { + return; + } entity.remove(); } } @@ -136,7 +142,7 @@ public class EntitySpawnListener implements Listener { @EventHandler public void onChunkLoad(ChunkLoadEvent event) { @NotNull Chunk chunk = event.getChunk(); - for (Entity entity : chunk.getEntities()) { + for (final Entity entity : chunk.getEntities()) { testCreate(entity); } } From 5e2e4a8631c6c2c81bd655056fae77d170388cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 7 Apr 2020 21:43:32 +0200 Subject: [PATCH 2/3] Revert testCreate change --- .../plotsquared/bukkit/listeners/EntitySpawnListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java index 5fade4edb..8aa7a16a9 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/EntitySpawnListener.java @@ -50,7 +50,8 @@ public class EntitySpawnListener implements Listener { public static void testCreate(final Entity entity) { @NotNull World world = entity.getWorld(); - if (!areaName.equals(world.getName())) { + if (areaName == world.getName()) { + } else { areaName = world.getName(); hasPlotArea = PlotSquared.get().hasPlotArea(areaName); } From e161209a46728f03879caaa047fdc97bfbd83bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 7 Apr 2020 22:12:52 +0200 Subject: [PATCH 3/3] Fix plot claiming --- .../plotsquared/plot/commands/Claim.java | 15 ++++++++--- .../plotsquared/plot/database/SQLManager.java | 1 - .../plotsquared/plot/object/Plot.java | 27 ++++++++++++++++--- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java index 3a17fb183..559df28ef 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Claim.java @@ -101,8 +101,12 @@ public class Claim extends SubCommand { final String finalSchematic = schematic; DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { - plot.claim(player, true, finalSchematic); - if (area.isAutoMerge()) { + if (!plot.claim(player, true, finalSchematic)) { + PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + + String.format("Failed to claim plot %s", plot.getId().toCommaSeparatedString())); + sendMessage(player, Captions.PLOT_NOT_CLAIMED); + plot.owner = null; + } else if (area.isAutoMerge()) { PlotMergeEvent event = PlotSquared.get().getEventDispatcher() .callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); if (event.getEventResult() == Result.DENY) { @@ -112,7 +116,12 @@ public class Claim extends SubCommand { } } } - }), () -> sendMessage(player, Captions.PLOT_NOT_CLAIMED)); + }), () -> { + PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + + String.format("Failed to add plot %s to the database", plot.getId().toCommaSeparatedString())); + sendMessage(player, Captions.PLOT_NOT_CLAIMED); + plot.owner = null; + }); return true; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java index ee4bf35fa..b3d52a114 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/database/SQLManager.java @@ -978,7 +978,6 @@ import java.util.concurrent.atomic.AtomicInteger; } public void createPlotSafe(final Plot plot, final Runnable success, final Runnable failure) { - final long timestamp = plot.getTimestamp(); addPlotTask(plot, new UniqueStatement("createPlotSafe_" + plot.hashCode()) { @Override public void set(PreparedStatement statement) throws SQLException { statement.setInt(1, plot.getId().x); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 4aac2dd11..17d857ed2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -1,7 +1,6 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.PlotSquared; -import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.Settings; @@ -19,7 +18,14 @@ import com.github.intellectualsites.plotsquared.plot.generator.SquarePlotWorld; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; -import com.github.intellectualsites.plotsquared.plot.util.*; +import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; +import com.github.intellectualsites.plotsquared.plot.util.MainUtil; +import com.github.intellectualsites.plotsquared.plot.util.MathMan; +import com.github.intellectualsites.plotsquared.plot.util.Permissions; +import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; +import com.github.intellectualsites.plotsquared.plot.util.TaskManager; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; +import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; @@ -1581,6 +1587,9 @@ public class Plot { public boolean claim(final PlotPlayer player, boolean teleport, String schematic) { if (!canClaim(player)) { + PlotSquared.debug(Captions.PREFIX.getTranslated() + + String.format("Player %s attempted to claim plot %s, but was not allowed", + player.getName(), this.getId().toCommaSeparatedString())); return false; } return claim(player, teleport, schematic, true); @@ -1591,6 +1600,9 @@ public class Plot { if (updateDB) { if (!create(player.getUUID(), true)) { + PlotSquared.debug(Captions.PREFIX.getTranslated() + + String.format("Player %s attempted to claim plot %s, but the database failed to update", + player.getName(), this.getId().toCommaSeparatedString())); return false; } } else { @@ -1676,6 +1688,9 @@ public class Plot { }); return true; } + PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + + String.format("Failed to add plot %s to plot area %s", this.getId().toCommaSeparatedString(), + this.area.toString())); return false; } @@ -2212,7 +2227,13 @@ public class Plot { return false; } } - return this.guessOwner() == null && !isMerged(); + final UUID owner = this.guessOwner(); + if (owner != null) { + if (player == null || !player.getUUID().equals(owner)) { + return false; + } + } + return !isMerged(); } /**