Remove a water bottle from the inventory

Discussion in 'Plugin Development' started by MetalGearDaner, Nov 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MetalGearDaner

    I would like to know how to remove from the item 1 water bottle.

    Thanx!
     
  2. Offline

    _Filip

    What do you have so far?
     
  3. Offline

    mythbusterma

    MetalGearDaner

    Could you maybe provide some code? Or a clear explanation of what you're doing?
     
  4. Offline

    glasseater

    MetalGearDaner
    Code:java
    1. if (player.getItemInHand().getType() == Material.POTION
    2. player.getInventory().getItemInHand().setType(Material.AIR);

    That is how I do it. Not sure if that is what you meant though.
     
  5. Offline

    Dudemister1999

    Code:java
    1. public static void decrItemInHand(Player player, ItemStack item)
    2. {
    3. if(item != null)
    4. {
    5. int amount = item.getAmount() - 1;
    6.  
    7. if(amount == 0)
    8. {
    9. item.setType(Material.AIR);
    10. }
    11. else
    12. {
    13. item.setAmount(amount);
    14. }
    15. player.updateInventory();
    16. }
    17. }


    Note that I changed some of the code, it used to be for decreasing the amount of an item in a player's hand. :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. Offline

    MetalGearDaner

    This event generates a water bottle when cancelling the event. I would like to remove that bottle.

    Code:java
    1. public void onWaterFillTry(PlayerInteractEvent event) {
    2. Player p = event.getPlayer();
    3. ItemMeta meta = p.getItemInHand().getItemMeta();
    4. if (event.getClickedBlock() != null) {
    5. Material m = event.getClickedBlock().getType();
    6. if (m.equals(Material.WATER) || equals(Material.STATIONARY_WATER)) {
    7. if ((meta.getLore().get(0).endsWith("puntos") & meta.getDisplayName().equals("MegaBotella"))) {
    8. event.getPlayer().sendMessage("No puedes recoger agua con una botella de almacenamiento de experiencia.");
    9. event.setCancelled(true);
    10. //HERE TODO REMOVE WATER BOTTLE.
    11. }
    12. }
    13. }
    14. }


    Something like that, but specifying that the potion is a Water Potion and it doesn't necessarily have to be in the player hand.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  7. Offline

    PreFiXAUT

    Then go throught the Inventory of the Player and check if it is a Water-potion. If so, decrease the amount.
     
Thread Status:
Not open for further replies.

Share This Page