From 1d7a534fe4b8611c804b841d4ec2de59c6238920 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 18 Nov 2016 20:57:26 +0100 Subject: [PATCH] Added permission for extending other players' shop chests --- .../shopchest/language/LanguageUtils.java | 1 + .../shopchest/language/LocalizedMessage.java | 1 + .../listeners/ChestProtectListener.java | 37 +++++++++++-------- src/main/resources/lang/de_DE.lang | 1 + src/main/resources/lang/en_US.lang | 3 ++ src/main/resources/plugin.yml | 7 +++- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 05a5c15..ebb22d8 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -966,6 +966,7 @@ public class LanguageUtils { 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."))); + messages.add(new LocalizedMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS, langConfig.getString("message.noPermission.extend-others", "&cYou don't have permission to extend this chest."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CREATE, langConfig.getString("message.commandDescription.create", "Create a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_REMOVE, langConfig.getString("message.commandDescription.remove", "Remove a shop."))); messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_INFO, langConfig.getString("message.commandDescription.info", "Retrieve shop information."))); diff --git a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java index c1daaf5..f0086c0 100644 --- a/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java +++ b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java @@ -112,6 +112,7 @@ public class LocalizedMessage { NO_PERMISSION_RELOAD, NO_PERMISSION_UPDATE, NO_PERMISSION_CONFIG, + NO_PERMISSION_EXTEND_OTHERS, COMMAND_DESC_CREATE, COMMAND_DESC_REMOVE, COMMAND_DESC_INFO, diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index 198129c..4a4fb9d 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -43,6 +43,8 @@ public class ChestProtectListener implements Listener { Player p = e.getPlayer(); 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("shopchest.removeOther")) { shopUtils.removeShop(shop, true); @@ -96,7 +98,7 @@ public class ChestProtectListener implements Listener { @EventHandler public void onBlockPlace(BlockPlaceEvent e) { - + Player p = e.getPlayer(); Block b = e.getBlockPlaced(); if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { @@ -109,26 +111,31 @@ public class ChestProtectListener implements Listener { Chest l = (Chest) dc.getLeftSide(); if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) { - plugin.debug(e.getPlayer().getName() + " tried to extend a shop to a double chest"); + Shop shop; - if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { - Shop shop; + if (b.getLocation().equals(r.getLocation())) { + shop = shopUtils.getShop(l.getLocation()); + } else if (b.getLocation().equals(l.getLocation())) { + shop = shopUtils.getShop(r.getLocation()); + } else { + return; + } - if (b.getLocation().equals(r.getLocation())) { - shop = shopUtils.getShop(l.getLocation()); - } else if (b.getLocation().equals(l.getLocation())) { - shop = shopUtils.getShop(r.getLocation()); + plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); + + if (shop.getVendor().getUniqueId().equals(p.getUniqueId()) || p.hasPermission("shopchest.extendOther")) { + if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { + shopUtils.removeShop(shop, true); + Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); + shopUtils.addShop(newShop, true); + plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); } else { - return; + e.setCancelled(true); + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); } - - shopUtils.removeShop(shop, true); - - Shop newShop = new Shop(shop.getID(), ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType()); - shopUtils.addShop(newShop, true); } else { e.setCancelled(true); - e.getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); + p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_EXTEND_OTHERS)); } } diff --git a/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang index 55da2e5..1b9d859 100644 --- a/src/main/resources/lang/de_DE.lang +++ b/src/main/resources/lang/de_DE.lang @@ -68,6 +68,7 @@ message.noPermission.remove-others=&cDu hast keine Berechtigung diesen Shop zu e 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. +message.noPermission.extend-others=&cDu hast keine Berechtigung diesen Shop zu erweitern. message.commandDescription.create=Erstelle einen Shop. message.commandDescription.remove=Entferne einen Shop. message.commandDescription.info=Rufe Informationen über den Shop ab. diff --git a/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang index 1c949ed..f608333 100644 --- a/src/main/resources/lang/en_US.lang +++ b/src/main/resources/lang/en_US.lang @@ -238,6 +238,9 @@ message.noPermission.update=&cYou don't have permission to check for updates. # Set the message when a not permitted player tries to change configuration values. message.noPermission.config=&cYou don't have permission to change configuration values. +# Set the message when a not permitted player tries to extend another player's shop's chest. +message.noPermission.extend-others=&cYou don't have permission to extend this chest. + # Set the command description message for '/shop create' when you type '/shop'. message.commandDescription.create=Create a shop. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b537f59..b59a294 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -35,7 +35,7 @@ permissions: shopchest.create: true default: op shopchest.removeOther: - description: Allows you to remove other players' shop. + description: Allows you to remove other players' shops. default: op shopchest.buy: description: Allows you to buy something. @@ -44,7 +44,7 @@ permissions: description: Allows you to sell something. default: true shopchest.openOther: - description: Allows you to open other players' shop. + description: Allows you to open other players' shops. default: op shopchest.notification.update: description: Allows you to get update notification on join. @@ -60,3 +60,6 @@ permissions: shopchest.config: description: Allows you to change configuration values per command. default: op + shopchest.extendOther: + description: Allows you to extend other players' shops. + default: op