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..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 @@ -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,16 @@ 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 { areaName = world.getName(); hasPlotArea = PlotSquared.get().hasPlotArea(areaName); } - if (!hasPlotArea) + if (!hasPlotArea) { return; + } test(entity); } @@ -76,15 +77,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 +143,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); } } 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 1fcbd3005..3e9ba35ce 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 @@ -1709,6 +1709,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); @@ -1719,6 +1722,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 { @@ -1804,6 +1810,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; } @@ -2346,7 +2355,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(); } /**