1.13.2 How do I update my plugin to support 1.13.x item names?

Discussion in 'Spigot Plugin Development' started by SavageBob, Jan 20, 2020.

  1. 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!
     
    #1 SavageBob, Jan 20, 2020
    Last edited: Jan 20, 2020
    • Creative Creative x 1
  2. 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...
     
    • Like Like x 1
  3. FrostedSnowman

    Resource Staff

  4. @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("_", " ");
        }
    ?
     
  5. Yes. The whole method can be replaced by just this.
     
    • Informative Informative x 1
  6. 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


     
     
    #6 SavageBob, Jan 22, 2020
    Last edited: Jan 22, 2020
  7. Then you are not building against 1.13+
     
  8. Wait do you want it to run from old versions up to newer ones or do you want only 1.13+ support?
     
  9. Only 1.13+ Support.
     
  10. Make sure to build against 1.13.
     
    • Useful Useful x 1
  11. You can use XMaterial to support 1.8 to 1.15.1
     
  12. What’s XMaterial?
     
  13. add 'api-version: 1.13' to your plugin.yml file.
     
    • Like Like x 1
  14. Ever heard of google?
     
  15. 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:

    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;

     
     
  16. Take a look at XSeries it contains a bunch of classea to support all types of thing across versions, including materials and enchantments
     
    • Like Like x 1
  17. 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.