getMaterial depreciated for gui

Discussion in 'Spigot Plugin Development' started by Spoonle, Sep 10, 2019.

  1. I'm trying to make a gui (following a tutorial on it) but they use getMaterial but its depreciated.

    Code (Java):

    item = new ItemStack(Material.getMaterial(materialId), amount);
     
    That is what I have, whats the updated way to do this? I've never made a GUI before and want to learn!
     
  2. Which version of Spigot are you using?
     
  3. You could use the Material enum straight away. https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html
    For example: Material.ACACIA_SLAB

    Also I believe the reason why that function is deprecated is because we now use name id's, not numerical id's. So you'd use something like Material.getMaterial("stone_axe"). Do note that if you're hard-coding it, and you don't plan on adding user customization, using the enumeration is far better practice.
     
  4. I'm using 1.8 Spigot.

    So how could I change the line of code? Do I just remove the line or should I just remove the getMaterial? Or should I make the decision of what I want item to be and change getMaterial to an actual block
     
  5. does the code work?
    If yes then ignore the depreciation.
    The deprecation is there is there to warn of future removal of that method.
    Since you're making a plugin for a dinosaur server version you will be fine.
    Most time deprecated methods work fine, its just a warning.
     
    • Like Like x 1
  6. You were right, it works just fine even though its depreciated. Thanks for your help :)
     
    • Friendly Friendly x 1
  7. Actually, it is already removed in versions >1.13, as there are no numeric IDs anymore
     
  8. I'm using spigot 1.8 for my server and as the resource for my plugins :)