Solved Using Item ID for Material.<Item>

Discussion in 'Plugin Development' started by NewDevOnTheBlock, May 13, 2015.

Thread Status:
Not open for further replies.
  1. Hello,

    Would I be able to allow someone in a configuration file set some code like Material.<Item_Name> to something like Material.100, instead of Material.RED_MUSHROOM_BLOCK.

    I suppose I could say "Enter a String here: " and have the server manager type in "RED_MUSHROOM_BLOCK", but most people are familiar with the Item ID's.

    If someone doesn't understand my question, I'm trying to allow someone to use an Item ID in a configuration file, to then use that number to create an item using an ItemStack.
     
  2. @DJSkepter Well that was easy enough... I should have noticed that. Thanks for the help! And it doesn't matter that it is deprecated? I know my other deprecated stuff still works, but just curious.
     
  3. @NewDevOnTheBlock Couple of things: You're better off using matchMaterial() as that will work both if they enter an ID, or if they enter a name (cc: @DJSkepter). Secondly, it's deprecated because it relies on magic numbers, so you shouldn't be using it. Magic numbers are where the numbers don't match up to what they represent in a logical way - i.e. there's no reason that item 102 should represent... whatever it does. There's no way to know what it is, other than to know it. Whereas it's fairly logical to assume that a grass block is represented by "GRASS". Despite your insistence that most people are more familiar with IDs, I think that most people would be more likely to know the name than the ID ;)
     
    DJSkepter likes this.
  4. @AdamQpzm So you're suggesting I don't use item ID's? If I use Material.matchMaterial( String ), then I will have someone use common block/item names instead of a specific ID?

    Example:
    1. Currently I would have Material.GRASS
    2. In the original post I ask if I could make it Material.getMaterial(2)
    3. You're suggesting I use Material.matchMaterial("GRASS")

    If I use your method, how can I tell whoever uses this plugin the correct name to enter in order to get the correct item without any errors. Item ID's just seem more reliable, since there is no chance to mistake what you're entering. Not saying I'm against your idea, because it looks like your suggestion is more up-to-date. Just curious how it works.

    **Edit**
    @AdamQpzm would I tell people to go to a website like this one, and use the name after 'minecraft:' in all capitals?
     
  5. I don't agree with this, I've accidentally entered the wrong ID before - both because I thought I knew the ID but didn't, and because I made a mistake when entering it. It's pretty easy to enter 1 instead of 2, but it's pretty hard to accidentally enter stone instead of grass.

    Actually my suggestion works both way - Material.matchMaterial("2") and Material.matchMaterial("grass") would both result in Material.GRASS. So the user can choose whether they want to use IDs or names :)

    Personally I've always just linked them to the Javadocs page for the Material enum, because you can know for sure that it matches up to what Bukkit is expecting.
     
    NewDevOnTheBlock likes this.
Thread Status:
Not open for further replies.

Share This Page