Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PlayerDropItemEvent

Comments in 'Plugin Development' started by deot, Nov 1, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi,
    I wanted to disable drop item when player died :)
    So, I tried to disable PlayerDropItemEvent
    PHP:
    public function onDrop(PlayerDropItemEvent $e){
         
    $e->setCancelled(true);
    }
    But, this code will only disable drop item when player touch and hold the item and hotbar (I mean dropping item by hotbar) It wonr cancel the drop item event when player died...

    So, how can I achieve that? :)
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event){
        if(
    $event->getEntity() instanceof Player){
            
    $event->setDrops([]); //This will set the drops to nothing
        
    }
    }
    PlayerDropItemEvent is fired when a player drops an item from their hotbar, not the way you wanted to use it.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PlayerDeathEvent->getEntity() always return a Player. You can assert that.
    deot likes this.
  4. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    If it always returns a player your wasting some valuable. miniscule amounts of a second each time a player dies.

Share This Page

Advertisement