From e2e034bcc8a9b1cd313fa237a81b3dc84f35389e Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 3 Jun 2016 16:28:44 +0200 Subject: [PATCH] Added shop creation costs (configurable) --- config.yml | 15 +++++++++++++++ src/de/epiceric/shopchest/Commands.java | 15 +++++++++++++++ src/de/epiceric/shopchest/config/Config.java | 12 ++++++++++++ src/de/epiceric/shopchest/config/Regex.java | 2 +- 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/config.yml b/config.yml index 120dd47..ec22270 100644 --- a/config.yml +++ b/config.yml @@ -41,6 +41,17 @@ main-command-name: "shop" # Value MUST be a number (e.g. 1, 1.5, 2.75, ...) maximal-distance: 1.75 +# Set the price a player has to pay in order to create... +# You can set this to 0 to disable costs. +# Value MUST be a number (e.g. 1, 1.5, 2.75, ...) +shop-creation-price: + + # ...a normal shop + normal: 5 + + # ...an admin shop + admin: 0 + # Set whether the shop's chest should be protected by hoppers hopper-protection: true @@ -135,6 +146,10 @@ messages: # Set the message when the clicked chest is not a shop. chest-no-shop: "&cChest is not a shop." + # Set the message when the player doesn't have enough money to create a shop + # Usable Regex: %CREATION-PRICE%, %CURRENCY-SYMBOL% + shop-create-not-enough-money: "&cNot enough money. You need &6%CREATION-PRICE%%CURRENCY-SYMBOL% &cto create a shop." + shop-info: # Set the vendor message the player gets after entering '/shop info'. diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index eb53ae0..91c276a 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -10,6 +10,7 @@ import de.epiceric.shopchest.utils.ClickType.EnumClickType; import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.UpdateChecker; import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult; +import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -281,6 +282,20 @@ public class Commands extends BukkitCommand { } } + double creationPrice = (shopType == ShopType.NORMAL) ? Config.shop_creation_price_normal() : Config.shop_creation_price_admin(); + if (creationPrice > 0) { + if (ShopChest.econ.getBalance(p) >= creationPrice) { + EconomyResponse r = ShopChest.econ.withdrawPlayer(p, creationPrice); + if (!r.transactionSuccess()) { + p.sendMessage(Config.error_occurred(r.errorMessage)); + return; + } + } else { + p.sendMessage(Config.shop_create_not_enough_money(creationPrice)); + return; + } + } + ClickType.addPlayerClickType(p, new ClickType(EnumClickType.CREATE, itemStack, buyPrice, sellPrice, shopType)); p.sendMessage(Config.click_chest_to_create()); diff --git a/src/de/epiceric/shopchest/config/Config.java b/src/de/epiceric/shopchest/config/Config.java index feb2b9b..7c2e6c1 100644 --- a/src/de/epiceric/shopchest/config/Config.java +++ b/src/de/epiceric/shopchest/config/Config.java @@ -72,6 +72,14 @@ public class Config { return plugin.getConfig().getDouble("maximal-distance"); } + public static double shop_creation_price_normal() { + return plugin.getConfig().getDouble("shop-creation-price.normal"); + } + + public static double shop_creation_price_admin() { + return plugin.getConfig().getDouble("shop-creation-price.admin"); + } + public static int default_limit() { return plugin.getConfig().getInt("shop-limits.default"); } @@ -264,6 +272,10 @@ public class Config { return plugin.getConfig().getString("messages.shop-info.none").replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); } + public static String shop_create_not_enough_money(double creationPrice) { + return plugin.getConfig().getString("messages.shop-create-not-enough-money").replace(Regex.creationPrice, String.valueOf(creationPrice)).replace(Regex.currencySymbol, currency_symbol()).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); + } + public static String limit_reached(int limit) { return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2"); } diff --git a/src/de/epiceric/shopchest/config/Regex.java b/src/de/epiceric/shopchest/config/Regex.java index 5c8fae1..f273309 100644 --- a/src/de/epiceric/shopchest/config/Regex.java +++ b/src/de/epiceric/shopchest/config/Regex.java @@ -5,7 +5,7 @@ public class Regex { public static String vendor = "%VENDOR%"; public static String amount = "%AMOUNT%"; public static String itemName = "%ITEMNAME%"; - public static String price = "%PRICE%"; + public static String creationPrice = "%CREATION-PRICE%"; public static String currencySymbol = "%CURRENCY-SYMBOL%"; public static String error = "%ERROR%"; public static String enchantment = "%ENCHANTMENT%";