Having players respawn with items.

Discussion in 'Plugin Development' started by AstramG, Feb 18, 2013.

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

    AstramG

    I was wondering how I would get players to respawn with items after death. In my plugin, translated to English it basically checks for when you die and when you are, it immediately warps you somewhere and tries to spawn you the items. However, since its the death event it will not spawn the items since it thinks you're dead. I tried to use the PlayerRespawnEvent but it didn't work because the respawn GUI doesn't show when you die (It immediately teleports you). Therefor, I'm in need of a way to give the players the items.
     
  2. Offline

    repsor

    It's really not clear what you'retrying to say. Just use the respawn event.
     
  3. Offline

    AstramG

    repsor
    I can't because that is triggered when the player presses the button that says respawn.
    When the player dies he automatically gets teleported, no window comes up.
     
  4. Offline

    repsor

    ofcourse it does, unless the playerdeathevent is cancelled :)
     
  5. Offline

    AstramG

    It doesn't I've tried.
     
  6. Offline

    lcpvp

    Try
    Code:java
    1.  
    2. public void onPlayerRespawn(PlayerRespawnEvent event){
    3. Player p = event.getPlayer();
    4. p.sendMessage(ChatColor.BLUE + "You Respawned");
    5. }
     
  7. Offline

    AstramG

    It doesn't happen because the event is never ran :p, when you die it immediately teleports you with no screen coming up
     
  8. Offline

    lcpvp

    WHen you tp them give them stuff that you want to.
     
  9. Offline

    CubixCoders

    So let is this what is happening?
    A player dies, the death event is cancelled and he is teleported making it a automatic-respawn? If so, just add the items in the PlayerDeathEvent you were checking for.
     
  10. Offline

    AstramG

    Tried that, didn't work because the death event triggered it

    That doesnt work because it thinks that players are dead

    I found a solution, what I did was checked on movement to see if they're inv was empty and if it was, it'll give the items. :)

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

    CubixCoders

    Please just show your listener class then.

    AstramG that's good and all but it won't work very effectively, what happens when the player throws all his items to get more? You would have to restrict that and pickingup items

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

    AstramG

    I've did that already, forgot to mention. I restricted dropping.
     
  13. Offline

    CubixCoders

    Okay then good job :p
     
  14. Offline

    AstramG

    I'm just worried about the lag it'd cause if I kept doing this in this sort of situation in the future. And by the way, while I have you. Do you know how to remove drops? (These are drops form the PlayerDeathEvent trying to make the player not drop anything) What I have so far is:
    Code:
    for (ItemStack drops : event.getDrops()) {
        drops.setType(Material.AIR);
    }
    However, it doesn't work :p
     
  15. Offline

    lcpvp

    Check out my posts please on the dev page, the item menu one and timer one.


    Glad you solved

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerDeath(PlayerDeathEvent event){
    4. event.getDrops().clear();
    5. }
    6.  


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

    AstramG

    lol, I can't believe I didn't realize that :p. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page