Solved PlayerDeathEvent

Discussion in 'Plugin Development' started by girardcome, Jun 19, 2019.

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

    girardcome

    Hi, I'm stuck on a problem with the PlayerDeathEvent event.

    What I want: When the player dies, he is respawn instantly and is teleported randomly in the map.

    What I did:

    PHP:
       for (PotionEffect e p.getActivePotionEffects()) {
                        
    p.addPotionEffect(new PotionEffect(e.getType(), 00), true);
                    }
                   
                    
    p.getInventory().setArmorContents(new ItemStack[p.getInventory().getArmorContents().length]);
                    
    p.setHealth(20);
                    
    p.setFoodLevel(20);

                   
                    
    Spawn spawn = new Spawn(plugin);
                    
    spawn.teleportRandomLocation(pp.getLocation(), plugin.getRandom(-400400),
                            
    plugin.getRandom(-400400));
    What I got: The problem is that all the items of the inventory of the dead player are not dropped at the exact place where he died, unfortunately his stuff is dropped at the place where he will be teleported. .
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    girardcome

  4. Offline

    KarimAKL

    @girardcome You are looping the player's inventory, not the contents.
    Use Player#getInventory()#getContents()
     
  5. Offline

    girardcome

    Thanks it worked!
     
Thread Status:
Not open for further replies.

Share This Page