You can now add scripts to the hologram format itself

Use curly brackets to add a script to the format.
Also, "regex" has been renamed to "placeholder".
This commit is contained in:
Eric 2017-05-23 15:18:02 +02:00
parent 4b4cfb3c0f
commit ca064da094
10 changed files with 203 additions and 154 deletions

View File

@ -5,7 +5,7 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.wasteofplastic.askyblock.ASkyBlock;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.HologramFormat;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
@ -323,11 +323,11 @@ public class ShopChest extends JavaPlugin {
latestVersion = uc.getVersion();
downloadLink = uc.getLink();
isUpdateNeeded = true;
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)));
Bukkit.getConsoleSender().sendMessage("[ShopChest] " + LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Placeholder.VERSION, latestVersion)));
for (Player p : getServer().getOnlinePlayers()) {
if (p.hasPermission(Permissions.UPDATE_NOTIFICATION)) {
JsonBuilder jb = new JsonBuilder(ShopChest.this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
JsonBuilder jb = new JsonBuilder(ShopChest.this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Placeholder.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink);
jb.sendJson(p);
}
}

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.event.*;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
@ -12,7 +12,6 @@ import de.epiceric.shopchest.utils.ClickType.EnumClickType;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -139,8 +138,8 @@ class ShopCommand implements CommandExecutor {
plugin.debug(p.getName() + " is viewing his shop limits: " + shopUtils.getShopAmount(p) + "/" + shopUtils.getShopLimit(p));
int limit = shopUtils.getShopLimit(p);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OCCUPIED_SHOP_SLOTS,
new LocalizedMessage.ReplacedRegex(Regex.LIMIT, (limit < 0 ? "" : String.valueOf(limit))),
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shopUtils.getShopAmount(p)))));
new LocalizedMessage.ReplacedRegex(Placeholder.LIMIT, (limit < 0 ? "" : String.valueOf(limit))),
new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(shopUtils.getShopAmount(p)))));
} else if (args[0].equalsIgnoreCase("open")) {
needsHelp = false;
open(p);
@ -186,13 +185,13 @@ class ShopCommand implements CommandExecutor {
if (args[1].equalsIgnoreCase("set")) {
plugin.getShopChestConfig().set(property, value);
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, new LocalizedMessage.ReplacedRegex(Regex.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Regex.VALUE, value)));
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, new LocalizedMessage.ReplacedRegex(Placeholder.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Placeholder.VALUE, value)));
} else if (args[1].equalsIgnoreCase("add")) {
plugin.getShopChestConfig().add(property, value);
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_ADDED, new LocalizedMessage.ReplacedRegex(Regex.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Regex.VALUE, value)));
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_ADDED, new LocalizedMessage.ReplacedRegex(Placeholder.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Placeholder.VALUE, value)));
} else if (args[1].equalsIgnoreCase("remove")) {
plugin.getShopChestConfig().remove(property, value);
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, new LocalizedMessage.ReplacedRegex(Regex.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Regex.VALUE, value)));
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, new LocalizedMessage.ReplacedRegex(Placeholder.PROPERTY, property), new LocalizedMessage.ReplacedRegex(Placeholder.VALUE, value)));
} else {
sendBasicHelpMessage(sender);
}
@ -216,10 +215,10 @@ class ShopCommand implements CommandExecutor {
plugin.setUpdateNeeded(true);
if (sender instanceof Player) {
JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Placeholder.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink());
jb.sendJson((Player) sender);
} else {
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())));
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Placeholder.VERSION, uc.getVersion())));
}
} else if (result == UpdateCheckerResult.FALSE) {
@ -254,7 +253,7 @@ class ShopCommand implements CommandExecutor {
public void onResult(Object result) {
if (result instanceof Integer) {
int count = (int) result;
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(count))));
sender.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.RELOADED_SHOPS, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(count))));
plugin.debug(sender.getName() + " has reloaded " + count + " shops");
}
}
@ -279,7 +278,7 @@ class ShopCommand implements CommandExecutor {
if (limit != -1) {
if (shopUtils.getShopAmount(p) >= limit) {
if (shopType != ShopType.ADMIN || !plugin.getShopChestConfig().exclude_admin_shops) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_LIMIT_REACHED, new LocalizedMessage.ReplacedRegex(Regex.LIMIT, String.valueOf(limit))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_LIMIT_REACHED, new LocalizedMessage.ReplacedRegex(Placeholder.LIMIT, String.valueOf(limit))));
plugin.debug(p.getName() + " has reached the limit");
return;
}
@ -358,7 +357,7 @@ class ShopCommand implements CommandExecutor {
if (itemStack.getType().equals(inHand.getType()) && itemStack.getDurability() == inHand.getDurability()) {
if (buyEnabled) {
if ((buyPrice < amount * minPrice) && (buyPrice > 0)) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Regex.MIN_PRICE, String.valueOf(amount * minPrice))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Placeholder.MIN_PRICE, String.valueOf(amount * minPrice))));
plugin.debug(p.getName() + "'s buy price is lower than the minimum");
return;
}
@ -366,7 +365,7 @@ class ShopCommand implements CommandExecutor {
if (sellEnabled) {
if ((sellPrice < amount * minPrice) && (sellPrice > 0)) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Regex.MIN_PRICE, String.valueOf(amount * minPrice))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Placeholder.MIN_PRICE, String.valueOf(amount * minPrice))));
plugin.debug(p.getName() + "'s sell price is lower than the minimum");
return;
}
@ -388,7 +387,7 @@ class ShopCommand implements CommandExecutor {
if (itemStack.getType().equals(inHand.getType()) && itemStack.getDurability() == inHand.getDurability()) {
if (buyEnabled) {
if ((buyPrice > amount * maxPrice) && (buyPrice > 0)) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_HIGH, new LocalizedMessage.ReplacedRegex(Regex.MAX_PRICE, String.valueOf(amount * maxPrice))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_HIGH, new LocalizedMessage.ReplacedRegex(Placeholder.MAX_PRICE, String.valueOf(amount * maxPrice))));
plugin.debug(p.getName() + "'s buy price is higher than the maximum");
return;
}
@ -396,7 +395,7 @@ class ShopCommand implements CommandExecutor {
if (sellEnabled) {
if ((sellPrice > amount * maxPrice) && (sellPrice > 0)) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_PRICE_TOO_HIGH, new LocalizedMessage.ReplacedRegex(Regex.MAX_PRICE, String.valueOf(amount * maxPrice))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_PRICE_TOO_HIGH, new LocalizedMessage.ReplacedRegex(Placeholder.MAX_PRICE, String.valueOf(amount * maxPrice))));
plugin.debug(p.getName() + "'s sell price is higher than the maximum");
return;
}
@ -408,7 +407,7 @@ class ShopCommand implements CommandExecutor {
if (sellEnabled && buyEnabled) {
if (plugin.getShopChestConfig().buy_greater_or_equal_sell) {
if (buyPrice < sellPrice) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Regex.MIN_PRICE, String.valueOf(sellPrice))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, new LocalizedMessage.ReplacedRegex(Placeholder.MIN_PRICE, String.valueOf(sellPrice))));
plugin.debug(p.getName() + "'s buy price is lower than the sell price");
return;
}
@ -429,7 +428,7 @@ class ShopCommand implements CommandExecutor {
double creationPrice = (shopType == ShopType.NORMAL) ? plugin.getShopChestConfig().shop_creation_price_normal : plugin.getShopChestConfig().shop_creation_price_admin;
if (creationPrice > 0) {
if (plugin.getEconomy().getBalance(p) < creationPrice) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedRegex(Regex.CREATION_PRICE, String.valueOf(creationPrice))));
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedRegex(Placeholder.CREATION_PRICE, String.valueOf(creationPrice))));
plugin.debug(p.getName() + " can not pay the creation price");
return;
}

View File

@ -10,6 +10,8 @@ import javax.script.ScriptException;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class HologramFormat {
@ -32,11 +34,11 @@ public class HologramFormat {
/**
* Get the format for the given line of the hologram
* @param line Line of the hologram
* @param values Values of the requirements that might be needed by the format (contains {@code null} if not comparable)
* @param reqMap Values of the requirements that might be needed by the format (contains {@code null} if not comparable)
* @return The format of the first working option, or an empty String if no option is working
* because of not fulfilled requirements
*/
public String getFormat(int line, Map<Requirement, Object> values) {
public String getFormat(int line, Map<Requirement, Object> reqMap, Map<Placeholder, Object> plaMap) {
ConfigurationSection options = config.getConfigurationSection("lines." + line + ".options");
optionLoop:
@ -47,16 +49,16 @@ public class HologramFormat {
String format = option.getString("format");
for (String sReq : requirements) {
for (Requirement req : values.keySet()) {
for (Requirement req : reqMap.keySet()) {
if (sReq.contains(req.toString())) {
if (!eval(sReq, values)) {
if (!evalRequirement(sReq, reqMap)) {
continue optionLoop;
}
}
}
}
return format;
return evalPlaceholder(format, plaMap);
}
return "";
@ -76,7 +78,7 @@ public class HologramFormat {
ConfigurationSection option = options.getConfigurationSection(key);
String format = option.getString("format");
if (format.contains(Regex.STOCK.getName())) {
if (format.contains(Placeholder.STOCK.toString())) {
return true;
}
@ -107,24 +109,27 @@ public class HologramFormat {
* @param values Values of the requirements
* @return Result of the condition
*/
public boolean eval(String condition, Map<Requirement, Object> values) {
public boolean evalRequirement(String condition, Map<Requirement, Object> values) {
try {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
String c = condition;
String cond = condition;
for (HologramFormat.Requirement req : HologramFormat.Requirement.values()) {
if (c.contains(req.toString()) && values.containsKey(req)) {
String replace = String.valueOf(values.get(req));
if (values.get(req) instanceof String) {
replace = String.format("\"%s\"", replace);
if (cond.contains(req.toString()) && values.containsKey(req)) {
Object val = values.get(req);
String sVal = String.valueOf(val);
if (val instanceof String && !(sVal.startsWith("\"") && sVal.endsWith("\""))) {
sVal = String.format("\"%s\"", sVal);
}
c = c.replace(req.toString(), replace);
cond = cond.replace(req.toString(), sVal);
}
}
return (boolean) engine.eval(c);
return (boolean) engine.eval(cond);
} catch (ScriptException e) {
plugin.debug("Failed to eval condition: " + condition);
plugin.debug(e);
@ -132,4 +137,48 @@ public class HologramFormat {
return false;
}
/**
* Parse and evaluate a condition
* @param string Message or hologram format whose containing scripts to execute
* @param values Values of the placeholders
* @return Result of the condition
*/
public String evalPlaceholder(String string, Map<Placeholder, Object> values) {
try {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
Matcher matcher = Pattern.compile("\\{([^}]+)}").matcher(string);
String newString = string;
while (matcher.find()) {
String withBrackets = matcher.group();
String script = withBrackets.substring(1, withBrackets.length() - 1);
for (Placeholder placeholder : values.keySet()) {
if (script.contains(placeholder.toString())) {
Object val = values.get(placeholder);
String sVal = String.valueOf(val);
if (val instanceof String && !(sVal.startsWith("\"") && sVal.endsWith("\""))) {
sVal = String.format("\"%s\"", sVal);
}
script = script.replace(placeholder.toString(), sVal);
}
}
String result = String.valueOf(engine.eval(script));
newString = newString.replace(withBrackets, result);
}
return newString;
} catch (ScriptException e) {
plugin.debug("Failed to eval placeholder script in string: " + string);
plugin.debug(e);
}
return string;
}
}

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.config;
public enum Regex {
public enum Placeholder {
VENDOR("%VENDOR%"),
AMOUNT("%AMOUNT%"),
@ -27,11 +27,12 @@ public enum Regex {
private String name;
Regex(String name) {
Placeholder(String name) {
this.name = name;
}
public String getName() {
@Override
public String toString() {
return name;
}

View File

@ -2,7 +2,7 @@ package de.epiceric.shopchest.language;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.LanguageConfiguration;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.nms.CustomBookMeta;
import de.epiceric.shopchest.nms.SpawnEggMeta;
import de.epiceric.shopchest.utils.Utils;
@ -1003,36 +1003,36 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.DOUBLE_CHEST_BLOCKED, langConfig.getString("message.double-chest-blocked", "&cThere must not be a block above the chest.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_REMOVED, langConfig.getString("message.shop-removed", "&6Shop removed.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHEST_NO_SHOP, langConfig.getString("message.chest-no-shop", "&cChest is not a shop.")));
messages.add(new LocalizedMessage(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."), Regex.CREATION_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_VENDOR, langConfig.getString("message.shopInfo.vendor", "&6Vendor: &e%VENDOR%"), Regex.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRODUCT, langConfig.getString("message.shopInfo.product", "&6Product: &e%AMOUNT% x %ITEMNAME%"), Regex.AMOUNT, Regex.ITEM_NAME));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_STOCK, langConfig.getString("message.shopInfo.stock", "&6In Stock: &e%AMOUNT%"), Regex.AMOUNT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS, langConfig.getString("message.shopInfo.enchantments", "&6Enchantments: &e%ENCHANTMENT%"), Regex.ENCHANTMENT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, langConfig.getString("message.shopInfo.potion-effect", "&6Potion Effect: &e%POTION-EFFECT% %EXTENDED%"), Regex.POTION_EFFECT, Regex.EXTENDED));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE, langConfig.getString("message.shopInfo.music-disc-title", "&6Music Disc Title: &e%MUSIC-TITLE%"), Regex.MUSIC_TITLE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_BOOK_GENERATION, langConfig.getString("message.shopInfo.book-generation", "&6Generation: &e%GENERATION%"), Regex.GENERATION));
messages.add(new LocalizedMessage(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."), Placeholder.CREATION_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_VENDOR, langConfig.getString("message.shopInfo.vendor", "&6Vendor: &e%VENDOR%"), Placeholder.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRODUCT, langConfig.getString("message.shopInfo.product", "&6Product: &e%AMOUNT% x %ITEMNAME%"), Placeholder.AMOUNT, Placeholder.ITEM_NAME));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_STOCK, langConfig.getString("message.shopInfo.stock", "&6In Stock: &e%AMOUNT%"), Placeholder.AMOUNT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS, langConfig.getString("message.shopInfo.enchantments", "&6Enchantments: &e%ENCHANTMENT%"), Placeholder.ENCHANTMENT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT, langConfig.getString("message.shopInfo.potion-effect", "&6Potion Effect: &e%POTION-EFFECT% %EXTENDED%"), Placeholder.POTION_EFFECT, Placeholder.EXTENDED));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE, langConfig.getString("message.shopInfo.music-disc-title", "&6Music Disc Title: &e%MUSIC-TITLE%"), Placeholder.MUSIC_TITLE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_BOOK_GENERATION, langConfig.getString("message.shopInfo.book-generation", "&6Generation: &e%GENERATION%"), Placeholder.GENERATION));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_NONE, langConfig.getString("message.shopInfo.none", "&7None")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRICE, langConfig.getString("message.shopInfo.price", "&6Price: Buy: &e%BUY-PRICE%&6 Sell: &e%SELL-PRICE%"), Regex.BUY_PRICE, Regex.SELL_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_PRICE, langConfig.getString("message.shopInfo.price", "&6Price: Buy: &e%BUY-PRICE%&6 Sell: &e%SELL-PRICE%"), Placeholder.BUY_PRICE, Placeholder.SELL_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_DISABLED, langConfig.getString("message.shopInfo.disabled", "&7Disabled")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_NORMAL, langConfig.getString("message.shopInfo.is-normal", "&6Type: &eNormal")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_ADMIN, langConfig.getString("message.shopInfo.is-admin", "&6Type: &eAdmin")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_INFO_EXTENDED, langConfig.getString("message.shopInfo.extended", "(Extended)")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SELL_DISABLED, langConfig.getString("message.buy-and-sell-disabled", "&cYou can't create a shop with buying and selling disabled.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SUCCESS, langConfig.getString("message.buy-success", "&aYou bought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a from &6%VENDOR%&a."), Regex.AMOUNT, Regex.ITEM_NAME, Regex.BUY_PRICE, Regex.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SUCESS_ADMIN, langConfig.getString("message.buy-success-admin", "&aYou bought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a."), Regex.AMOUNT, Regex.ITEM_NAME, Regex.BUY_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_SUCESS, langConfig.getString("message.sell-success", "&aYou sold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%&a to &6%VENDOR%&a."), Regex.AMOUNT, Regex.ITEM_NAME, Regex.SELL_PRICE, Regex.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_SUCESS_ADMIN, langConfig.getString("message.sell-success-admin", "&aYou sold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%&a."), Regex.AMOUNT, Regex.ITEM_NAME, Regex.SELL_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SOMEONE_BOUGHT, langConfig.getString("message.someone-bought", "&6%PLAYER% &abought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a from your shop."), Regex.PLAYER, Regex.AMOUNT, Regex.ITEM_NAME, Regex.BUY_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SOMEONE_SOLD, langConfig.getString("message.someone-sold", "&6%PLAYER% &asold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%&a to your shop."), Regex.PLAYER, Regex.AMOUNT, Regex.ITEM_NAME, Regex.SELL_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.REVENUE_WHILE_OFFLINE, langConfig.getString("message.revenue-while-offline", "&6While you were offline, your shops have made a revenue of &c%REVENUE%&6."), Regex.REVENUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SUCCESS, langConfig.getString("message.buy-success", "&aYou bought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a from &6%VENDOR%&a."), Placeholder.AMOUNT, Placeholder.ITEM_NAME, Placeholder.BUY_PRICE, Placeholder.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_SUCESS_ADMIN, langConfig.getString("message.buy-success-admin", "&aYou bought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a."), Placeholder.AMOUNT, Placeholder.ITEM_NAME, Placeholder.BUY_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_SUCESS, langConfig.getString("message.sell-success", "&aYou sold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%&a to &6%VENDOR%&a."), Placeholder.AMOUNT, Placeholder.ITEM_NAME, Placeholder.SELL_PRICE, Placeholder.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_SUCESS_ADMIN, langConfig.getString("message.sell-success-admin", "&aYou sold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%&a."), Placeholder.AMOUNT, Placeholder.ITEM_NAME, Placeholder.SELL_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SOMEONE_BOUGHT, langConfig.getString("message.someone-bought", "&6%PLAYER% &abought &6%AMOUNT% x %ITEMNAME%&a for &6%BUY-PRICE%&a from your shop."), Placeholder.PLAYER, Placeholder.AMOUNT, Placeholder.ITEM_NAME, Placeholder.BUY_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SOMEONE_SOLD, langConfig.getString("message.someone-sold", "&6%PLAYER% &asold &6%AMOUNT% x %ITEMNAME%&a for &6%SELL-PRICE%&a to your shop."), Placeholder.PLAYER, Placeholder.AMOUNT, Placeholder.ITEM_NAME, Placeholder.SELL_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.REVENUE_WHILE_OFFLINE, langConfig.getString("message.revenue-while-offline", "&6While you were offline, your shops have made a revenue of &c%REVENUE%&6."), Placeholder.REVENUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NOT_ENOUGH_INVENTORY_SPACE, langConfig.getString("message.not-enough-inventory-space", "&cNot enough space in inventory.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHEST_NOT_ENOUGH_INVENTORY_SPACE, langConfig.getString("message.chest-not-enough-inventory-space", "&cShop is full.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NOT_ENOUGH_MONEY, langConfig.getString("message.not-enough-money", "&cNot enough money.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.NOT_ENOUGH_ITEMS, langConfig.getString("message.not-enough-items", "&cNot enough items.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.VENDOR_NOT_ENOUGH_MONEY, langConfig.getString("message.vendor-not-enough-money", "&cVendor has not enough money.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.OUT_OF_STOCK, langConfig.getString("message.out-of-stock", "&cShop out of stock.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.VENDOR_OUT_OF_STOCK, langConfig.getString("message.vendor-out-of-stock", "&cYour shop that sells &6%AMOUNT% x %ITEMNAME% &cis out of stock."), Regex.AMOUNT, Regex.ITEM_NAME));
messages.add(new LocalizedMessage(LocalizedMessage.Message.ERROR_OCCURRED, langConfig.getString("message.error-occurred", "&cAn error occurred: %ERROR%"), Regex.ERROR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.VENDOR_OUT_OF_STOCK, langConfig.getString("message.vendor-out-of-stock", "&cYour shop that sells &6%AMOUNT% x %ITEMNAME% &cis out of stock."), Placeholder.AMOUNT, Placeholder.ITEM_NAME));
messages.add(new LocalizedMessage(LocalizedMessage.Message.ERROR_OCCURRED, langConfig.getString("message.error-occurred", "&cAn error occurred: %ERROR%"), Placeholder.ERROR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.AMOUNT_PRICE_NOT_NUMBER, langConfig.getString("message.amount-and-price-not-number", "&cAmount and price must be a number.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.AMOUNT_IS_ZERO, langConfig.getString("message.amount-is-zero", "&cAmount must be greater than 0.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.PRICES_CONTAIN_DECIMALS, langConfig.getString("message.prices-contain-decimals", "&cPrices must not contain decimals.")));
@ -1041,20 +1041,20 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_REMOVE, langConfig.getString("message.click-chest-to-remove-shop", "&aClick a shop to remove it.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_INFO, langConfig.getString("message.click-chest-for-info", "&aClick a shop to retrieve information.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CLICK_CHEST_OPEN, langConfig.getString("message.click-chest-to-open-shop", "&aClick a shop to open it.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.OPENED_SHOP, langConfig.getString("message.opened-shop", "&aYou opened %VENDOR%'s shop."), Regex.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.OPENED_SHOP, langConfig.getString("message.opened-shop", "&aYou opened %VENDOR%'s shop."), Placeholder.VENDOR));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP, langConfig.getString("message.cannot-break-shop", "&cYou can't break a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_SELL_BROKEN_ITEM, langConfig.getString("message.cannot-sell-broken-item", "&cYou can't sell a broken item.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, langConfig.getString("message.buy-price-too-low", "&cThe buy price must be higher than %MIN-PRICE%."), Regex.MIN_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_PRICE_TOO_LOW, langConfig.getString("message.sell-price-too-low", "&cThe sell price must be higher than %MIN-PRICE%."), Regex.MIN_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_PRICE_TOO_HIGH, langConfig.getString("message.buy-price-too-high", "&cThe buy price must be lower than %MAX-PRICE%."), Regex.MAX_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_PRICE_TOO_HIGH, langConfig.getString("message.sell-price-too-high", "&cThe sell price must be lower than %MAX-PRICE%."), Regex.MAX_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_PRICE_TOO_LOW, langConfig.getString("message.buy-price-too-low", "&cThe buy price must be higher than %MIN-PRICE%."), Placeholder.MIN_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_PRICE_TOO_LOW, langConfig.getString("message.sell-price-too-low", "&cThe sell price must be higher than %MIN-PRICE%."), Placeholder.MIN_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUY_PRICE_TOO_HIGH, langConfig.getString("message.buy-price-too-high", "&cThe buy price must be lower than %MAX-PRICE%."), Placeholder.MAX_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELL_PRICE_TOO_HIGH, langConfig.getString("message.sell-price-too-high", "&cThe sell price must be lower than %MAX-PRICE%."), Placeholder.MAX_PRICE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.BUYING_DISABLED, langConfig.getString("message.buying-disabled", "&cBuying is disabled at this shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SELLING_DISABLED, langConfig.getString("message.selling-disabled", "&cSelling is disabled at this shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.RELOADED_SHOPS, langConfig.getString("message.reloaded-shops", "&aSuccessfully reloaded %AMOUNT% shop/s."), Regex.AMOUNT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_LIMIT_REACHED, langConfig.getString("message.shop-limit-reached", "&cYou reached your limit of &6%LIMIT% &cshop/s."), Regex.LIMIT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.OCCUPIED_SHOP_SLOTS, langConfig.getString("message.occupied-shop-slots", "&6You have &c%AMOUNT%/%LIMIT% &6shop slot/s occupied."), Regex.AMOUNT, Regex.LIMIT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.RELOADED_SHOPS, langConfig.getString("message.reloaded-shops", "&aSuccessfully reloaded %AMOUNT% shop/s."), Placeholder.AMOUNT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.SHOP_LIMIT_REACHED, langConfig.getString("message.shop-limit-reached", "&cYou reached your limit of &6%LIMIT% &cshop/s."), Placeholder.LIMIT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.OCCUPIED_SHOP_SLOTS, langConfig.getString("message.occupied-shop-slots", "&6You have &c%AMOUNT%/%LIMIT% &6shop slot/s occupied."), Placeholder.AMOUNT, Placeholder.LIMIT));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CANNOT_SELL_ITEM, langConfig.getString("message.cannot-sell-item", "&cYou cannot create a shop with this item.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, langConfig.getString("message.update.update-available", "&6&lVersion &c%VERSION% &6of &cShopChest &6is available &chere."), Regex.VERSION));
messages.add(new LocalizedMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, langConfig.getString("message.update.update-available", "&6&lVersion &c%VERSION% &6of &cShopChest &6is available &chere."), Placeholder.VERSION));
messages.add(new LocalizedMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD, langConfig.getString("message.update.click-to-download", "Click to download")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.UPDATE_NO_UPDATE, langConfig.getString("message.update.no-update", "&6&lNo new update available.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.UPDATE_CHECKING, langConfig.getString("message.update.checking", "&6&lChecking for updates...")));
@ -1082,9 +1082,9 @@ public class LanguageUtils {
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_LIMITS, langConfig.getString("message.commandDescription.limits", "View shop limits.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_OPEN, langConfig.getString("message.commandDescription.open", "Open a shop.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.COMMAND_DESC_CONFIG, langConfig.getString("message.commandDescription.config", "Change configuration values.")));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, langConfig.getString("message.config.set", "&6Changed &a%PROPERTY% &6to &a%VALUE%&6."), Regex.PROPERTY, Regex.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, langConfig.getString("message.config.removed", "&6Removed &a%VALUE% &6from &a%PROPERTY%&6."), Regex.PROPERTY, Regex.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_ADDED, langConfig.getString("message.config.added", "&6Added &a%VALUE% &6to &a%PROPERTY%&6."), Regex.PROPERTY, Regex.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_SET, langConfig.getString("message.config.set", "&6Changed &a%PROPERTY% &6to &a%VALUE%&6."), Placeholder.PROPERTY, Placeholder.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_REMOVED, langConfig.getString("message.config.removed", "&6Removed &a%VALUE% &6from &a%PROPERTY%&6."), Placeholder.PROPERTY, Placeholder.VALUE));
messages.add(new LocalizedMessage(LocalizedMessage.Message.CHANGED_CONFIG_ADDED, langConfig.getString("message.config.added", "&6Added &a%VALUE% &6to &a%PROPERTY%&6."), Placeholder.PROPERTY, Placeholder.VALUE));
}
/**
@ -1092,6 +1092,7 @@ public class LanguageUtils {
* @return Localized Name of the Item, the custom name, or if <i>stack</i> is a book, the title of the book
*/
public static String getItemName(ItemStack stack) {
if (stack == null) return null;
if (stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
if (meta.getDisplayName() != null) {
@ -1187,6 +1188,7 @@ public class LanguageUtils {
* @return Localized Name of the enchantment with the given level afterwards
*/
public static String getEnchantmentName(Enchantment enchantment, int level) {
if (enchantment == null) return null;
String enchantmentString = formatDefaultString(enchantment.getName());
String levelString = langConfig.getString("enchantment.level." + level, String.valueOf(level));
@ -1210,6 +1212,7 @@ public class LanguageUtils {
* @return Comma separated list of localized enchantments
*/
public static String getEnchantmentString(Map<Enchantment, Integer> enchantmentMap) {
if (enchantmentMap == null) return null;
Enchantment[] enchantments = enchantmentMap.keySet().toArray(new Enchantment[enchantmentMap.size()]);
StringBuilder enchantmentList = new StringBuilder();
@ -1232,6 +1235,7 @@ public class LanguageUtils {
* @return Localized Name of the Base Potion Effect
*/
public static String getPotionEffectName(ItemStack itemStack) {
if (itemStack == null) return null;
if (!(itemStack.getItemMeta() instanceof PotionMeta)) return "";
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
@ -1263,6 +1267,7 @@ public class LanguageUtils {
* @return Localized title of the Music Disc
*/
public static String getMusicDiscName(Material musicDiscMaterial) {
if (musicDiscMaterial == null) return null;
for (MusicDiscName musicDiscName : musicDiscNames) {
if (musicDiscMaterial == musicDiscName.getMusicDiscMaterial()) {
return musicDiscName.getLocalizedName();
@ -1277,6 +1282,7 @@ public class LanguageUtils {
* @return Localized title of the generation
*/
public static String getBookGenerationName(CustomBookMeta.Generation generation) {
if (generation == null) return null;
for (BookGenerationName generationName : generationNames) {
if (generation == generationName.getGeneration()) {
return generationName.getLocalizedName();
@ -1294,8 +1300,8 @@ public class LanguageUtils {
public static String getMessage(LocalizedMessage.Message message, LocalizedMessage.ReplacedRegex... replacedRegexes) {
String _message = ChatColor.RED + "An error occurred: Message not found: " + message.toString();
ArrayList<Regex> neededRegexes = new ArrayList<>();
ArrayList<Regex> usedRegexes = new ArrayList<>();
ArrayList<Placeholder> neededRegexes = new ArrayList<>();
ArrayList<Placeholder> usedRegexes = new ArrayList<>();
for (LocalizedMessage localizedMessage : messages) {
if (localizedMessage.getMessage() == message) {
@ -1304,15 +1310,15 @@ public class LanguageUtils {
neededRegexes.add(replacedRegex.getRegex());
for (int i = 0; i < localizedMessage.getRegexes().length; i++) {
if (localizedMessage.getRegexes()[i] == replacedRegex.getRegex()) {
Regex regex = replacedRegex.getRegex();
Placeholder regex = replacedRegex.getRegex();
String toReplace = replacedRegex.getReplace();
if (regex == Regex.BUY_PRICE || regex == Regex.SELL_PRICE || regex == Regex.MIN_PRICE || regex == Regex.CREATION_PRICE || regex == Regex.REVENUE) {
if (regex == Placeholder.BUY_PRICE || regex == Placeholder.SELL_PRICE || regex == Placeholder.MIN_PRICE || regex == Placeholder.CREATION_PRICE || regex == Placeholder.REVENUE) {
if (!toReplace.equals(getMessage(LocalizedMessage.Message.SHOP_INFO_DISABLED))) {
double price = Double.parseDouble(toReplace);
toReplace = plugin.getEconomy().format(price);
}
}
_message = _message.replace(regex.getName(), toReplace);
_message = _message.replace(regex.toString(), toReplace);
usedRegexes.add(regex);
break;
}
@ -1322,9 +1328,9 @@ public class LanguageUtils {
}
if (!neededRegexes.containsAll(usedRegexes)) {
for (Regex regex : usedRegexes) {
for (Placeholder regex : usedRegexes) {
if (!neededRegexes.contains(regex)) {
plugin.getLogger().warning("Regex '" + regex.toString() + "' was not used in message '" + message.toString() + "'");
plugin.getLogger().warning("Placeholder '" + regex.toString() + "' was not used in message '" + message.toString() + "'");
}
}
}

View File

@ -1,15 +1,15 @@
package de.epiceric.shopchest.language;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.config.Placeholder;
import org.bukkit.ChatColor;
public class LocalizedMessage {
private Message message;
private Regex[] regexes;
private Placeholder[] regexes;
private String localizedString;
public LocalizedMessage(Message message, String localizedString, Regex... regexes) {
public LocalizedMessage(Message message, String localizedString, Placeholder... regexes) {
this.message = message;
this.regexes = regexes;
this.localizedString = ChatColor.translateAlternateColorCodes('&', localizedString);
@ -28,9 +28,9 @@ public class LocalizedMessage {
}
/**
* @return Array of {@link Regex}, which are required by the message
* @return Array of {@link Placeholder}, which are required by the message
*/
public Regex[] getRegexes() {
public Placeholder[] getRegexes() {
return regexes;
}
@ -134,10 +134,10 @@ public class LocalizedMessage {
public static class ReplacedRegex {
private Regex regex;
private Placeholder regex;
private String replace;
public ReplacedRegex(Regex regex, String replace) {
public ReplacedRegex(Placeholder regex, String replace) {
this.regex = regex;
this.replace = replace;
}
@ -150,9 +150,9 @@ public class LocalizedMessage {
}
/**
* @return Regex that will be replaced
* @return Placeholder that will be replaced
*/
public Regex getRegex() {
public Placeholder getRegex() {
return regex;
}

View File

@ -1,7 +1,7 @@
package de.epiceric.shopchest.listeners;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.language.LanguageUtils;
import de.epiceric.shopchest.language.LocalizedMessage;
import de.epiceric.shopchest.nms.JsonBuilder;
@ -27,7 +27,7 @@ public class NotifyPlayerOnJoinListener implements Listener {
if (plugin.isUpdateNeeded()) {
if (p.hasPermission(Permissions.UPDATE_NOTIFICATION)) {
JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Placeholder.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink());
jb.sendJson(p);
}
}
@ -39,7 +39,7 @@ public class NotifyPlayerOnJoinListener implements Listener {
long lastLogout = (long) result;
if (lastLogout < 0) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED,
new LocalizedMessage.ReplacedRegex(Regex.ERROR, "Could not get last time you logged out")));
new LocalizedMessage.ReplacedRegex(Placeholder.ERROR, "Could not get last time you logged out")));
return;
}
@ -50,7 +50,7 @@ public class NotifyPlayerOnJoinListener implements Listener {
double revenue = (double) result;
if (revenue != 0) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.REVENUE_WHILE_OFFLINE,
new LocalizedMessage.ReplacedRegex(Regex.REVENUE, String.valueOf(revenue))));
new LocalizedMessage.ReplacedRegex(Placeholder.REVENUE, String.valueOf(revenue))));
}
}
}

View File

@ -14,7 +14,7 @@ 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.Regex;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.event.*;
import de.epiceric.shopchest.external.PlotSquaredShopFlag;
import de.epiceric.shopchest.external.WorldGuardShopFlag;
@ -444,8 +444,8 @@ public class ShopInteractListener implements Listener {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OUT_OF_STOCK));
if (shop.getVendor().isOnline() && config.enable_vendor_messages) {
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.VENDOR_OUT_OF_STOCK,
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(shop.getProduct()))));
new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(shop.getProduct()))));
}
plugin.debug("Shop is out of stock");
}
@ -629,7 +629,7 @@ public class ShopInteractListener implements Listener {
EconomyResponse r = plugin.getEconomy().withdrawPlayer(executor, location.getWorld().getName(), creationPrice);
if (!r.transactionSuccess()) {
plugin.debug("Economy transaction failed: " + r.errorMessage);
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r.errorMessage)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Placeholder.ERROR, r.errorMessage)));
return;
}
@ -690,7 +690,7 @@ public class ShopInteractListener implements Listener {
executor.openInventory(shop.getInventoryHolder().getInventory());
plugin.debug("Opened shop (#" + shop.getID() + ")");
if (message) executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OPENED_SHOP, new LocalizedMessage.ReplacedRegex(Regex.VENDOR, shop.getVendor().getName())));
if (message) executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.OPENED_SHOP, new LocalizedMessage.ReplacedRegex(Placeholder.VENDOR, shop.getVendor().getName())));
}
/**
@ -717,11 +717,11 @@ public class ShopInteractListener implements Listener {
shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
String vendorString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_VENDOR,
new LocalizedMessage.ReplacedRegex(Regex.VENDOR, vendorName));
new LocalizedMessage.ReplacedRegex(Placeholder.VENDOR, vendorName));
String productString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_PRODUCT,
new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(shop.getProduct())));
new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(shop.getProduct().getAmount())),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(shop.getProduct())));
String enchantmentString = "";
String potionEffectString = "";
@ -731,14 +731,14 @@ public class ShopInteractListener implements Listener {
String disabled = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_DISABLED);
String priceString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_PRICE,
new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, (shop.getBuyPrice() > 0 ? String.valueOf(shop.getBuyPrice()) : disabled)),
new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, (shop.getSellPrice() > 0 ? String.valueOf(shop.getSellPrice()) : disabled)));
new LocalizedMessage.ReplacedRegex(Placeholder.BUY_PRICE, (shop.getBuyPrice() > 0 ? String.valueOf(shop.getBuyPrice()) : disabled)),
new LocalizedMessage.ReplacedRegex(Placeholder.SELL_PRICE, (shop.getSellPrice() > 0 ? String.valueOf(shop.getSellPrice()) : disabled)));
String shopType = LanguageUtils.getMessage(shop.getShopType() == ShopType.NORMAL ?
LocalizedMessage.Message.SHOP_INFO_NORMAL : LocalizedMessage.Message.SHOP_INFO_ADMIN);
String stock = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_STOCK,
new LocalizedMessage.ReplacedRegex(Regex.STOCK, String.valueOf(amount)));
new LocalizedMessage.ReplacedRegex(Placeholder.STOCK, String.valueOf(amount)));
String potionEffectName = LanguageUtils.getPotionEffectName(shop.getProduct());
@ -747,8 +747,8 @@ public class ShopInteractListener implements Listener {
String extended = potionExtended ? LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_EXTENDED) : "";
potionEffectString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_POTION_EFFECT,
new LocalizedMessage.ReplacedRegex(Regex.POTION_EFFECT, potionEffectName),
new LocalizedMessage.ReplacedRegex(Regex.EXTENDED, extended));
new LocalizedMessage.ReplacedRegex(Placeholder.POTION_EFFECT, potionEffectName),
new LocalizedMessage.ReplacedRegex(Placeholder.EXTENDED, extended));
}
if (type == Material.WRITTEN_BOOK) {
@ -767,13 +767,13 @@ public class ShopInteractListener implements Listener {
}
bookGenerationString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_BOOK_GENERATION,
new LocalizedMessage.ReplacedRegex(Regex.GENERATION, LanguageUtils.getBookGenerationName(generation)));
new LocalizedMessage.ReplacedRegex(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(generation)));
}
String musicDiscName = LanguageUtils.getMusicDiscName(type);
if (musicDiscName.length() > 0) {
musicDiscTitleString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_MUSIC_TITLE,
new LocalizedMessage.ReplacedRegex(Regex.MUSIC_TITLE, musicDiscName));
new LocalizedMessage.ReplacedRegex(Placeholder.MUSIC_TITLE, musicDiscName));
}
Map<Enchantment, Integer> enchantmentMap = ItemUtils.getEnchantments(shop.getProduct());
@ -781,7 +781,7 @@ public class ShopInteractListener implements Listener {
if (enchantmentList.length() > 0) {
enchantmentString = LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_INFO_ENCHANTMENTS,
new LocalizedMessage.ReplacedRegex(Regex.ENCHANTMENT, enchantmentList));
new LocalizedMessage.ReplacedRegex(Placeholder.ENCHANTMENT, enchantmentList));
}
executor.sendMessage(" ");
@ -890,21 +890,21 @@ public class ShopInteractListener implements Listener {
executor.updateInventory();
String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_SUCCESS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Regex.VENDOR, vendorName)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_SUCCESS, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Placeholder.VENDOR, vendorName)));
plugin.debug(executor.getName() + " successfully bought (#" + shop.getID() + ")");
if (shop.getVendor().isOnline() && config.enable_vendor_messages) {
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SOMEONE_BOUGHT, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Regex.PLAYER, executor.getName())));
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SOMEONE_BOUGHT, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Placeholder.BUY_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Placeholder.PLAYER, executor.getName())));
}
} else {
plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")");
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r2.errorMessage)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Placeholder.ERROR, r2.errorMessage)));
econ.depositPlayer(executor, newPrice);
}
} else {
@ -921,14 +921,14 @@ public class ShopInteractListener implements Listener {
addToInventory(inventory, newProduct);
executor.updateInventory();
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_SUCESS_ADMIN, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(newPrice))));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.BUY_SUCESS_ADMIN, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Placeholder.BUY_PRICE, String.valueOf(newPrice))));
plugin.debug(executor.getName() + " successfully bought (#" + shop.getID() + ")");
}
} else {
plugin.debug("Economy transaction failed (r): " + r.errorMessage + " (#" + shop.getID() + ")");
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r.errorMessage)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Placeholder.ERROR, r.errorMessage)));
}
} else {
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NOT_ENOUGH_INVENTORY_SPACE));
@ -1029,21 +1029,21 @@ public class ShopInteractListener implements Listener {
executor.updateInventory();
String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName());
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_SUCESS, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Regex.VENDOR, vendorName)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_SUCESS, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Placeholder.VENDOR, vendorName)));
plugin.debug(executor.getName() + " successfully sold (#" + shop.getID() + ")");
if (shop.getVendor().isOnline() && config.enable_vendor_messages) {
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SOMEONE_SOLD, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Regex.PLAYER, executor.getName())));
shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SOMEONE_SOLD, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Placeholder.SELL_PRICE, String.valueOf(newPrice)),
new LocalizedMessage.ReplacedRegex(Placeholder.PLAYER, executor.getName())));
}
} else {
plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")");
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r2.errorMessage)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Placeholder.ERROR, r2.errorMessage)));
econ.withdrawPlayer(executor, newPrice);
}
@ -1061,15 +1061,15 @@ public class ShopInteractListener implements Listener {
removeFromInventory(executor.getInventory(), newProduct);
executor.updateInventory();
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_SUCESS_ADMIN, new LocalizedMessage.ReplacedRegex(Regex.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Regex.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(newPrice))));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SELL_SUCESS_ADMIN, new LocalizedMessage.ReplacedRegex(Placeholder.AMOUNT, String.valueOf(newAmount)),
new LocalizedMessage.ReplacedRegex(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new LocalizedMessage.ReplacedRegex(Placeholder.SELL_PRICE, String.valueOf(newPrice))));
plugin.debug(executor.getName() + " successfully sold (#" + shop.getID() + ")");
}
} else {
plugin.debug("Economy transaction failed (r): " + r.errorMessage + " (#" + shop.getID() + ")");
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r.errorMessage)));
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Placeholder.ERROR, r.errorMessage)));
}
} else {

View File

@ -3,7 +3,7 @@ package de.epiceric.shopchest.shop;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.config.HologramFormat;
import de.epiceric.shopchest.config.Regex;
import de.epiceric.shopchest.config.Placeholder;
import de.epiceric.shopchest.exceptions.ChestNotFoundException;
import de.epiceric.shopchest.exceptions.NotEnoughSpaceException;
import de.epiceric.shopchest.language.LanguageUtils;
@ -195,7 +195,6 @@ public class Shop {
List<String> lines = new ArrayList<>();
Map<HologramFormat.Requirement, Object> requirements = new HashMap<>();
requirements.put(HologramFormat.Requirement.VENDOR, getVendor().getName());
requirements.put(HologramFormat.Requirement.AMOUNT, getProduct().getAmount());
requirements.put(HologramFormat.Requirement.ITEM_TYPE, getProduct().getType() + (getProduct().getDurability() > 0 ? ":" + getProduct().getDurability() : ""));
@ -212,48 +211,37 @@ public class Shop {
requirements.put(HologramFormat.Requirement.IN_STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct()));
requirements.put(HologramFormat.Requirement.MAX_STACK, getProduct().getMaxStackSize());
Map<Placeholder, Object> placeholders = new HashMap<>();
placeholders.put(Placeholder.VENDOR, getVendor().getName());
placeholders.put(Placeholder.AMOUNT, getProduct().getAmount());
placeholders.put(Placeholder.ITEM_NAME, LanguageUtils.getItemName(getProduct()));
placeholders.put(Placeholder.ENCHANTMENT, LanguageUtils.getEnchantmentString(ItemUtils.getEnchantments(getProduct())));
placeholders.put(Placeholder.BUY_PRICE, getBuyPrice());
placeholders.put(Placeholder.SELL_PRICE, getSellPrice());
placeholders.put(Placeholder.POTION_EFFECT, LanguageUtils.getPotionEffectName(getProduct()));
placeholders.put(Placeholder.MUSIC_TITLE, LanguageUtils.getMusicDiscName(getProduct().getType()));
placeholders.put(Placeholder.GENERATION, LanguageUtils.getBookGenerationName(ItemUtils.getBookGeneration(getProduct())));
placeholders.put(Placeholder.STOCK, Utils.getAmount(getInventoryHolder().getInventory(), getProduct()));
int lineCount = plugin.getHologramFormat().getLineCount();
for (int i = 0; i < lineCount; i++) {
String format = plugin.getHologramFormat().getFormat(i, requirements);
for (Regex regex : Regex.values()) {
String format = plugin.getHologramFormat().getFormat(i, requirements, placeholders);
for (Placeholder regex : placeholders.keySet()) {
String replace = "";
switch (regex) {
case VENDOR:
replace = getVendor().getName();
break;
case AMOUNT:
replace = String.valueOf(getProduct().getAmount());
break;
case ITEM_NAME:
replace = LanguageUtils.getItemName(getProduct());
break;
case ENCHANTMENT:
replace = LanguageUtils.getEnchantmentString(ItemUtils.getEnchantments(getProduct()));
break;
case BUY_PRICE:
replace = plugin.getEconomy().format(getBuyPrice());
break;
case SELL_PRICE:
replace = plugin.getEconomy().format(getSellPrice());
break;
case POTION_EFFECT:
replace = LanguageUtils.getPotionEffectName(getProduct());
break;
case MUSIC_TITLE:
replace = LanguageUtils.getMusicDiscName(getProduct().getType());
break;
case GENERATION:
CustomBookMeta.Generation gen = ItemUtils.getBookGeneration(getProduct());
if (gen != null) replace = LanguageUtils.getBookGenerationName(gen);
break;
case STOCK:
replace = String.valueOf(Utils.getAmount(getInventoryHolder().getInventory(), getProduct()));
break;
default:
replace = String.valueOf(placeholders.get(regex));
}
format = format.replace(regex.getName(), replace);
format = format.replace(regex.toString(), replace);
}
lines.add(format);

View File

@ -26,11 +26,17 @@
# %SELL-PRICE%, %POTION-EFFECT%, %MUSIC-TITLE%, %GENERATION%,
# %STOCK%, %MAX-STACK%
#
# In the format, placeholders can also be used for scripts.
# Examples:
# - "In Stock: {%STOCK% / 64} Stk."
# - "In Stock: {(%STOCK% - (%STOCK% % 64)) / 64} Stk. {%STOCK% % 64}"
#
# Other information:
# - Options can be called however you want.
# - Color codes can be used in the format.
# - Options are checked from top to bottom; the first to
# fulfill the requirements will be taken.
# - All scripts have to be in JavaScript syntax.
# - Lines start with 0.
lines: