From 7bc79121bc5380307d30004354c2618ef7da862a Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Mon, 30 Sep 2019 21:19:46 +0800 Subject: [PATCH] Fix `People are able to use dye on other players shops, so the shop texts color changes` Former-commit-id: 2c02588e1216f26c034409380f02637df2640f79 [formerly ba507b928795bcb997d0da34b9d0356e79602ab2] Former-commit-id: e3fcb8c37a1a31f0fba92784baccc44dec824048 --- .../quickshop/Listeners/PlayerListener.java | 31 ++++++++++++++++--- .../maxgamer/quickshop/Shop/DisplayItem.java | 2 ++ .../org/maxgamer/quickshop/Util/Util.java | 9 ++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java b/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java index ddb1abeda..0d18472fc 100644 --- a/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java +++ b/src/main/java/org/maxgamer/quickshop/Listeners/PlayerListener.java @@ -1,10 +1,7 @@ package org.maxgamer.quickshop.Listeners; import lombok.AllArgsConstructor; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event.Result; @@ -263,5 +260,29 @@ public class PlayerListener implements Listener { PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo()); onMove(me); } - + @EventHandler(priority = EventPriority.HIGH,ignoreCancelled = true) + public void onDyeing(PlayerInteractEvent e){ + if(e.getAction() != Action.RIGHT_CLICK_BLOCK){ + return; + } + if(!Util.isDyes(e.getItem().getType())){ + return; + } + Block block = e.getClickedBlock(); + if(block == null){ + return; + } + if(!Util.isWallSign(block.getType())){ + return; + } + Block attachedBlock = Util.getAttached(block); + if(attachedBlock == null){ + return; + } + if(plugin.getShopManager().getShopIncludeAttached(attachedBlock.getLocation()) == null){ + return; + } + e.setCancelled(true); + Util.debugLog("Disallow "+e.getPlayer().getName()+" dye the shop sign."); + } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 6f3684d86..08611caeb 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -1,9 +1,11 @@ package org.maxgamer.quickshop.Shop; +import com.google.common.collect.BiMap; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 28b1efb52..f229b39e1 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -1124,4 +1124,13 @@ public class Util { public static boolean isDevMode() { return devMode; } + + /** + * Get a material is a dye + * @param material The material + * @return yes or not + */ + public static boolean isDyes(Material material){ + return material.name().toUpperCase().endsWith("_DYE"); + } }