Get Material with custom MaterialData form Config

Discussion in 'Spigot Plugin Development' started by WAS, Apr 13, 2017.

  1. WAS

    WAS

    How does one go about creating a Material with a applied MaterialData from a config.

    For example you have something set like
    Code (YAML):
    material: STONE
    data
    : 1
    Where the data would be 1 for Granite. Not sure if really this sick or just being dumb.

    Or even simpler config
    Code (YAML):
    item: 1:1
     
  2. NathanWolf

    Supporter

    There isn't a non-deprecated way to do it, but the deprecated methods work just fine. You can use either of the MaterialData constructors that take a byte, for instance:

    https://hub.spigotmc.org/javadocs/b...ial/MaterialData.html#MaterialData(int, byte)

    For items, you'd set the "damage" field in the ItemStack constructor:

    https://hub.spigotmc.org/javadocs/b...ml#ItemStack(org.bukkit.Material, int, short)

    For Blocks, there is a deprecated setData method:

    https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/block/Block.html#setData(byte)
     
  3. WAS

    WAS

    Hmm. So in general there is a whole lot of bs custom checking to make sure you have the right material to get or set the right data?

    Again what is with all the deprecation without standardization. If nothing exists to replace it, you don't mark it deprecated. x.x