Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by PabloX11, Mar 22, 2020.
Compare the type.
Compare ItemStack#getType() with the right Material.
I'm not understanding you, write it
If you want someone to write the code for you, you should take a look at the Service and Recruitment section.
I don't want anyone to write the code for me, I write it myself ...
The ItemStack has a method called getType. It returns an Material object representing the material. You can compare it with the equals-operator with another Material object.
He's saying to do this:
... event.getBlock().getType() == Material.AZURE_BLUET ...
getId() and getData() are deprecated because they use raw magic numbers that you'd have to look up. Luckily, you can just compare the Material object returned by getType() to see what it is, in this case 38:3 is an azure bluet.
I already tried those, but I would like to enter the id of the block, there are items that I want to add that do not leave me that way...
Material.AZURE_BLUET wouldn't exist in 1.8.8 they'd all be classified under either RED_ROSE or YELLOW_FLOWER, if you'd try to compare for example item.getType() of Stone Bricks to a Material of Cracked Stone Bricks it would return true because the type is indeed correct but it's ignoring it's data value of cracked stone bricks being like 98:2 (it's just checking that 98 == 98 basically ignoring any :number after it), this is how it works at least in 1.12.2 so I assume the same is said for a version lower.
to OP: There's no non-deprecated way to get the sub id / data value of an item/block, you'll just have to deal with that. I think you could compare itemStacks to get everything about the item you're comparing though (that won't work for blocks though) and get if everything excluding the amount is the same as the item you're comparing it too if you use like ItemStack#isSimilar(itemStack).
There was Bukkit's attempt at a wrapper for magic data values, MaterialData. It wasn't entirely complete but a lot of blocks and items were covered by this. For instance, the different types of wood. Though we now live in modern times and in versions that aren't almost 6 years old, we have Material constants for all blocks.
is that I need to put the id 31: 1, and if I put the TALLGRASS it tells me that there is no such block
well that's because like I said in 1.12.2 and lower (I think 1.13 is when it began to have their own block names for each and every sub id version of a block) they aren't called by their minecraft names so Material.TALL_GRASS wouldn't exist and what you would need to do is:
event.getBlock().getType() == Material.GRASS && event.getBlock().getData() == 1
at least I think #getData() is the proper one.
again to the same as before...
getData() will always be deprecated. It was deprecated because they're meaningless and arbitrary values that had no good alternative. Having constant numbers in your code to denote a state is seriously discouraged and is the reason it was deprecated. Unless you have an alternative with MaterialData, you will never get around that deprecation. Suppress it and move on or update to a modern version
If you use a 6 year old version, you obviously have to use deprecated methods. That is like using a 20-year-old car and asking why it is not the fastest or why it has a deprecated engine.
These methods were deprecated in the 1.8 API already anyways (was done way before this time as well) for the reasons I mentioned above. Magic values. This version just had an incomplete alternative.
you need to check if the item/block is null and is air...