From 1564b58a3dc464dd59f6bc348b545b8cef3796e1 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 17 Jul 2015 14:54:07 +1000 Subject: [PATCH] Optimize block physics event --- .../plot/flag/FlagManager.java | 19 ++++---- .../plot/listeners/PlayerEvents.java | 43 +++++++++---------- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 9b565ab08..092bfbba7 100644 --- a/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -122,12 +122,15 @@ public class FlagManager { } public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) { - Flag flag = settings.flags.get(id); - if (flag == null) { + Flag flag; + if (settings.flags.size() == 0 || (flag = settings.flags.get(id)) == null) { PlotWorld plotworld = PS.get().getPlotWorld(world); if (plotworld == null) { return null; } + if (plotworld.DEFAULT_FLAGS.size() == 0) { + return null; + } return ((HashMap) plotworld.DEFAULT_FLAGS.clone()).get(id); } return flag; @@ -160,13 +163,10 @@ public class FlagManager { return false; } final Flag flag = getPlotFlag(plot, strFlag); - if (flag == null) { + if (flag == null || !((Boolean) flag.getValue())) { return false; } - if (flag.getValue() instanceof Boolean) { - return (boolean) flag.getValue(); - } - return false; + return true; } public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) { @@ -174,12 +174,9 @@ public class FlagManager { return false; } final Flag flag = getPlotFlag(plot, strFlag); - if (flag == null) { + if (flag == null || ((Boolean) flag.getValue())) { return false; } - if (flag.getValue() instanceof Boolean) { - return !(boolean) flag.getValue(); - } return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 2cd12aa04..24eeb733e 100644 --- a/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -207,42 +207,39 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } } - @EventHandler + @EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST) public void onPhysicsEvent(BlockPhysicsEvent event) { - Block block = event.getBlock(); - Location loc = BukkitUtil.getLocation(block.getLocation()); - if (!PS.get().isPlotWorld(loc.getWorld())) { - return; - } - switch (block.getType()) { - case REDSTONE_COMPARATOR_OFF: - case REDSTONE_COMPARATOR_ON: { + switch (event.getChangedTypeId()) { + case 149: + case 150: { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); Plot plot = MainUtil.getPlot(loc); if (plot == null) { return; } - Flag redstone = FlagManager.getPlotFlag(plot, "redstone"); - if (redstone == null || (Boolean) redstone.getValue()) { - return; - } - if (!MainUtil.isPlotArea(plot)) { + if (FlagManager.isPlotFlagTrue(plot, "redstone")) { return; } event.setCancelled(true); return; } + case 122: + case 145: + case 12: + case 13: { + Block block = event.getBlock(); + Location loc = BukkitUtil.getLocation(block.getLocation()); + Plot plot = MainUtil.getPlot(loc); + if (plot != null && FlagManager.isPlotFlagTrue(plot, "disable-physics")) { + event.setCancelled(true); + return; + } + return; + } default: { - break; - } - } - if (block.getType().hasGravity()) { - Plot plot = MainUtil.getPlot(loc); - if (plot == null) { return; } - if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) { - event.setCancelled(true); - } } }