From e6393ecd6c9d1f14d22c5822d47e16d941248dfd Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 3 Jun 2019 16:53:23 +0200 Subject: [PATCH] Added refund to "Shop removed" message + Fixed refund option being ignored --- .../epiceric/shopchest/language/LanguageUtils.java | 1 + .../java/de/epiceric/shopchest/language/Message.java | 1 + .../shopchest/listeners/ChestProtectListener.java | 12 +++++++++--- .../shopchest/listeners/ShopInteractListener.java | 12 +++++++++--- src/main/resources/lang/de_DE-legacy.lang | 3 ++- src/main/resources/lang/de_DE.lang | 3 ++- src/main/resources/lang/en_US-legacy.lang | 9 +++++++-- src/main/resources/lang/en_US.lang | 9 +++++++-- 8 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 3ae6552..cf1973c 100644 --- a/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -2177,6 +2177,7 @@ public class LanguageUtils { messages.add(new LocalizedMessage(Message.CHEST_BLOCKED, langConfig.getString("message.chest-blocked", "&cThere must not be a block above the chest."))); messages.add(new LocalizedMessage(Message.DOUBLE_CHEST_BLOCKED, langConfig.getString("message.double-chest-blocked", "&cThere must not be a block above the chest."))); messages.add(new LocalizedMessage(Message.SHOP_REMOVED, langConfig.getString("message.shop-removed", "&6Shop removed."))); + messages.add(new LocalizedMessage(Message.SHOP_REMOVED_REFUND, langConfig.getString("message.shop-removed-refund", "&6Shop removed. You were refunded &c%CREATION-PRICE%&6."))); messages.add(new LocalizedMessage(Message.ALL_SHOPS_REMOVED, langConfig.getString("message.all-shops-removed", "&6Removed all (&c%AMOUNT%&6) shop/s of &c%VENDOR%&6."))); messages.add(new LocalizedMessage(Message.CHEST_NO_SHOP, langConfig.getString("message.chest-no-shop", "&cChest is not a shop."))); messages.add(new LocalizedMessage(Message.SHOP_CREATE_NOT_ENOUGH_MONEY, langConfig.getString("message.shop-create-not-enough-money", "&cNot enough money. You need &6%CREATION-PRICE% &cto create a shop."))); diff --git a/src/main/java/de/epiceric/shopchest/language/Message.java b/src/main/java/de/epiceric/shopchest/language/Message.java index 9e8fc7d..dfbffb9 100644 --- a/src/main/java/de/epiceric/shopchest/language/Message.java +++ b/src/main/java/de/epiceric/shopchest/language/Message.java @@ -7,6 +7,7 @@ public enum Message { CHEST_BLOCKED, DOUBLE_CHEST_BLOCKED, SHOP_REMOVED, + SHOP_REMOVED_REFUND, ALL_SHOPS_REMOVED, CHEST_NO_SHOP, SHOP_CREATE_NOT_ENOUGH_MONEY, diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index 9065d85..bbe7030 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -64,19 +64,25 @@ public class ChestProtectListener implements Listener { } }); } else { - if (p.getUniqueId().equals(shop.getVendor().getUniqueId())) { - double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal; + double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal; + if (creationPrice > 0 && Config.refundShopCreation && p.getUniqueId().equals(shop.getVendor().getUniqueId())) { EconomyResponse r = plugin.getEconomy().depositPlayer(p, shop.getLocation().getWorld().getName(), creationPrice); if (!r.transactionSuccess()) { plugin.debug("Economy transaction failed: " + r.errorMessage); p.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r.errorMessage))); + p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND, + new Replacement(Placeholder.CREATION_PRICE, 0))); + } else { + p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND, + new Replacement(Placeholder.CREATION_PRICE, creationPrice))); } + } else { + p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); } shopUtils.removeShop(shop, true); plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); - p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); } } diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index 401b942..22a3499 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -527,19 +527,25 @@ public class ShopInteractListener implements Listener { return; } - if (executor.getUniqueId().equals(shop.getVendor().getUniqueId())) { - double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal; + double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal; + if (creationPrice > 0 && Config.refundShopCreation && executor.getUniqueId().equals(shop.getVendor().getUniqueId())) { EconomyResponse r = plugin.getEconomy().depositPlayer(executor, shop.getLocation().getWorld().getName(), creationPrice); if (!r.transactionSuccess()) { plugin.debug("Economy transaction failed: " + r.errorMessage); executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r.errorMessage))); + executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND, + new Replacement(Placeholder.CREATION_PRICE, 0))); + } else { + executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND, + new Replacement(Placeholder.CREATION_PRICE, creationPrice))); } + } else { + executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); } shopUtils.removeShop(shop, true); plugin.debug("Removed shop (#" + shop.getID() + ")"); - executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); } /** diff --git a/src/main/resources/lang/de_DE-legacy.lang b/src/main/resources/lang/de_DE-legacy.lang index e996a3f..05714a6 100644 --- a/src/main/resources/lang/de_DE-legacy.lang +++ b/src/main/resources/lang/de_DE-legacy.lang @@ -4,7 +4,8 @@ message.chest-already-shop=&cTruhe ist bereits ein Shop. message.chest-blocked=&cÜber der Truhe ist kein Platz. message.double-chest-blocked=&cÜber der Truhe ist kein Platz. message.shop-removed=&6Shop entfernt. -message.all-shops-removed=&6Alle (&c%AMOUNT%&6) Shop/s von &c%VENDOR%&6 wurden entfernt. +message.shop-removed-refund=&6Shop entfernt. Dir wurden &c%CREATION-PRICE%&6 erstattet. +message.all-shops-removed=&6Alle (&c%AMOUNT%&6) Shops von &c%VENDOR%&6 wurden entfernt. message.chest-no-shop=&cTruhe ist kein Shop. message.shop-create-not-enough-money=&cNicht genug Geld. Du brauchst &6%CREATION-PRICE% &cum einen Shop zu erstellen. message.shopInfo.vendor=&6Verkäufer: &e%VENDOR% diff --git a/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang index 3b584be..91ed4ca 100644 --- a/src/main/resources/lang/de_DE.lang +++ b/src/main/resources/lang/de_DE.lang @@ -4,7 +4,8 @@ message.chest-already-shop=&cTruhe ist bereits ein Shop. message.chest-blocked=&cÜber der Truhe ist kein Platz. message.double-chest-blocked=&cÜber der Truhe ist kein Platz. message.shop-removed=&6Shop entfernt. -message.all-shops-removed=&6Alle (&c%AMOUNT%&6) Shop/s von &c%VENDOR%&6 wurden entfernt. +message.shop-removed-refund=&6Shop entfernt. Dir wurden &c%CREATION-PRICE%&6 erstattet. +message.all-shops-removed=&6Alle (&c%AMOUNT%&6) Shops von &c%VENDOR%&6 wurden entfernt. message.chest-no-shop=&cTruhe ist kein Shop. message.shop-create-not-enough-money=&cNicht genug Geld. Du brauchst &6%CREATION-PRICE% &cum einen Shop zu erstellen. message.shopInfo.vendor=&6Verkäufer: &e%VENDOR% diff --git a/src/main/resources/lang/en_US-legacy.lang b/src/main/resources/lang/en_US-legacy.lang index 808af58..8efceed 100644 --- a/src/main/resources/lang/en_US-legacy.lang +++ b/src/main/resources/lang/en_US-legacy.lang @@ -23,12 +23,17 @@ message.chest-blocked=&cThere must not be a block above the chest. # to create a double chest shop, but there is a block above the placed chest. message.double-chest-blocked=&cThere must not be a block above the chest. -# Set the message when the clicked shop is removed. +# Set the message when the clicked shop is removed but no refund was given. message.shop-removed=&6Shop removed. +# Set the message when the clicked shop is removed and the player is refunded +# the creation price. +# Usable Placeholders: %CREATION-PRICE% +message.shop-removed-refund=&6Shop removed. You were refunded &c%CREATION-PRICE%&6. + # Set the message when all shops of a player were removed. # Usable Placeholders: %AMOUNT%, %VENDOR% -message.all-shops-removed=&6Removed all (&c%AMOUNT%&6) shop/s of &c%VENDOR%&6. +message.all-shops-removed=&6Removed all (&c%AMOUNT%&6) shops of &c%VENDOR%&6. # Set the message when the clicked chest is not a shop. message.chest-no-shop=&cChest is not a shop. diff --git a/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang index 94af73a..41c42e2 100644 --- a/src/main/resources/lang/en_US.lang +++ b/src/main/resources/lang/en_US.lang @@ -16,12 +16,17 @@ message.chest-blocked=&cThere must not be a block above the chest. # to create a double chest shop, but there is a block above the placed chest. message.double-chest-blocked=&cThere must not be a block above the chest. -# Set the message when the clicked shop is removed. +# Set the message when the clicked shop is removed but no refund was given. message.shop-removed=&6Shop removed. +# Set the message when the clicked shop is removed and the player is refunded +# the creation price. +# Usable Placeholders: %CREATION-PRICE% +message.shop-removed-refund=&6Shop removed. You were refunded &c%CREATION-PRICE%&6. + # Set the message when all shops of a player were removed. # Usable Placeholders: %AMOUNT%, %VENDOR% -message.all-shops-removed=&6Removed all (&c%AMOUNT%&6) shop/s of &c%VENDOR%&6. +message.all-shops-removed=&6Removed all (&c%AMOUNT%&6) shops of &c%VENDOR%&6. # Set the message when the clicked chest is not a shop. message.chest-no-shop=&cChest is not a shop.