Bukkit's setData(data)
and getData()
are deprecated. But there's no replacement.
Bukkit/Spigot JavaDoc says this about setData()
:
Deprecated. Magic value
Why is that?
You change the data tag for a block using the /blockdata command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /blockdata command was replaced by the /data command.
Use /setblock! The /setblock command in Minecraft allows the user to change a block at a specific coordinates in their current Minecraft world to the block specified. The usage and syntax of this command depends on which platform (Java or Bedrock) you are using it.
So far, the only way to do it is by using:
Block.setData(byte data);
So, you could do something like this:
myBlock.setData(2); // Set block data to 2
Although Block.setData()
is deprecated, it still works, and will continue to work (deprecated methods in Bukkit are rarely removed, especially those for which there is no alternative).
I wish I could give a better answer, but that's the only thing that you can do, as of now.
The reason it is deprecated is because Minecraft is moving away from item IDs, and switching to item names, to make it easier to expand in the future. Where you used to have to run /give player 19
, you are now supposed to run /give player minecraft:sponge
(although the ID still works). The same thing is going to happen to data values, instead of giving someone 35:14
, you now give them red wool
.
To get rid of the warning given by using a deprecated method, put @SuppressWarnings("deprecation")
above the deprecated method when you use it, or above the method in which it is used.
To set the type of the block, you could use:
Block.setType(Material type);
An example is:
myBlock.setType(Material.GOLD_BLOCK); // Set block to gold block
You could also use MaterialData
, but no one really knows how to use it (as far as I know). It's one of the things included in the Bukkit API, but no one knows why.
The source of WorldEdit and most other big plugins look messy because they use a lot of interfaces. To the developers, it seems very organized, but to someone reading it, it looks very messy, unless you can actually visualize the hierarchy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With