diff --git a/src/main/java/org/maxgamer/quickshop/QuickShop.java b/src/main/java/org/maxgamer/quickshop/QuickShop.java index 90fecbd1f..9717a2937 100644 --- a/src/main/java/org/maxgamer/quickshop/QuickShop.java +++ b/src/main/java/org/maxgamer/quickshop/QuickShop.java @@ -6,10 +6,12 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; @@ -25,7 +27,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.scheduler.BukkitTask; import org.maxgamer.quickshop.Command.QS; @@ -50,6 +52,7 @@ import org.maxgamer.quickshop.Shop.Shop; import org.maxgamer.quickshop.Shop.ShopManager; import org.maxgamer.quickshop.Shop.ShopType; import org.maxgamer.quickshop.Util.CustomItemName; +import org.maxgamer.quickshop.Util.CustomPotionsName; import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Permissions; import org.maxgamer.quickshop.Util.Util; @@ -104,7 +107,7 @@ public class QuickShop extends JavaPlugin { /** Whether debug info should be shown in the console */ public static boolean debug = false; - private Map customItemNames = new HashMap(); + private Map> customItemsName = new HashMap>(); /** The plugin metrics from Hidendra */ // public Metrics getMetrics(){ return metrics; } @@ -156,8 +159,8 @@ public class QuickShop extends JavaPlugin { getServer().getPluginManager().registerEvents(ll, this); } - if (this.getConfig().isSet("custom-names")) { - for (String s : this.getConfig().getStringList("custom-names")) { + if (this.getConfig().isSet("custom-items-name")) { + for (String s : this.getConfig().getStringList("custom-items-name")) { try { String[] mainVal = s.split("[;]"); if (mainVal.length!=3) { @@ -172,18 +175,10 @@ public class QuickShop extends JavaPlugin { ItemStack is; if (matVal.length>1) { - if (material==Material.POTION) { - PotionType potionType = PotionType.valueOf(matVal[1].toUpperCase()); - if (potionType==null) { - throw new Exception("Invalid PotionType: "+matVal[1]); - } - is = new Potion(potionType).toItemStack(1); - } else { - try { - is = new ItemStack(material, 1, Short.valueOf(matVal[1])); - } catch (Exception e) { - throw new Exception("Invalid data value: "+matVal[1]); - } + try { + is = new ItemStack(material, 1, Short.valueOf(matVal[1])); + } catch (Exception e) { + throw new Exception("Invalid data value: "+matVal[1]); } } else { is = new ItemStack(material, 1, (short) 0); @@ -193,13 +188,66 @@ public class QuickShop extends JavaPlugin { Bukkit.getLogger().warning("Custom item name definition {"+s+"} sign name is longer than 16 characters. Only the first 16 characters will be shown."); } - customItemNames.put(is, new CustomItemName(is, mainVal[1], mainVal[2])); + List cinList = customItemsName.get(material); + if (cinList==null) { + cinList = new ArrayList(); + customItemsName.put(material, cinList); + } + + cinList.add(new CustomItemName(is, mainVal[1], mainVal[2])); } catch (Exception e) { Bukkit.getLogger().warning("Invalid custom item name definition {"+s+"} Error: "+e.getMessage()); } } } + ConfigurationSection customPotionsName = this.getConfig().getConfigurationSection("custom-potions-name"); + if (customPotionsName!=null) { + CustomPotionsName.setFullPotionFormat(customPotionsName.getString("format-full")); + CustomPotionsName.setSignPotionFormat(customPotionsName.getString("format-sign")); + CustomPotionsName.setSplashFull(customPotionsName.getString("splash-full")); + CustomPotionsName.setSplashSign(customPotionsName.getString("splash-sign")); + Map potionTypes = new HashMap(); + for (String s : customPotionsName.getStringList("types")) { + try { + String[] a = s.split("[;]"); + if (a.length!=3) { + throw new Exception("Invalid format (main args length must be 3)"); + } + + PotionType type = PotionType.valueOf(a[0].toUpperCase()); + if (type==null) { + throw new Exception("Invalid PotionType "+a[0]); + } + + potionTypes.put(type, new CustomPotionsName.Names(a[1], a[2])); + } catch (Exception e) { + Bukkit.getLogger().warning("Invalid potion item name definition {"+s+"} Error: "+e.getMessage()); + } + } + CustomPotionsName.setPotionTypes(potionTypes); + + Map potionEffects = new HashMap(); + for (String s : customPotionsName.getStringList("effects")) { + try { + String[] a = s.split("[;]"); + if (a.length!=2) { + throw new Exception("Invalid format (main args length must be 2)"); + } + + PotionEffectType type = PotionEffectType.getByName(a[0]); + if (type==null) { + throw new Exception("Invalid PotionEffectType "+a[0]); + } + + potionEffects.put(type, a[1]); + } catch (Exception e) { + Bukkit.getLogger().warning("Invalid potion effect type name definition {"+s+"} Error: "+e.getMessage()); + } + } + CustomPotionsName.setPotionEffects(potionEffects); + } + ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits"); if (limitCfg != null) { getLogger().info("Limit cfg found..."); @@ -474,7 +522,18 @@ public class QuickShop extends JavaPlugin { return this.shopManager; } - public Map getCustomItemNames() { - return customItemNames; + public Map> getCustomItemsNameMap() { + return customItemsName; + } + + public CustomItemName getCustomItemNames(ItemStack is) { + List list = customItemsName.get(is.getType()); + for (CustomItemName cin : list) { + if (cin.matches(is)) { + return cin; + } + } + + return null; } } \ No newline at end of file diff --git a/src/main/java/org/maxgamer/quickshop/Util/CustomItemName.java b/src/main/java/org/maxgamer/quickshop/Util/CustomItemName.java index bcf4d2a08..8f73d785f 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/CustomItemName.java +++ b/src/main/java/org/maxgamer/quickshop/Util/CustomItemName.java @@ -21,6 +21,9 @@ public class CustomItemName { public String getFullName() { return fullName; } + public boolean matches(ItemStack otherItemStack) { + return otherItemStack.getType()==this.itemStack.getType() && otherItemStack.getDurability()==this.itemStack.getDurability(); + } @Override public int hashCode() { @@ -51,7 +54,7 @@ public class CustomItemName { } else if (!fullName.equals(other.fullName)) { return false; } - if (itemStack == null) { + if (itemStack.getItemMeta() == null) { if (other.itemStack != null) { return false; } @@ -72,4 +75,6 @@ public class CustomItemName { public String toString() { return "CustomItemName [itemStack=" + itemStack + ", signName=" + signName + ", fullName=" + fullName + "]"; } + + } diff --git a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java index 06ba330d8..afd288e62 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java +++ b/src/main/java/org/maxgamer/quickshop/Util/MsgUtil.java @@ -12,6 +12,7 @@ import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.enchantments.Enchantment; @@ -19,7 +20,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.maxgamer.quickshop.QuickShop; -import org.maxgamer.quickshop.Shop.ContainerShop; import org.maxgamer.quickshop.Shop.Shop; @SuppressWarnings("deprecation") @@ -146,6 +146,9 @@ public class MsgUtil { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.shop-information")); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName()==null ? (shop.isUnlimited() ? "AdminShop" : "Unknown") : Bukkit.getOfflinePlayer(shop.getOwner()).getName())); p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item", shop.getDataName())); + if (items.getType()==Material.POTION) { + p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.effects", CustomPotionsName.getEffects(items))); + } if (Util.isTool(items.getType())) { p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.damage-percent-remaining", Util.getToolPercentage(items))); } diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index ecf7777b5..793f8fc2b 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -363,19 +363,21 @@ public class Util { * Fetches an ItemStack's name - For example, converting INK_SAC:11 to * Dandellion Yellow, or WOOL:14 to Red Wool * - * @param i + * @param itemStack * The itemstack to fetch the name of * @return The human readable item name. */ - public static String getName(ItemStack i) { - ItemStack is = i.clone(); - is.setAmount(1); - CustomItemName customItemName = QuickShop.instance.getCustomItemNames().get(is); + public static String getName(ItemStack itemStack) { + if (itemStack.getType()==Material.POTION) { + return CustomPotionsName.getFullName(itemStack); + } + + CustomItemName customItemName = QuickShop.instance.getCustomItemNames(itemStack); if (customItemName!=null) { return customItemName.getFullName(); } - String vanillaName = getDataName(i.getType(), i.getDurability()); + String vanillaName = getDataName(itemStack.getType(), itemStack.getDurability()); return prettifyText(vanillaName); } @@ -403,9 +405,13 @@ public class Util { // Let's make very long names shorter for our sign public static String getNameForSign(ItemStack itemStack) { + if (itemStack.getType()==Material.POTION) { + return CustomPotionsName.getSignName(itemStack); + } + ItemStack is = itemStack.clone(); is.setAmount(1); - CustomItemName customItemName = QuickShop.instance.getCustomItemNames().get(is); + CustomItemName customItemName = QuickShop.instance.getCustomItemNames(is); if (customItemName!=null) { return customItemName.getSignName(); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b5c9e8df1..da6d73627 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -94,9 +94,24 @@ blacklist: price-restriction: - Bedrock;100;200 -#Custom names for items. Format: ;; -# PotionType: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionType.html -custom-names: +#Custom name for items. Format: ;; +custom-items-name: - NETHER_STALK;Nether Wart;Nether Wart -- POTION*INVISIBILITY;Invis.Potion;Invisibility Potion +custom-potions-name: + format-full: "%splash %type %tier" + format-sign: "%splash%type%tier" + splash-sign: "Splash" + splash-full: "Splash" + + #Custom names for potions types. Format: ;; + # PotionType: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionType.html + types: + - INVISIBILITY;Invis.Potion;Potion of Invisibility + + #Custom names for potion effect type. Format: ; + # PotionEffect: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html + effects: + - FIRE_RESISTANCE;Fire resistance + - INVISIBILITY;Invisibility + \ No newline at end of file diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 14ca64de6..1eb82539c 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -60,6 +60,7 @@ menu: damage-percent-remaining: "&e{0}% &aRemaining." this-shop-is-buying: "&aThis shop is &dBUYING&a items." this-shop-is-selling: "&aThis shop is &bSELLING&a items." + effects: "&aEffects: &e{0}" bypassing-lock: "&cBypassing a QuickShop lock!"