From 134fbdf1df72a769126aa2cd0c851f3545294c26 Mon Sep 17 00:00:00 2001 From: Ali Moghnieh Date: Sat, 2 Jan 2016 11:51:11 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20Essentials=20Signs=20abuse=20using=20colo?= =?UTF-8?q?urs.=20Prior=20to=20this=20commit,=20the=20sign=20creation=20st?= =?UTF-8?q?age=20could=20be=20bypassed=20by=20typing=20&1&1[Test]=20assumi?= =?UTF-8?q?ng=20that=20was=20the=20success-name=20of=20the=20Essentials=20?= =?UTF-8?q?Sign.=20This=20commit=20prevents=20this=20by=20checking=20if=20?= =?UTF-8?q?the=20top=20line=20contains=20any=20of=20the=20success-name,=20?= =?UTF-8?q?without=20color.=20And=20so=20if=20anyone=20tries=20to=20type?= =?UTF-8?q?=20&1[repair]=20it=20will=20be=20displayed=20as=20[repair],=20b?= =?UTF-8?q?ut=20if=20someone=20tried=20&1[repairs]=20it=20will=20be=20disp?= =?UTF-8?q?layed=20as=20=C2=A71[repairs],=20as=20repairs=20is=20not=20an?= =?UTF-8?q?=20Essentials=20Sign.=20It=20might=20be=20worth=20noting=20that?= =?UTF-8?q?=20all=20signs=20are=20checked=20including=20disabled=20signs?= =?UTF-8?q?=20to=20prevent=20abuse=20ahead=20of=20time.=20So=20even=20if?= =?UTF-8?q?=20[repair]=20is=20disabled=20all=20colours=20will=20still=20be?= =?UTF-8?q?=20stripped=20from=20[repair].?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../essentials/signs/SignBlockListener.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java index f9138e2f0..136f06f91 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignBlockListener.java @@ -84,12 +84,19 @@ public class SignBlockListener implements Listener { event.setLine(i, FormatUtil.formatString(user, "essentials.signs", event.getLine(i))); } - final String topLine = event.getLine(0); + final String lColorlessTopLine = ChatColor.stripColor(event.getLine(0)).toLowerCase().trim(); + if (lColorlessTopLine.isEmpty()) { + return; + } //We loop through all sign types here to prevent clashes with preexisting signs later for (Signs signs : Signs.values()) { final EssentialsSign sign = signs.getSign(); - if (topLine.endsWith(sign.getSuccessName()) && ChatColor.stripColor(topLine).equalsIgnoreCase(ChatColor.stripColor(sign.getSuccessName()))) { - event.setLine(0, ChatColor.stripColor(topLine)); + // If the top line contains any of the success name (excluding colors), just remove all colours from the first line. + // This is to ensure we are only modifying possible Essentials Sign and not just removing colors from the first line of all signs. + // Top line and sign#getSuccessName() are both lowercased since contains is case-sensitive. + String lSuccessName = ChatColor.stripColor(sign.getSuccessName().toLowerCase()); + if (lColorlessTopLine.contains(lSuccessName)) { + event.setLine(0, lColorlessTopLine); } } }