Drop Event Not Working!

Discussion in 'Plugin Development' started by footy, Apr 16, 2014.

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

    footy

    Code:
    @EventHandler
          public static void OnPlayerDrop(PlayerDropItemEvent Event)
          {
            Player player = Event.getPlayer();
            int item = player.getItemInHand().getTypeId();
     
            if ((item == 54) && (player.getGameMode() == GameMode.SURVIVAL))
            {
              Event.setCancelled(true);
              player.sendMessage(ChatColor.BLUE + "[CreaivePolice]" + ChatColor.BLACK + " - " + ChatColor.WHITE + "Dropping This Item is Denied");
              Event.setCancelled(true);
            }
          }
    Why is this not working ?
    Suspose to detect player in survival and if the player is holding item 54 and tries to drop the item than the player is denied dropping that item?
     
  2. Offline

    Konkz

    if (item == Material.CHEST && player.getGameMode() == GameMode.SURVIVAL) {
    //
    }

    Don't use getTypeId() - no point if you can use material.
    Also don't cancel the event twice... why? :p

    PHP:
    @EventHandler
    public void onPlayerDrop(PlayerDropItemEvent e) {
    Player p e.getPlayer();
     
    if (
    p.getItemInHand.getType() == Material.CHEST && p.getGameMode() == GameMode.SURVIVAL) {
      
    e.setCancelled();
      
    p.sendMessage("You can't drop this item!");
    }
    }
    This should work. :)
     
    Krotass likes this.
  3. Offline

    footy

    Well im only using the Item Id 54 which is chest as a test function, i wnt to be able to use the ID function.
     
  4. Offline

    Konkz


    Why do you want to use ID's? They are deprecated as far as I believe because Minecraft is removing them.
     
  5. Offline

    DrEinsteinium

    Code:
    @EventHandler
    public void onPlayerDrop(PlayerDropItemEvent e) {
    Player p = e.getPlayer();
     
    if (p.getItemInHand.getType().equals(Material.CHEST) && p.getGameMode().equals(GameMode.SURVIVAL))
    {
      e.setCancelled();
      p.sendMessage("You can't drop this item!");
    }
    }
    Change all of your == to .equals().
     
  6. Offline

    footy

    Nvm lol Works now =-)

    Been working hours and forgot one little ) in if
     
Thread Status:
Not open for further replies.

Share This Page