From 76ea273ad6d099d0ecb06f60378672af4fa606ba Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 4 Aug 2016 21:12:19 +0200 Subject: [PATCH] Changed way of checking if chests are protected If another plugin cancelled the PlayerInteractEvent before ShopChest, the player is not permitted to create a shop on the clicked chest. The dependency of 'Lockette' is no longer needed. It might occur that a plugin, which is not used for protections, cancels the PlayerInteractEvent so a shop cannot be created. This closes #14 --- ShopChest/dependency-reduced-pom.xml | 6 -- .../java/de/epiceric/shopchest/ShopChest.java | 9 -- .../listeners/ShopInteractListener.java | 92 +++++++++---------- ShopChest/src/main/resources/lang/de_DE.lang | 2 +- ShopChest/src/main/resources/lang/en_US.lang | 2 +- pom.xml | 6 -- 6 files changed, 44 insertions(+), 73 deletions(-) diff --git a/ShopChest/dependency-reduced-pom.xml b/ShopChest/dependency-reduced-pom.xml index 2ed648c..9b29adb 100644 --- a/ShopChest/dependency-reduced-pom.xml +++ b/ShopChest/dependency-reduced-pom.xml @@ -56,12 +56,6 @@ - - org.yi.acru.bukkit - lockette - 1.8.36 - provided - me.minebuilders clearlag diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java b/ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java index 2db6c94..a09cf0a 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -41,7 +41,6 @@ public class ShopChest extends JavaPlugin { private Config config = null; private Economy econ = null; private Permission perm = null; - private boolean lockette = false; private boolean lwc = false; private Database database; private boolean isUpdateNeeded = false; @@ -239,7 +238,6 @@ public class ShopChest extends JavaPlugin { }, config.auto_reload_time * 20, config.auto_reload_time * 20); } - lockette = getServer().getPluginManager().isPluginEnabled("Lockette"); lwc = getServer().getPluginManager().isPluginEnabled("LWC"); Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() { @@ -455,13 +453,6 @@ public class ShopChest extends JavaPlugin { return lwc; } - /** - * @return Whether Lockette is available - */ - public boolean hasLockette() { - return lockette; - } - /** * @return Whether an update is needed (will return false if not checked) */ diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 8b64a9d..49b11d9 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -1,7 +1,5 @@ package de.epiceric.shopchest.listeners; -import com.griefcraft.lwc.LWC; -import com.griefcraft.model.Protection; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.event.ShopBuySellEvent; @@ -28,6 +26,7 @@ import org.bukkit.block.Chest; import org.bukkit.enchantments.Enchantment; 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.Action; import org.bukkit.event.player.PlayerInteractEvent; @@ -36,7 +35,6 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.EnchantmentStorageMeta; -import org.yi.acru.bukkit.Lockette.Lockette; import java.util.HashMap; import java.util.Map; @@ -57,6 +55,47 @@ public class ShopInteractListener implements Listener { this.shopUtils = plugin.getShopUtils(); } + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerInteractCreate(PlayerInteractEvent e) { + Player p = e.getPlayer(); + Block b = e.getClickedBlock(); + + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (ClickType.getPlayerClickType(p) != null) { + if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) { + if (!shopUtils.isShop(b.getLocation())) { + if (e.isCancelled() && !perm.has(p, "shopchest.create.protected")) { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); + ClickType.removePlayerClickType(p); + return; + } + + e.setCancelled(true); + + if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { + ClickType clickType = ClickType.getPlayerClickType(p); + ItemStack product = clickType.getProduct(); + double buyPrice = clickType.getBuyPrice(); + double sellPrice = clickType.getSellPrice(); + ShopType shopType = clickType.getShopType(); + + create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); + } else { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); + } + } else { + e.setCancelled(true); + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP)); + } + + ClickType.removePlayerClickType(p); + } + } + } + } + } + @EventHandler public void onPlayerInteract(PlayerInteractEvent e) { Block b = e.getClickedBlock(); @@ -71,53 +110,6 @@ public class ShopInteractListener implements Listener { if (ClickType.getPlayerClickType(p) != null) { switch (ClickType.getPlayerClickType(p).getClickType()) { - - case CREATE: - e.setCancelled(true); - - if (!perm.has(p, "shopchest.create.protected")) { - if (plugin.hasLockette()) { - if (Lockette.isProtected(b)) { - if (!Lockette.isOwner(b, p) || !Lockette.isUser(b, p, true)) { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); - ClickType.removePlayerClickType(p); - break; - } - } - } - - if (plugin.hasLWC()) { - if (LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()) != null) { - Protection protection = LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()); - if (!protection.isOwner(p) || !protection.isRealOwner(p)) { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); - ClickType.removePlayerClickType(p); - break; - } - } - } - } - - - if (!shopUtils.isShop(b.getLocation())) { - if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { - ClickType clickType = ClickType.getPlayerClickType(p); - ItemStack product = clickType.getProduct(); - double buyPrice = clickType.getBuyPrice(); - double sellPrice = clickType.getSellPrice(); - ShopType shopType = clickType.getShopType(); - - create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); - } else { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); - } - } else { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP)); - } - - ClickType.removePlayerClickType(p); - break; - case INFO: e.setCancelled(true); diff --git a/ShopChest/src/main/resources/lang/de_DE.lang b/ShopChest/src/main/resources/lang/de_DE.lang index 36cfd40..1819d5c 100644 --- a/ShopChest/src/main/resources/lang/de_DE.lang +++ b/ShopChest/src/main/resources/lang/de_DE.lang @@ -57,7 +57,7 @@ message.hologram.only-buy=Kauf %BUY-PRICE% message.hologram.only-sell=Verkauf %SELL-PRICE% message.noPermission.create=&cDu hast keine Berechtigung einen Shop zu erstellen. message.noPermission.create-admin=&cDu hast keine Berechtigung einen Admin-Shop zu erstellen. -message.noPermission.create-protected=&cDu hast keine Berechtigung einen Shop auf einer gesicherten Truhe zu erstellen. +message.noPermission.create-protected=&cDu hast keine Berechtigung hier einen Shop zu erstellen. message.noPermission.open-others=&cDu hast keine Berechtigung diesen Shop zu öffnen. message.noPermission.buy=&cDu hast keine Berechtigung etwas zu kaufen. message.noPermission.sell=&cDu hast keine Berechtigung etwas zu verkaufen. diff --git a/ShopChest/src/main/resources/lang/en_US.lang b/ShopChest/src/main/resources/lang/en_US.lang index 6068c64..3b1641b 100644 --- a/ShopChest/src/main/resources/lang/en_US.lang +++ b/ShopChest/src/main/resources/lang/en_US.lang @@ -204,7 +204,7 @@ message.noPermission.create=&cYou don't have permission to create a shop. message.noPermission.create-admin=&cYou don't have permission to create an admin shop. # Set the message when a not permitted player tries to create a shop on a protected chest. -message.noPermission.create-protected=&cYou don't have permission to create a shop on a protected chest. +message.noPermission.create-protected=&cYou don't have permission to create a shop here. # Set the message when a not permitted player tries to open another player's shop. message.noPermission.open-others=&cYou don't have permission to open this chest. diff --git a/pom.xml b/pom.xml index 7cd1d95..3f65f79 100644 --- a/pom.xml +++ b/pom.xml @@ -58,12 +58,6 @@ 1.6 provided - - org.yi.acru.bukkit - lockette - 1.8.36 - provided - me.minebuilders clearlag