diff --git a/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java index 2a3174a..f3f2a13 100644 --- a/src/main/java/de/epiceric/shopchest/config/Config.java +++ b/src/main/java/de/epiceric/shopchest/config/Config.java @@ -141,6 +141,11 @@ public class Config { **/ public static boolean confirmShopping; + /** + * Whether the shop creation price should be refunded at removal. + */ + public static boolean refundShopCreation; + /** *
Whether the update checker should run on start and notify players on join.
* The command is not affected by this setting and will continue to check for updates. @@ -480,6 +485,7 @@ public class Config { hopperProtection = plugin.getConfig().getBoolean("hopper-protection"); explosionProtection = plugin.getConfig().getBoolean("explosion-protection"); confirmShopping = plugin.getConfig().getBoolean("confirm-shopping"); + refundShopCreation = plugin.getConfig().getBoolean("refund-shop-creation"); enableUpdateChecker = plugin.getConfig().getBoolean("enable-update-checker"); enableHologramInteraction = plugin.getConfig().getBoolean("enable-hologram-interaction"); enableDebugLog = plugin.getConfig().getBoolean("enable-debug-log"); diff --git a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java index b42b36f..c35e671 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java @@ -8,16 +8,21 @@ import com.wasteofplastic.askyblock.ASkyBlockAPI; import com.wasteofplastic.askyblock.Island; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; +import de.epiceric.shopchest.config.Placeholder; import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.Message; +import de.epiceric.shopchest.language.Replacement; import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.shop.Shop; +import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.utils.Callback; import de.epiceric.shopchest.utils.Permissions; import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.Utils; import me.ryanhamshire.GriefPrevention.Claim; +import net.milkbowl.vault.economy.EconomyResponse; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -71,6 +76,16 @@ public class ChestProtectListener implements Listener { } }); } else { + if (p.getUniqueId().equals(shop.getVendor().getUniqueId())) { + double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal; + EconomyResponse r = plugin.getEconomy().withdrawPlayer(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))); + } + } + 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 effce06..d137740 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -773,6 +773,16 @@ public class ShopInteractListener implements Listener { return; } + if (executor.getUniqueId().equals(shop.getVendor().getUniqueId())) { + double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal; + EconomyResponse r = plugin.getEconomy().withdrawPlayer(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))); + } + } + shopUtils.removeShop(shop, true); plugin.debug("Removed shop (#" + shop.getID() + ")"); executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b871a2b..2502735 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -24,6 +24,16 @@ shop-info-item: "STICK" # in order to prevent accidental purchases or sells. confirm-shopping: false +# Set whether the shop creation price should be refunded +# when the shop is removed. +# This only applies when the creator of the shop removes it himself +# by command or by breaking it. +# No refund will be given for automatic shop removals or when +# the shop is removed by another player. +# If enabled, the currently set creation price will be refunded, +# not the one that was paid at creation. +refund-shop-creation: false + # Set whether the plugin will check for updates on server start # and notify permitted players on join. # The command is not affected by this setting and will continue to