Allow refund for shop creation price

Only refunded if shop is removed by vendor via command or by breaking
the chest. No refund will be given if shop is removed automatically or by
another player.

Closes #222
This commit is contained in:
Eric 2018-11-03 21:44:02 +01:00
parent 19e039f935
commit cc24669c0c
4 changed files with 41 additions and 0 deletions

View File

@ -141,6 +141,11 @@ public class Config {
**/ **/
public static boolean confirmShopping; public static boolean confirmShopping;
/**
* Whether the shop creation price should be refunded at removal.
*/
public static boolean refundShopCreation;
/** /**
* <p>Whether the update checker should run on start and notify players on join.</p> * <p>Whether the update checker should run on start and notify players on join.</p>
* The command is not affected by this setting and will continue to check for updates. * 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"); hopperProtection = plugin.getConfig().getBoolean("hopper-protection");
explosionProtection = plugin.getConfig().getBoolean("explosion-protection"); explosionProtection = plugin.getConfig().getBoolean("explosion-protection");
confirmShopping = plugin.getConfig().getBoolean("confirm-shopping"); confirmShopping = plugin.getConfig().getBoolean("confirm-shopping");
refundShopCreation = plugin.getConfig().getBoolean("refund-shop-creation");
enableUpdateChecker = plugin.getConfig().getBoolean("enable-update-checker"); enableUpdateChecker = plugin.getConfig().getBoolean("enable-update-checker");
enableHologramInteraction = plugin.getConfig().getBoolean("enable-hologram-interaction"); enableHologramInteraction = plugin.getConfig().getBoolean("enable-hologram-interaction");
enableDebugLog = plugin.getConfig().getBoolean("enable-debug-log"); enableDebugLog = plugin.getConfig().getBoolean("enable-debug-log");

View File

@ -8,16 +8,21 @@ import com.wasteofplastic.askyblock.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island; import com.wasteofplastic.askyblock.Island;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.external.PlotSquaredShopFlag; import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.Message; import de.epiceric.shopchest.language.Message;
import de.epiceric.shopchest.language.Replacement;
import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.nms.Hologram;
import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop;
import de.epiceric.shopchest.shop.Shop.ShopType;
import de.epiceric.shopchest.utils.Callback; import de.epiceric.shopchest.utils.Callback;
import de.epiceric.shopchest.utils.Permissions; import de.epiceric.shopchest.utils.Permissions;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.Utils; import de.epiceric.shopchest.utils.Utils;
import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.Claim;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -71,6 +76,16 @@ public class ChestProtectListener implements Listener {
} }
}); });
} else { } 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); shopUtils.removeShop(shop, true);
plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID())); plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));

View File

@ -773,6 +773,16 @@ public class ShopInteractListener implements Listener {
return; 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); shopUtils.removeShop(shop, true);
plugin.debug("Removed shop (#" + shop.getID() + ")"); plugin.debug("Removed shop (#" + shop.getID() + ")");
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED)); executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));

View File

@ -24,6 +24,16 @@ shop-info-item: "STICK"
# in order to prevent accidental purchases or sells. # in order to prevent accidental purchases or sells.
confirm-shopping: false 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 # Set whether the plugin will check for updates on server start
# and notify permitted players on join. # and notify permitted players on join.
# The command is not affected by this setting and will continue to # The command is not affected by this setting and will continue to