Solved How to set a specific item for PlayerDropEvent?

Discussion in 'Plugin Development' started by TECGaming360, Apr 13, 2014.

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

    TECGaming360

    I want to set a specific item for a player drop event and i am having issues finding out on how to do this so i need help! Here is what i have so far.
    Code:java
    1. @EventHandler
    2. public void onDropItem(PlayerDropItemEvent e) {
    3. Player player = e.getPlayer();
    4. e.setCancelled(true);
    5.  
    6. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + "You can not Drop this Item!");
    7. }
    8. }


    I need to set lets say compass as the certain item.
     
  2. Offline

    Phyla

    Check if the item is in the players hand:
    if (p.getItemInHand().equals(Material.<the item you dont want dropped>) {
    e.setCancelled(true);
     
  3. Offline

    TECGaming360

    It is telling me it is supposed to be getItemDrop

    In stead of getItemInHand

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

    Anonymous350

    TECGaming360

    I'm pretty sure he forgot getInventory

    Code:java
    1. if(player.getInventory().getItemInHand().equals(Material.COMPASS)) {
     
  5. Offline

    TECGaming360

    it never enabled, Like the plugin works but the drop event drops the compass as well.
     
  6. Offline

    Compressions

    TECGaming360
    Code:
    if(e.getItemDrop().getItemStack().getType() == Material.COMPASS) {
    e.setCancelled(true);
    }
     
    TECGaming360 and TigerHix like this.
  7. Offline

    TECGaming360

    ThnakYou so much this was bothering me it was the if "e"!
    Code:java
    1. if(e.getItemDrop().getItemStack().getType() == Material.COMPASS)
     
Thread Status:
Not open for further replies.

Share This Page