Added shop creation costs (configurable)

This commit is contained in:
Eric 2016-06-03 16:28:44 +02:00
parent ce2c812b27
commit e2e034bcc8
4 changed files with 43 additions and 1 deletions

View File

@ -41,6 +41,17 @@ main-command-name: "shop"
# Value MUST be a number (e.g. 1, 1.5, 2.75, ...) # Value MUST be a number (e.g. 1, 1.5, 2.75, ...)
maximal-distance: 1.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 # Set whether the shop's chest should be protected by hoppers
hopper-protection: true hopper-protection: true
@ -135,6 +146,10 @@ messages:
# Set the message when the clicked chest is not a shop. # Set the message when the clicked chest is not a shop.
chest-no-shop: "&cChest 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: shop-info:
# Set the vendor message the player gets after entering '/shop info'. # Set the vendor message the player gets after entering '/shop info'.

View File

@ -10,6 +10,7 @@ import de.epiceric.shopchest.utils.ClickType.EnumClickType;
import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker; import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult; import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; 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)); ClickType.addPlayerClickType(p, new ClickType(EnumClickType.CREATE, itemStack, buyPrice, sellPrice, shopType));
p.sendMessage(Config.click_chest_to_create()); p.sendMessage(Config.click_chest_to_create());

View File

@ -72,6 +72,14 @@ public class Config {
return plugin.getConfig().getDouble("maximal-distance"); 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() { public static int default_limit() {
return plugin.getConfig().getInt("shop-limits.default"); 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"); 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) { 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"); return plugin.getConfig().getString("messages.shop-limit-reached").replace(Regex.limit, String.valueOf(limit)).replaceAll("(&([a-f0-9k-or]))", "\u00A7$2");
} }

View File

@ -5,7 +5,7 @@ public class Regex {
public static String vendor = "%VENDOR%"; public static String vendor = "%VENDOR%";
public static String amount = "%AMOUNT%"; public static String amount = "%AMOUNT%";
public static String itemName = "%ITEMNAME%"; 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 currencySymbol = "%CURRENCY-SYMBOL%";
public static String error = "%ERROR%"; public static String error = "%ERROR%";
public static String enchantment = "%ENCHANTMENT%"; public static String enchantment = "%ENCHANTMENT%";