From 8796dbeb566b26f10f0577ba70a8841f87c19d01 Mon Sep 17 00:00:00 2001 From: Kaleb M <12635144+kalebmmm@users.noreply.github.com> Date: Thu, 3 Aug 2017 19:09:12 -0400 Subject: [PATCH] [Fix] Essentials signs validity (#1402) * [Fix] Essentials signs validity Any sign in the format of &1[...] was a valid sign according to essentials, but 3rd party plugins with the same sign format would be treated equally (cancelling nearby explosions, etc) Valid signs after this fix are: - In the format of &1[...] as before - Are essentials signs and enabled in the essentials config * Revert "[Fix] Essentials signs validity" This reverts commit 60d95b6585184051124cd32358401653042edd18. * [Fix - v2] Essentials signs validity Any sign in the format of &1[...] was a valid sign according to essentials, but 3rd party plugins with the same sign format would be treated equally (cancelling nearby explosions, etc) --- .../essentials/signs/EssentialsSign.java | 17 +++++++++++++++++ .../essentials/signs/SignBlockListener.java | 10 +++++----- .../essentials/signs/SignEntityListener.java | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java index 502bffb2c..69a3585e9 100644 --- a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java @@ -7,6 +7,7 @@ import net.ess3.api.MaxMoneyException; import net.ess3.api.events.SignBreakEvent; import net.ess3.api.events.SignCreateEvent; import net.ess3.api.events.SignInteractEvent; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -232,10 +233,26 @@ public class EssentialsSign { return false; } + /** @deprecated, use {@link #isValidSign(IEssentials, ISign)} if possible */ + @Deprecated public static boolean isValidSign(final ISign sign) { return sign.getLine(0).matches("§1\\[.*\\]"); } + public static boolean isValidSign(final IEssentials ess, final ISign sign) { + if (!sign.getLine(0).matches("§1\\[.*\\]")) + return false; + + // Validate that the sign is actually an essentials sign + String signName = ChatColor.stripColor(sign.getLine(0)).replaceAll("[^a-zA-Z]", ""); + for (EssentialsSign essSign : ess.getSettings().enabledSigns()) { + if (essSign.getName().equalsIgnoreCase(signName)) + return true; + } + + return false; + } + protected boolean onBlockPlace(final Block block, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { return true; } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java index 86c59ef05..bf6ce02f1 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -142,7 +142,7 @@ public class SignBlockListener implements Listener { } final Block against = event.getBlockAgainst(); - if ((against.getType() == WALL_SIGN || against.getType() == SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(against))) { + if ((against.getType() == WALL_SIGN || against.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(against))) { event.setCancelled(true); return; } @@ -166,7 +166,7 @@ public class SignBlockListener implements Listener { } final Block block = event.getBlock(); - if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { + if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { event.setCancelled(true); return; } @@ -186,7 +186,7 @@ public class SignBlockListener implements Listener { } final Block block = event.getBlock(); - if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { + if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { event.setCancelled(true); return; } @@ -206,7 +206,7 @@ public class SignBlockListener implements Listener { } for (Block block : event.getBlocks()) { - if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { + if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { event.setCancelled(true); return; } @@ -231,7 +231,7 @@ public class SignBlockListener implements Listener { final Block[] affectedBlocks = new Block[]{pistonBaseBlock, pistonBaseBlock.getRelative(event.getDirection()), event.getRetractLocation().getBlock()}; for (Block block : affectedBlocks) { - if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { + if (((block.getType() == WALL_SIGN || block.getType() == SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { event.setCancelled(true); return; } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java b/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java index 65aa2fc0e..192470ed3 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignEntityListener.java @@ -25,7 +25,7 @@ public class SignEntityListener implements Listener { } for (Block block : event.blockList()) { - if (((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { + if (((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { event.setCancelled(true); return; } @@ -46,7 +46,7 @@ public class SignEntityListener implements Listener { } final Block block = event.getBlock(); - if (((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) && EssentialsSign.isValidSign(new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { + if (((block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) && EssentialsSign.isValidSign(ess, new EssentialsSign.BlockSign(block))) || EssentialsSign.checkIfBlockBreaksSigns(block)) { event.setCancelled(true); return; }