Hello! I have a shop plugin that was made custom for my server a while back and have been updating it through the years. However, with 1.13 I have absolutely no idea how to update it to support the new item names instead of the old numeric item ID's. Here is the code from the ItemStrings class: https://pastebin.com/vrL9p7xX I still have a pretty limited understanding of creating/editing Spigot plugins so any help or guidance is much appreciated. Thank you!
For the user friendly name you can maybe use this (didnt test but should work) Code (Java): public static String getPlayerFriendlyName(Material material) { String namespacedKey = material.getKey().getKey(); return namespacedKey.substring(0, 1).toUpperCase() + namespacedKey.substring(1).replace("_", " "); } Btw who the f*** wrote this code? Just make a set and check for contains. Code (Java): public static boolean needsDurability(Material mat) { return !(mat != Material.WOOD_SWORD && mat != Material.STONE_SWORD && mat != Material.IRON_SWORD && mat != Material.GOLD_SWORD && mat != Material.DIAMOND_SWORD && mat != Material.WOOD_PICKAXE && mat != Material.STONE_PICKAXE && mat != Material.IRON_PICKAXE && mat != Material.GOLD_PICKAXE && mat != Material.DIAMOND_PICKAXE && mat != Material.WOOD_AXE && mat != Material.STONE_AXE && mat != Material.IRON_AXE && mat != Material.GOLD_AXE && mat != Material.DIAMOND_AXE && mat != Material.WOOD_SPADE && mat != Material.STONE_SPADE && mat != Material.IRON_SPADE && mat != Material.GOLD_SPADE && mat != Material.DIAMOND_SPADE && mat != Material.WOOD_HOE && mat != Material.STONE_HOE && mat != Material.IRON_HOE && mat != Material.GOLD_HOE && mat != Material.DIAMOND_HOE && mat != Material.LEATHER_HELMET && mat != Material.CHAINMAIL_HELMET && mat != Material.IRON_HELMET && mat != Material.GOLD_HELMET && mat != Material.DIAMOND_HELMET && mat != Material.LEATHER_CHESTPLATE && mat != Material.CHAINMAIL_CHESTPLATE && mat != Material.IRON_CHESTPLATE && mat != Material.GOLD_CHESTPLATE && mat != Material.DIAMOND_CHESTPLATE && mat != Material.LEATHER_LEGGINGS && mat != Material.CHAINMAIL_LEGGINGS && mat != Material.IRON_LEGGINGS && mat != Material.GOLD_LEGGINGS && mat != Material.DIAMOND_LEGGINGS && mat != Material.LEATHER_BOOTS && mat != Material.CHAINMAIL_BOOTS && mat != Material.IRON_BOOTS && mat != Material.GOLD_BOOTS && mat != Material.DIAMOND_BOOTS); } PS or even better: Code (Java): public static boolean hasDurability(Material material) { return material.getMaxDurability() > 1; } This whole class should be 50 lines not 500 lines...
For your needsDurability method, just check if the ItemStack's ItemMeta is instanceof Damageable. https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/Damageable.html
@7smile7 Thanks for the reply. I am still unsure of what you mean though. Are you saying to replace all of the ItemStrings in the getUserFriendlyNames with just: Code (Text): public static String getPlayerFriendlyName(Material material) { String namespacedKey = material.getKey().getKey(); return namespacedKey.substring(0, 1).toUpperCase() + namespacedKey.substring(1).replace("_", " "); } ?
Still not having any luck with it. This is my Class right now: https://hastebin.com/umigegiles.java EDIT: This is the error I am getting Code (Text): Caused by: java.lang.Error: Unresolved compilation problem: The method getKey() is undefined for the type Material
I built against Spigot 1.13 and am getting this error on a server running 1.13: https://pastebin.com/BpNvTEqE
Thank you all so much for all of the help. Just one last thing, How do I update the enchantments to support 1.13? This is currently what I have and it is not working: Spoiler Code (Text): public static String getUserFriendlyName(Enchantment e) { /* 319 */ if (e.getName().equalsIgnoreCase("arrow_damage")) return "Power"; /* 320 */ if (e.getName().equalsIgnoreCase("ARROW_FIRE")) return "Flame"; /* 321 */ if (e.getName().equalsIgnoreCase("ARROW_INFINITE")) return "Infinity"; /* 322 */ if (e.getName().equalsIgnoreCase("ARROW_KNOCKBACK")) return "Punch"; /* 323 */ if (e.getName().equalsIgnoreCase("DAMAGE_ALL")) return "Sharpness"; /* 324 */ if (e.getName().equalsIgnoreCase("DAMAGE_ARTHROPODS")) return "Bane of arthropods"; /* 325 */ if (e.getName().equalsIgnoreCase("DAMAGE_UNDEAD")) return "Smite"; /* 326 */ if (e.getName().equalsIgnoreCase("DIG_SPEED")) return "Efficiency"; /* 327 */ if (e.getName().equalsIgnoreCase("DURABILITY")) return "Unbreaking"; /* 328 */ if (e.getName().equalsIgnoreCase("LOOT_BONUS_BLOCKS")) return "Fortune"; /* 329 */ if (e.getName().equalsIgnoreCase("LOOT_BONUS_MOBS")) return "Looting"; /* 330 */ if (e.getName().equalsIgnoreCase("LUCK")) return "Luck of the sea"; /* 331 */ if (e.getName().equalsIgnoreCase("OXYGEN")) return "Respiration"; /* 332 */ if (e.getName().equalsIgnoreCase("PROTECTION_ENVIRONMENTAL")) return "Protection"; /* 333 */ if (e.getName().equalsIgnoreCase("PROTECTION_EXPLOSIONS")) return "Blast protection"; /* 334 */ if (e.getName().equalsIgnoreCase("PROTECTION_FALL")) return "Feather falling"; /* 335 */ if (e.getName().equalsIgnoreCase("PROTECTION_FIRE")) return "Fire protection"; /* 336 */ if (e.getName().equalsIgnoreCase("PROTECTION_PROJECTILE")) return "Projectile protection"; /* 337 */ if (e.getName().equalsIgnoreCase("WATER_WORKER")) return "Aqua infinity"; /* */ /* 339 */ String name = e.getKey().replaceAll("_", " ").toLowerCase(); /* 340 */ name = String.valueOf(name.substring(0, 1).toUpperCase()) + name.substring(1); /* */ /* 342 */ return name;
Take a look at XSeries it contains a bunch of classea to support all types of thing across versions, including materials and enchantments
I thought you typod, looks like it's a resource, nice. I've been developing my own version of it for my projects, but it looks like their version includes everything.