From 480453b716bcd8e6a7f03a7eebfde204fe27867e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 16 Jun 2016 20:16:48 +1000 Subject: [PATCH] Various Fixes #1177 Additional check for left click with milk on adult entity Add setting for enabling persistent meta Only set fly persistent meta if it differs from the current gamemode fly mode. --- .../bukkit/listeners/PlayerEvents.java | 14 ++++---- .../plot/config/Settings.java | 2 ++ .../plot/object/PlotPlayer.java | 22 ++++++++----- .../plot/util/expiry/ExpireManager.java | 32 +++++++++++++------ .../plotsquared/listener/PlotListener.java | 19 +++++++---- 5 files changed, 58 insertions(+), 31 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 18db8f69b..9fbc6f7bf 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -2102,14 +2102,16 @@ public class PlayerEvents extends PlotListener implements Listener { } Entity victim = event.getEntity(); if (!entityDamage(damager, victim)) { - event.setCancelled(true); - if (victim instanceof Ageable) { - Ageable ageable = (Ageable) victim; - if (ageable.getAge() == -24000) { - ageable.setAge(0); - ageable.setAdult(); + if (event.isCancelled()) { + if (victim instanceof Ageable) { + Ageable ageable = (Ageable) victim; + if (ageable.getAge() == -24000) { + ageable.setAge(0); + ageable.setAdult(); + } } } + event.setCancelled(true); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index b18c3f76e..a5b93dfc3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -285,6 +285,8 @@ public class Settings extends Config { public static boolean UUID_CACHE = true; @Comment("Notify players of updates") public static boolean UPDATER = true; + @Comment("Stores user metadata in a database") + public static boolean PERSISTENT_META = true; @Comment("Optimizes permission checks") public static boolean PERMISSION_CACHE = true; @Comment("Optimizes block changing code") diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index a96330394..4b7725827 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -415,12 +415,14 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { } public void populatePersistentMetaMap() { - DBFunc.getPersistentMeta(getUUID(), new RunnableVal>() { - @Override - public void run(Map value) { - PlotPlayer.this.metaMap = value; - } - }); + if (Settings.Enabled_Components.PERSISTENT_META) { + DBFunc.getPersistentMeta(getUUID(), new RunnableVal>() { + @Override + public void run(Map value) { + PlotPlayer.this.metaMap = value; + } + }); + } } public byte[] getPersistentMeta(String key) { @@ -431,13 +433,17 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { if (this.metaMap.containsKey(key)) { this.metaMap.remove(key); } - DBFunc.removePersistentMeta(getUUID(), key); + if (Settings.Enabled_Components.PERSISTENT_META) { + DBFunc.removePersistentMeta(getUUID(), key); + } } public void setPersistentMeta(String key, byte[] value) { boolean delete = hasPersistentMeta(key); this.metaMap.put(key, value); - DBFunc.addPersistentMeta(getUUID(), key, value, delete); + if (Settings.Enabled_Components.PERSISTENT_META) { + DBFunc.addPersistentMeta(getUUID(), key, value, delete); + } } public boolean hasPersistentMeta(String key) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java index ce4f84653..a67a95bed 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/expiry/ExpireManager.java @@ -57,9 +57,13 @@ public class ExpireManager { } public void handleEntry(PlotPlayer pp, Plot plot) { - if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear") && plotsToDelete.contains(plot) && !isExpired(new ArrayDeque<>(tasks), plot).isEmpty()) { - plotsToDelete.remove(plot); - confirmExpiry(pp); + if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear") && plotsToDelete.contains(plot)) { + if (!isExpired(new ArrayDeque<>(tasks), plot).isEmpty()) { + confirmExpiry(pp); + } else { + plotsToDelete.remove(plot); + confirmExpiry(pp); + } } } @@ -69,29 +73,37 @@ public class ExpireManager { } public void confirmExpiry(final PlotPlayer pp) { - if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp - .hasPermission("plots.admin.command.autoclear")) { + if (pp.getMeta("ignoreExpireTask") != null) { + return; + } + if (plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) { final int num = plotsToDelete.size(); - for (final Plot current : plotsToDelete) { + while (!plotsToDelete.isEmpty()) { + Iterator iter = plotsToDelete.iterator(); + final Plot current = iter.next(); if (!isExpired(new ArrayDeque<>(tasks), current).isEmpty()) { TaskManager.runTask(new Runnable() { @Override public void run() { + pp.setMeta("ignoreExpireTask", true); pp.teleport(current.getCenter()); + pp.deleteMeta("ignoreExpireTask"); PlotMessage msg = new PlotMessage() - .text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired:").color("$1").command("/plot list expired") + .text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired: ").color("$1").text(current.toString()).color("$2").suggest("/plot list expired") .tooltip("/plot list expired") //.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired") - .text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete") + .text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").suggest("/plot delete") .tooltip("/plot delete") - .text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").command("/plot set keep 1d") + .text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").suggest("/plot set keep 1d") .tooltip("/plot set keep 1d") - .text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").command("/plot set keep true") + .text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").suggest("/plot set keep true") .tooltip("/plot set keep true"); msg.send(pp); } }); return; + } else { + iter.remove(); } } plotsToDelete.clear(); diff --git a/Core/src/main/java/com/plotsquared/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/listener/PlotListener.java index e7d5666df..65778c9c1 100644 --- a/Core/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/listener/PlotListener.java @@ -72,6 +72,17 @@ public class PlotListener { } } } + Optional flyFlag = plot.getFlag(Flags.FLY); + if (flyFlag.isPresent()) { + boolean flight = player.getFlight(); + if (flyFlag.get() != player.getFlight()) { + PlotGameMode gamemode = player.getGameMode(); + if (flight != (gamemode == PlotGameMode.CREATIVE || gamemode == PlotGameMode.SPECTATOR)) { + player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight())); + } + player.setFlight(flyFlag.get()); + } + } Optional gamemodeFlag = plot.getFlag(Flags.GAMEMODE); if (gamemodeFlag.isPresent()) { if (player.getGameMode() != gamemodeFlag.get()) { @@ -83,13 +94,6 @@ public class PlotListener { } } } - Optional flyFlag = plot.getFlag(Flags.FLY); - if (flyFlag.isPresent()) { - if (flyFlag.get() != player.getFlight()) { - player.setPersistentMeta("flight", ByteArrayUtilities.booleanToBytes(player.getFlight())); - player.setFlight(flyFlag.get()); - } - } Optional timeFlag = plot.getFlag(Flags.TIME); if (timeFlag.isPresent()) { try { @@ -200,6 +204,7 @@ public class PlotListener { if (plot.getFlag(Flags.FLY).isPresent()) { if (player.hasPersistentMeta("flight")) { player.setFlight(ByteArrayUtilities.bytesToBoolean(player.getPersistentMeta("flight"))); + player.removePersistentMeta("flight"); } else { PlotGameMode gameMode = player.getGameMode(); if (gameMode == PlotGameMode.SURVIVAL || gameMode == PlotGameMode.ADVENTURE) {