From 2951ef8349aa5eed1c8962eba8c710a7538cdc49 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 4 Jan 2017 14:34:34 +0100 Subject: [PATCH] Only permitted players can remove admin shops + Changed permission "shopchest.removeOther" to "shopchest.remove.other" Closes #36 --- .../shopchest/language/LanguageUtils.java | 3 + .../shopchest/language/LocalizedMessage.java | 1 + .../listeners/ChestProtectListener.java | 61 +++++++++++-------- .../listeners/ShopInteractListener.java | 18 ++++-- .../epiceric/shopchest/utils/Permissions.java | 3 +- src/main/resources/lang/de_DE.lang | 1 + src/main/resources/lang/en_US.lang | 3 + src/main/resources/plugin.yml | 8 ++- 8 files changed, 65 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 82fc4e1..fd4a153 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -653,6 +653,7 @@ public class LanguageUtils { itemNames.add(new ItemName(Material.SHULKER_SHELL, langConfig.getString("item.shulkerShell.name", "Shulker Shell"))); if (Utils.getRevision() >= 2 || Utils.getMajorVersion() > 11) { + // Add Item Name of 1.11.2 itemNames.add(new ItemName(Material.IRON_NUGGET, langConfig.getString("item.ironNugget.name", "Iron Nugget"))); } } @@ -696,6 +697,7 @@ public class LanguageUtils { enchantmentNames.add(new EnchantmentName(Enchantment.VANISHING_CURSE, langConfig.getString("enchantment.vanishing_curse", "Curse of Vanishing"))); if (Utils.getRevision() >= 2 || Utils.getMajorVersion() > 11) { + // Add Enchantment Name of 1.11.2 enchantmentNames.add(new EnchantmentName(Enchantment.SWEEPING_EDGE, langConfig.getString("enchantment.sweeping", "Sweeping Edge"))); } } @@ -974,6 +976,7 @@ public class LanguageUtils { messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_WG_BUY, langConfig.getString("message.noPermission.worldguard-buy", "&cYou don't have permission to buy something here."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_WG_SELL, langConfig.getString("message.noPermission.worldguard-sell", "&cYou don't have permission to sell something here."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS, langConfig.getString("message.noPermission.remove-others", "&cYou don't have permission to remove this shop."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_ADMIN, langConfig.getString("message.noPermission.remove-admin", "&cYou don't have permission to remove an admin shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_RELOAD, langConfig.getString("message.noPermission.reload", "&cYou don't have permission to reload the shops."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_UPDATE, langConfig.getString("message.noPermission.update", "&cYou don't have permission to check for updates."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_CONFIG, langConfig.getString("message.noPermission.config", "&cYou don't have permission to change configuration values."))); diff --git a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java index 86c10e8..64e42f8 100644 --- a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java +++ b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java @@ -111,6 +111,7 @@ public class LocalizedMessage { NO_PERMISSION_WG_BUY, NO_PERMISSION_WG_SELL, NO_PERMISSION_REMOVE_OTHERS, + NO_PERMISSION_REMOVE_ADMIN, NO_PERMISSION_RELOAD, NO_PERMISSION_UPDATE, NO_PERMISSION_CONFIG, diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index d5d0b4d..a9d57f6 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -44,6 +44,34 @@ public class ChestProtectListener implements Listener { this.worldGuard = worldGuard; } + private void remove(final Shop shop, final Block b, Player p) { + shopUtils.removeShop(shop, true); + + if (shop.getInventoryHolder() instanceof DoubleChest) { + DoubleChest dc = (DoubleChest) shop.getInventoryHolder(); + final Chest l = (Chest) dc.getLeftSide(); + final Chest r = (Chest) dc.getRightSide(); + + Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { + @Override + public void run() { + Shop newShop = null; + + if (b.getLocation().equals(l.getLocation())) + newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), r.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); + else if (b.getLocation().equals(r.getLocation())) + newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), l.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); + + shopUtils.addShop(newShop, true); + } + }, 1L); + return; + } + + plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED)); + } + @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e) { final Block b = e.getBlock(); @@ -55,33 +83,16 @@ public class ChestProtectListener implements Listener { if (p.isSneaking()) { plugin.debug(String.format("%s tries to break %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); - if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) { - shopUtils.removeShop(shop, true); - - if (shop.getInventoryHolder() instanceof DoubleChest) { - DoubleChest dc = (DoubleChest) shop.getInventoryHolder(); - final Chest l = (Chest) dc.getLeftSide(); - final Chest r = (Chest) dc.getRightSide(); - - Bukkit.getScheduler().runTaskLater(plugin, new Runnable() { - @Override - public void run() { - Shop newShop = null; - - if (b.getLocation().equals(l.getLocation())) - newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), r.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); - else if (b.getLocation().equals(r.getLocation())) - newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), l.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); - - shopUtils.addShop(newShop, true); - } - }, 1L); + if (shop.getShopType() == Shop.ShopType.ADMIN) { + if (p.hasPermission(Permissions.REMOVE_ADMIN)) { + remove(shop, b, p); + return; + } + } else { + if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) { + remove(shop, b, p); return; } - - plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_REMOVED)); - return; } } diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 28a5f42..2e139e7 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -181,13 +181,21 @@ public class ShopInteractListener implements Listener { if (shopUtils.isShop(b.getLocation())) { Shop shop = shopUtils.getShop(b.getLocation()); - if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) { - remove(p, shop); + if (shop.getShopType() == ShopType.ADMIN) { + if (p.hasPermission(Permissions.REMOVE_ADMIN)) { + remove(p, shop); + } else { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_ADMIN)); + plugin.debug(p.getName() + " is not permitted to remove an admin shop"); + } } else { - p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS)); - plugin.debug(p.getName() + " is not permitted to remove another player's shop"); + if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission(Permissions.REMOVE_OTHER)) { + remove(p, shop); + } else { + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_REMOVE_OTHERS)); + plugin.debug(p.getName() + " is not permitted to remove another player's shop"); + } } - } else { p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_NO_SHOP)); plugin.debug("Chest is not a shop"); diff --git a/src/main/java/de/epiceric/shopchest/utils/Permissions.java b/src/main/java/de/epiceric/shopchest/utils/Permissions.java index 300063c..41143f6 100644 --- a/src/main/java/de/epiceric/shopchest/utils/Permissions.java +++ b/src/main/java/de/epiceric/shopchest/utils/Permissions.java @@ -5,7 +5,8 @@ public class Permissions { public static final String CREATE = "shopchest.create"; public static final String CREATE_ADMIN = "shopchest.create.admin"; public static final String CREATE_PROTECTED = "shopchest.create.protected"; - public static final String REMOVE_OTHER = "shopchest.removeOther"; + public static final String REMOVE_OTHER = "shopchest.remove.other"; + public static final String REMOVE_ADMIN = "shopchest.remove.admin"; public static final String BUY = "shopchest.buy"; public static final String SELL = "shopchest.sell"; public static final String OPEN_OTHER = "shopchest.openOther"; diff --git a/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang index b226f34..7f312a6 100644 --- a/src/main/resources/lang/de_DE.lang +++ b/src/main/resources/lang/de_DE.lang @@ -67,6 +67,7 @@ message.noPermission.sell=&cDu hast keine Berechtigung etwas zu verkaufen. message.noPermission.worldguard-buy=&cDu hast keine Berechtigung hier etwas zu kaufen. message.noPermission.worldguard-sell=&cDu hast keine Berechtigung hier etwas zu verkaufen. message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu entfernen. +message.noPermission.remove-admin=&cDu hast keine Berechtigung einen Admin Shop zu entfernen. message.noPermission.reload=&cDu hast keine Berechtigung die Shops neu zu laden. message.noPermission.update=&cDu hast keine Berechtigung nach Aktualisierungen zu suchen. message.noPermission.config=&cDu hast keine Berechtigung Konfigurationswerte zu verändern. diff --git a/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang index e24789d..3c328f4 100644 --- a/src/main/resources/lang/en_US.lang +++ b/src/main/resources/lang/en_US.lang @@ -235,6 +235,9 @@ message.noPermission.worldguard-sell=&cYou don't have permission to sell somethi # Set the message when a not permitted player tries to remove another player's shop. message.noPermission.remove-others=&cYou don't have permission to remove this shop. +# Set the message when a not permitted player tries to remove an admin shop. +message.noPermission.remove-others=&cYou don't have permission to remove an admin shop. + # Set the message when a not permitted player tries to reload the shops. message.noPermission.reload=&cYou don't have permission to reload the shops. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8bb7472..257acf0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -15,7 +15,8 @@ permissions: shopchest.create: true shopchest.create.admin: true shopchest.create.protected: true - shopchest.removeOther: true + shopchest.remove.other: true + shopchest.remove.admin: true shopchest.buy: true shopchest.openOther: true shopchest.notification.update: true @@ -39,9 +40,12 @@ permissions: children: shopchest.create: true default: op - shopchest.removeOther: + shopchest.remove.other: description: Allows you to remove other players' shops. default: op + shopchest.remove.admin: + description: Allows you to remove admin shops. + default: op shopchest.buy: description: Allows you to buy something. default: true