Solved Player Death Event

Discussion in 'Plugin Development' started by MyNameIsHariK, Nov 4, 2013.

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

    MyNameIsHariK

    Hey Guys!

    This code isnt working. What I am trying to do is when player 'playerll' kills 'alive' they are added to the 'dead' group and teleport to location 'loc2'. Iff you can help me out it would be great.

    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent event){
    3.  
    4. String arena = "arena" + String.valueOf(1);
    5.  
    6. Vector vec2 = this.getCustomConfig().getConfigurationSection(arena).getVector("dead");
    7. final Location loc2 = new Location(Bukkit.getWorld((String) this.getCustomConfig().getConfigurationSection(arena).get("world")), vec2.getX(), vec2.getY(), vec2.getZ());
    8.  
    9. Player player = event.getEntity();
    10. Player killer = player.getKiller();
    11.  
    12.  
    13. if(playerll.contains(killer.getName())) {
    14. if(alive.contains(player.getName())) {
    15. dead.add(player.getName());
    16. player.teleport(loc2);
    17. }
    18. }
    19. }
    20. }


    Thanks for your time,
    Hari
     
  2. Offline

    EcMiner

    You need to teleport them on PlayerRespawnEvent
     
  3. Offline

    MyNameIsHariK

    EcMiner is this correct?

    Code:java
    1. public void onPlayerRespawn (PlayerRespawnEvent e) {
    2.  
    3. Player player = e.getPlayer();
    4.  
    5. String arena = "arena" + String.valueOf(1);
    6.  
    7. Vector vec2 = this.getCustomConfig().getConfigurationSection(arena).getVector("dead");
    8. final Location loc2 = new Location(Bukkit.getWorld((String) this.getCustomConfig().getConfigurationSection(arena).get("world")), vec2.getX(), vec2.getY(), vec2.getZ());
    9.  
    10. player.teleport(loc2);
    11.  
    12. }


    Then add onPlayerRespawn(); to the code I have in the first place? It says I need to put onPlayerRespawn(null);
    Is that correct?
     
  4. Offline

    Poppi

    For the playerrespawnevent use event.setRespawnLocation() and not teleport :)
     
  5. Offline

    MyNameIsHariK

    Is that a different event? or..
     
  6. Offline

    Poppi

    no, instead of teleporting in the playerRespawnEvent (as you showed us earlier in this thread) you use the inbuilt method setRespawnLocation
     
  7. Offline

    MyNameIsHariK

    I am really confused right now? Anyone else help please

    Poppi Can you doe it out? Im so confused

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

    Poppi

    Code:java
    1. @EventHandler
    2. public void onRespawn(PlayerRespawnEvent e){
    3. if(dead.contains(e.getPlayer().getName())){
    4. final Location loc2 = new Location(Bukkit.getWorld((String) this.getCustomConfig().getConfigurationSection(arena).get("world")), vec2.getX(), vec2.getY(), vec2.getZ());
    5. event.setRespawnLocation(loc2);
    6. }
    7. }
     
  9. Offline

    CraftBang

    MyNameIsHariK
    What Poppi ment is that you need to set the RESPAWN location.
    Because you can't teleport someone if he dies you know, he would just be respawned at the default respawn location.
    So you do instead of e.teleport(lo2)
    e.setRespawnLocation(loc2) like what Poppi showed you.
     
  10. Offline

    MyNameIsHariK

  11. Offline

    CraftBang

    MyNameIsHariK no problem :)
    If your problem is fixed you can make it Solved by right top, Thread settings > something like edit or something> make it solved :)
     
Thread Status:
Not open for further replies.

Share This Page