From f4f48b2c47ad9c379824df2227235fce4af6889a Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Mon, 12 Feb 2018 00:00:23 +0100 Subject: [PATCH] Fix sign protection. Resolves #246; resolves #215. Thx @kuohsuanlo! --- .../global/GlobalProtectionListener.java | 17 +++++++++-------- .../dre2n/dungeonsxl/world/DGameWorld.java | 3 ++- .../dre2n/dungeonsxl/world/DWorldListener.java | 13 +++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java index 9d821a9a..8291b7ed 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GlobalProtectionListener.java @@ -29,6 +29,7 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPhysicsEvent; @@ -47,7 +48,7 @@ public class GlobalProtectionListener implements Listener { DungeonsXL plugin = DungeonsXL.getInstance(); - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreakWithSignOnIt(BlockBreakEvent event) { Block block = event.getBlock(); Player player = event.getPlayer(); @@ -71,7 +72,7 @@ public class GlobalProtectionListener implements Listener { event.setCancelled(bbe.isCancelled()); } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); Player player = event.getPlayer(); @@ -85,21 +86,21 @@ public class GlobalProtectionListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockSpread(BlockSpreadEvent event) { if (DPortal.getByBlock(event.getBlock()) != null) { event.setCancelled(true); } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockPhysics(BlockPhysicsEvent event) { if (DPortal.getByBlock(event.getBlock()) != null) { event.setCancelled(true); } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent event) { List blocklist = event.blockList(); for (Block block : blocklist) { @@ -138,7 +139,7 @@ public class GlobalProtectionListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPortalCreation(PlayerInteractEvent event) { DGlobalPlayer dPlayer = plugin.getDPlayers().getByPlayer(event.getPlayer()); if (!dPlayer.isCreatingPortal()) { @@ -174,7 +175,7 @@ public class GlobalProtectionListener implements Listener { /* SUBJECT TO CHANGE */ @Deprecated - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (plugin.getDPlayers().getByPlayer(player).isInBreakMode()) { @@ -205,7 +206,7 @@ public class GlobalProtectionListener implements Listener { } @Deprecated - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onSignChange(SignChangeEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java b/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java index 7f5d77ee..b5666d81 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/DGameWorld.java @@ -16,6 +16,7 @@ */ package io.github.dre2n.dungeonsxl.world; +import io.github.dre2n.commons.misc.BlockUtil; import io.github.dre2n.commons.misc.FileUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; @@ -549,7 +550,7 @@ public class DGameWorld extends DInstanceWorld { Player player = event.getPlayer(); Block block = event.getBlock(); for (DSign dSign : dSigns) { - if (block.equals(dSign.getSign().getBlock()) && dSign.getType().isProtected()) { + if ((block.equals(dSign.getSign().getBlock()) || block.equals(BlockUtil.getAttachedBlock(dSign.getSign().getBlock()))) && dSign.getType().isProtected()) { return true; } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java b/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java index 41e1f823..0c48a380 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/world/DWorldListener.java @@ -20,6 +20,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockIgniteEvent; @@ -42,7 +43,7 @@ public class DWorldListener implements Listener { this.dWorlds = dWorlds; } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock(); // DEditWorld Signs @@ -61,7 +62,7 @@ public class DWorldListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockPlace(BlockPlaceEvent event) { Block block = event.getBlock(); @@ -75,7 +76,7 @@ public class DWorldListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockIgnite(BlockIgniteEvent event) { if (dWorlds.getInstanceByWorld(event.getBlock().getWorld()) == null) { return; @@ -86,7 +87,7 @@ public class DWorldListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockSpread(BlockSpreadEvent event) { Block block = event.getSource(); @@ -106,7 +107,7 @@ public class DWorldListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onEntityExplode(EntityExplodeEvent event) { DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); @@ -121,7 +122,7 @@ public class DWorldListener implements Listener { } } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onHangingBreakByEntity(HangingBreakByEntityEvent event) { DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); if (gameWorld != null) {