Delete item inhand

Discussion in 'Plugin Development' started by XxPowerKingxX, Jan 15, 2012.

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

    XxPowerKingxX

    I want to delete the bow, so they cant use it :S

    The code is inside AntiBow class, yes its defined in playerlistener playerinteract
    Code:
    public AntiBow (PlayerInteractEvent e, ClosedDoors plugin) {
        Player p = e.getPlayer();
        Action a = e.getAction();
        ItemStack iih = p.getItemInHand();
        if ((iih.getType() == Material.BOW))
            if (a == Action.RIGHT_CLICK_AIR) {
            p.getInventory().removeItem(p.getInventory().getItemInHand());
        p.sendMessage(ChatColor.GOLD + "[Alarm] "+ ChatColor.RED + "Pil og bue er ikke lov!"); }
        } }
     
  2. Offline

    wwsean08

    well thats not in the player interact, that's in the constructor. You want to put that code in the PlayerInteract method (this code won't work anyways because of the way that you extend PlayerListener). Here is roughly what you need:

    Code:java
    1.  
    2. public AntiBow(CosedDoors plugin){
    3. }
    4.  
    5. @Override
    6. public void onPlayerInteract(PlayerInteractEvent event){
    7. Player p = e.getPlayer();
    8. Action a = e.getAction();
    9. ItemStack iih = p.getItemInHand();
    10. if ((iih.getType() == Material.BOW))
    11. if (a == Action.RIGHT_CLICK_AIR) {
    12. p.getInventory().removeItem(p.getInventory().getItemInHand());
    13. p.sendMessage(ChatColor.GOLD + "[Alarm] "+ ChatColor.RED + "Pil og bue er ikke lov!");
    14. }
    15. }
     
  3. Offline

    XxPowerKingxX

    That gives me error on this tho, already tried that

    " e cannot be resolved
    Code:
               Player p = e.getPlayer();
               Action a = e.getAction();
     
  4. Offline

    wwsean08

    that's because i called it event in the method signature, if you change it back to e it will fix it (that's just a personal preference)
     
  5. Offline

    XxPowerKingxX

    oh lol didnt see that one

    Well, i get the message now tho. Any idea for how to delete the bow?

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

    wwsean08

    it should be getting rid of the bow if they right click air, but if it doesn't work you could try the clear method in player inventory, using the getHeldItemSlot
     
  7. Offline

    XxPowerKingxX

    Is there any other way, like event.setCancelled(true);
     
Thread Status:
Not open for further replies.

Share This Page