From d42649256118624159189021e0f5241a4bf1bdbf Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Sun, 27 Aug 2023 15:55:53 +0100 Subject: [PATCH] Fix issues with new 1.20 back side of signs This basically blocks any text on the backside of a sign if the front is a valid shop and with that also fixes an issue where valid shop sign syntax was detected on back side sign changes. --- .../ChestShop/Configuration/Messages.java | 1 + .../ChestShop/Listeners/Block/SignCreate.java | 21 +++++++++++++++++++ src/main/resources/languages/lang.en.yml | 1 + 3 files changed, 23 insertions(+) diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java index be4492b..acf816c 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Messages.java @@ -82,6 +82,7 @@ public class Messages { public static Message INVALID_SHOP_PRICE; public static Message INVALID_SHOP_QUANTITY; public static Message CANNOT_ACCESS_THE_CHEST; + public static Message CANNOT_CHANGE_SIGN_BACKSIDE; public static Message SELL_PRICE_HIGHER_THAN_BUY_PRICE; public static Message SELL_PRICE_ABOVE_MAX; diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java index d79d1f3..15e76a8 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java @@ -3,6 +3,7 @@ package com.Acrobot.ChestShop.Listeners.Block; import com.Acrobot.Breeze.Utils.BlockUtil; import com.Acrobot.Breeze.Utils.StringUtil; import com.Acrobot.ChestShop.ChestShop; +import com.Acrobot.ChestShop.Configuration.Messages; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import com.Acrobot.ChestShop.Events.ShopCreatedEvent; import com.Acrobot.ChestShop.Listeners.Block.Break.SignBreak; @@ -11,6 +12,7 @@ import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Utils.uBlock; import org.bukkit.block.Block; import org.bukkit.block.Sign; +import org.bukkit.block.sign.Side; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.SignChangeEvent; @@ -22,6 +24,17 @@ import static com.Acrobot.ChestShop.Permission.OTHER_NAME_DESTROY; */ public class SignCreate implements Listener { + private static boolean HAS_SIGN_SIDES; + + static { + try { + SignChangeEvent.class.getMethod("getSide"); + HAS_SIGN_SIDES = true; + } catch (NoSuchMethodException e) { + HAS_SIGN_SIDES = false; + } + } + @EventHandler(ignoreCancelled = true) public static void onSignChange(SignChangeEvent event) { Block signBlock = event.getBlock(); @@ -32,6 +45,14 @@ public class SignCreate implements Listener { Sign sign = (Sign) signBlock.getState(); + if (HAS_SIGN_SIDES && event.getSide() != Side.FRONT) { + if (ChestShopSign.isValid(sign)) { + event.setCancelled(true); + Messages.CANNOT_CHANGE_SIGN_BACKSIDE.sendWithPrefix(event.getPlayer()); + } + return; + } + if (ChestShopSign.isValid(event.getLines()) && !NameManager.canUseName(event.getPlayer(), OTHER_NAME_DESTROY, ChestShopSign.getOwner(event.getLines()))) { event.setCancelled(true); sign.update(); diff --git a/src/main/resources/languages/lang.en.yml b/src/main/resources/languages/lang.en.yml index 6a1cb6a..cad4e03 100644 --- a/src/main/resources/languages/lang.en.yml +++ b/src/main/resources/languages/lang.en.yml @@ -81,6 +81,7 @@ INVALID_SHOP_DETECTED: "The shop cannot be used!" INVALID_SHOP_PRICE: "The shop has an invalid price!" INVALID_SHOP_QUANTITY: "The shop has an invalid quantity!" CANNOT_ACCESS_THE_CHEST: "You don't have permissions to access this chest!" +CANNOT_CHANGE_SIGN_BACKSIDE: "You can't change the back side of a shop sign!" SELL_PRICE_HIGHER_THAN_BUY_PRICE: "Sell price is above the buy price!" SELL_PRICE_ABOVE_MAX: "Sell price %price is above maximum %maxprice!"