diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java index d452b4a..32275c0 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java @@ -337,7 +337,7 @@ public class ShopInteractListener implements Listener { if (shop.getVendor().isOnline() && Config.enableVendorMessages) { shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.VENDOR_OUT_OF_STOCK, new Replacement(Placeholder.AMOUNT, String.valueOf(shop.getProduct().getAmount())), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(itemStack)))); + new Replacement(Placeholder.ITEM_NAME, shop.getProduct().getLocalizedName()))); } plugin.debug("Shop is out of stock"); } @@ -639,7 +639,7 @@ public class ShopInteractListener implements Listener { new Replacement(Placeholder.AMOUNT, String.valueOf(product.getAmount()))) + " "; String[] parts = productString.split(Placeholder.ITEM_NAME.toString()); - String productName = LanguageUtils.getItemName(product.getItemStack()); + String productName = product.getLocalizedName(); String jsonItem = ""; JsonBuilder jb = new JsonBuilder(plugin); JsonBuilder.PartArray rootArray = new JsonBuilder.PartArray(); @@ -806,14 +806,14 @@ public class ShopInteractListener implements Listener { String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName()); executor.sendMessage(LanguageUtils.getMessage(Message.BUY_SUCCESS, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)), + new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)), new Replacement(Placeholder.VENDOR, vendorName))); plugin.debug(executor.getName() + " successfully bought (#" + shop.getID() + ")"); if (shop.getVendor().isOnline() && Config.enableVendorMessages) { shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_BOUGHT, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)), + new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)), new Replacement(Placeholder.PLAYER, executor.getName()))); } @@ -848,7 +848,7 @@ public class ShopInteractListener implements Listener { }.runTaskLater(plugin, 1L); executor.sendMessage(LanguageUtils.getMessage(Message.BUY_SUCCESS_ADMIN, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)))); + new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.BUY_PRICE, String.valueOf(newPrice)))); plugin.debug(executor.getName() + " successfully bought (#" + shop.getID() + ")"); } @@ -969,14 +969,14 @@ public class ShopInteractListener implements Listener { String vendorName = (shop.getVendor().getName() == null ? shop.getVendor().getUniqueId().toString() : shop.getVendor().getName()); executor.sendMessage(LanguageUtils.getMessage(Message.SELL_SUCCESS, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)), + new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)), new Replacement(Placeholder.VENDOR, vendorName))); plugin.debug(executor.getName() + " successfully sold (#" + shop.getID() + ")"); if (shop.getVendor().isOnline() && Config.enableVendorMessages) { shop.getVendor().getPlayer().sendMessage(LanguageUtils.getMessage(Message.SOMEONE_SOLD, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)), + new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)), new Replacement(Placeholder.PLAYER, executor.getName()))); } @@ -1012,7 +1012,7 @@ public class ShopInteractListener implements Listener { }.runTaskLater(plugin, 1L); executor.sendMessage(LanguageUtils.getMessage(Message.SELL_SUCCESS_ADMIN, new Replacement(Placeholder.AMOUNT, String.valueOf(newAmount)), - new Replacement(Placeholder.ITEM_NAME, LanguageUtils.getItemName(product)), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)))); + new Replacement(Placeholder.ITEM_NAME, newProduct.getLocalizedName()), new Replacement(Placeholder.SELL_PRICE, String.valueOf(newPrice)))); plugin.debug(executor.getName() + " successfully sold (#" + shop.getID() + ")"); } diff --git a/src/main/java/de/epiceric/shopchest/shop/Shop.java b/src/main/java/de/epiceric/shopchest/shop/Shop.java index 5e8e88e..26d7003 100644 --- a/src/main/java/de/epiceric/shopchest/shop/Shop.java +++ b/src/main/java/de/epiceric/shopchest/shop/Shop.java @@ -279,7 +279,7 @@ public class Shop { Map placeholders = new EnumMap<>(Placeholder.class); placeholders.put(Placeholder.VENDOR, getVendor().getName()); placeholders.put(Placeholder.AMOUNT, getProduct().getAmount()); - placeholders.put(Placeholder.ITEM_NAME, LanguageUtils.getItemName(itemStack)); + placeholders.put(Placeholder.ITEM_NAME, getProduct().getLocalizedName()); placeholders.put(Placeholder.ENCHANTMENT, LanguageUtils.getEnchantmentString(ItemUtils.getEnchantments(itemStack))); placeholders.put(Placeholder.BUY_PRICE, getBuyPrice()); placeholders.put(Placeholder.SELL_PRICE, getSellPrice()); diff --git a/src/main/java/de/epiceric/shopchest/shop/ShopProduct.java b/src/main/java/de/epiceric/shopchest/shop/ShopProduct.java index 19d78c2..b0030ad 100644 --- a/src/main/java/de/epiceric/shopchest/shop/ShopProduct.java +++ b/src/main/java/de/epiceric/shopchest/shop/ShopProduct.java @@ -2,6 +2,8 @@ package de.epiceric.shopchest.shop; import org.bukkit.inventory.ItemStack; +import de.epiceric.shopchest.language.LanguageUtils; + public class ShopProduct { private final ItemStack itemStack; @@ -17,6 +19,13 @@ public class ShopProduct { this(itemStack, itemStack.getAmount()); } + /** + * @return The localized name of the product's {@link ItemStack} in the selected language file. + */ + public String getLocalizedName() { + return LanguageUtils.getItemName(getItemStack()); + } + /** * @return The {@link ItemStack} with an amount of {@code 1}. */ diff --git a/src/main/java/de/epiceric/shopchest/sql/Database.java b/src/main/java/de/epiceric/shopchest/sql/Database.java index 2b26f3f..9443be2 100644 --- a/src/main/java/de/epiceric/shopchest/sql/Database.java +++ b/src/main/java/de/epiceric/shopchest/sql/Database.java @@ -5,7 +5,6 @@ import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.event.ShopBuySellEvent; import de.epiceric.shopchest.event.ShopBuySellEvent.Type; import de.epiceric.shopchest.exceptions.WorldNotFoundException; -import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.ShopProduct; import de.epiceric.shopchest.shop.Shop.ShopType; @@ -526,7 +525,7 @@ public abstract class Database { ps.setLong(3, millis); ps.setString(4, executor.getName()); ps.setString(5, executor.getUniqueId().toString()); - ps.setString(6, LanguageUtils.getItemName(product.getItemStack())); + ps.setString(6, product.getLocalizedName()); ps.setString(7, Utils.encode(product.getItemStack())); ps.setInt(8, product.getAmount()); ps.setString(9, shop.getVendor().getName());