Solved Teleport a player right before they die?

Discussion in 'Plugin Development' started by ChrisStarr32, Apr 22, 2014.

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

    ChrisStarr32

    I was wondering if it was possible to make it so right before a player dies it teleports them?
    I was thinking something like a repeating task looking at health and when it gets to zero, set there health to full and teleport them? Is this possible? If so how could I do it?

    Thanks!
    Chris
     
  2. I have no idea if this will work but just try
    Code:
    public void onDeath(PlayerDeathEvent e) {
      e.setCanceled(true);
      e.getPlayer().teleport(new Location(.....));
    }
     
  3. Offline

    ChrisStarr32

    WD_MUFFINFLUFFER
    The Method setCanceled(boolean) is undefined for the type PlayerDeathEvent()
     
  4. Try casting it to be able to be canceled
    Code:java
    1. ((Cancellable) e).setCancelled(true);
     
  5. Offline

    ChrisStarr32

    WD_MUFFINFLUFFER
    Nope.

    Thanks to @Domi381 on a different thread HERE
    I was able to get:
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void PlayerDamageReceive(EntityDamageByEntityEvent e) {
    3. if(e.getEntity() instanceof Player) {
    4. Player damaged = (Player) e.getEntity();
    5.  
    6. if(e.getDamager() instanceof Player) {
    7. Player damager = (Player) e.getDamager();
    8.  
    9. if(damaged.getWorld().getName() == plugin.worldname) {
    10. if((damaged.getHealth()-e.getDamage()) <= 0) {
    11.  
    12. //Killed
    13. e.setCancelled(true);
    14. damaged.teleport(plugin.spawn); // <---- plugin.spawn is the spawn-location that is defined in the main class.
    15. damaged.setHealth(20);
    16. }
    17. }
    18. }
    19. }
    20. }



    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page