Solved Detect water bottle

Discussion in 'Spigot Plugin Development' started by JustCedric, Jun 3, 2016.

  1. Hi guys,

    How can I detect if a player consumes a water bottle or a potion?

    If I just use Material.POTION It'll both work but I want it to only execute when someone drinks a water bottle and not a potion like an invisibility potion.
  3. Doesn't work.. It still executes when I drink a invisibility potion.
    Code (Text):
    if (e.getItem().getType() == Material.POTION && e.getItem().getDurability() == 0) {
  4. getDurability() returns the durability of the ItemStack i am saying the Item Data Damage
  5. and how would I get that?
  6. I now use this
    Code (Text):
    ItemStack water = new ItemStack(Material.POTION, e.getItem().getAmount(), (short) 0);
    if (e.getItem().getItemMeta() == water) {
    But it still doesn't work.
    • Friendly Friendly x 1
  7. Try the 2nd constuctor that I gave, still, i think it's better for you to use .equal() in this case
  8. Code (Text):
    ItemStack water = new ItemStack(Material.POTION, e.getItem().getAmount(), (short) 0);
    if (e.getItem().getItemMeta().equals(water)) {
    That's my code rn and it doesn't work.. And what do you mean? Can you maybe give an example.
  9. Should be getItem() only? I am using my ipad so haven't test it yet :p
  10. Nop doesn't work
  11. Hmm, then i can't help you at least in this stage, since i have no IDE to test, sorry.
  12. Those are exactly the same thing.

    Assuming you are using a recent version of minecraft, there are NBT tags you can check. There is also the entire org.bukkit.potion package for managing potions and potion effects.
    • Winner Winner x 1
  13. Oh year **** i forgot that, *drops mic*.
    Edit: Also, Now i am totally confused between an item damage and durability
  14. It easy
    Code (Text):

    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;

    public class PlayerInteractEvent implements Listener {
        public void onPlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent e){
            Player player = e.getPlayer();
            if(player.getItemInHand().getType().equals(Material.POTION) && player.getItemInHand().getData().getData() == 0){
                player.sendMessage("┬žbYou can't use this item !");
    • Agree Agree x 1
  15. Those are exactly the same thing.

    Items have a value for the ID, a value for the data tag (variant), which is also the damage level on tools/armor, and an optional NBTTagCompound that holds more complex data.

    Stuff like skull UUIDs, sign text, commandblock text, ect goes into the NBT tag.

    Variants are being moved to entirely new blocks with 1.10, i am fairly sure, ie; white_wool will be a different block ID than pink_wool.
    • Winner Winner x 1
  16. Ok thanks, you deserve 2 medals
  17. How would I get that? Can you maybe give me an example?