org.bukkit.event.player.PlayerTeleportEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerTeleportEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerTeleportListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void noPlayerInteractionsSameGroup() {
    // given
    Player player = mock(Player.class);

    World worldFrom = mock(World.class);
    given(worldFrom.getName()).willReturn("world");
    Location from = new Location(worldFrom, 1, 2, 3);
    World worldTo = mock(World.class);
    given(worldTo.getName()).willReturn("world_nether");
    Location to = new Location(worldTo, 4, 5, 6);

    Group group = TestHelper.mockGroup("world");
    given(groupManager.getGroupFromWorld("world")).willReturn(group);
    given(groupManager.getGroupFromWorld("world_nether")).willReturn(group);

    PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);

    // when
    listener.onPlayerTeleport(event);

    // then
    verifyZeroInteractions(playerManager);
}
 
Example #2
Source File: PlayerMovementListener.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Modify the to location of the given event to prevent the movement and
 * move the player so they are standing on the center of the block at the
 * from location.
 */
private static void resetPosition(final PlayerMoveEvent event) {
    Location newLoc;
    double yValue = event.getFrom().getY();

    if(yValue <= 0 || event instanceof PlayerTeleportEvent) {
        newLoc = event.getFrom();
    } else {
        newLoc = BlockUtils.center(event.getFrom()).subtract(new Vector(0, 0.5, 0));
        if(newLoc.getBlock() != null) {
            switch(newLoc.getBlock().getType()) {
            case STEP:
            case WOOD_STEP:
                newLoc.add(new Vector(0, 0.5, 0));
                break;
            default: break;
            }
        }
    }

    newLoc.setPitch(event.getTo().getPitch());
    newLoc.setYaw(event.getTo().getYaw());
    event.setCancelled(false);
    event.setTo(newLoc);
}
 
Example #3
Source File: MovePattern.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void cancelAction(User user, PacketEvent packetEvent)
{
    final IWrapperPlayPosition positionWrapper = packetEvent::getPacket;

    final Vector moveTo = new Vector(positionWrapper.getX(),
                                     positionWrapper.getY(),
                                     positionWrapper.getZ());

    final Location knownPosition = user.getPlayer().getLocation();

    // Not many blocks moved to prevent exploits and world change problems.
    if (moveTo.distanceSquared(knownPosition.toVector()) < 4) {
        // Teleport back the next tick.
        Bukkit.getScheduler().runTask(AACAdditionPro.getInstance(), () -> user.getPlayer().teleport(knownPosition, PlayerTeleportEvent.TeleportCause.UNKNOWN));
    }
}
 
Example #4
Source File: SentinelTrait.java    From Sentinel with MIT License 6 votes vote down vote up
/**
 * Called whenever a player teleports, for use with NPC guarding logic.
 */
public void onPlayerTeleports(final PlayerTeleportEvent event) {
    if (event.getFrom().getWorld().equals(event.getTo().getWorld())) {
        npc.teleport(event.getTo(), PlayerTeleportEvent.TeleportCause.PLUGIN);
    }
    else { // World loading up can cause glitches.
        event.getFrom().getChunk().load();
        event.getTo().getChunk().load();
        Bukkit.getScheduler().runTaskLater(SentinelPlugin.instance, new Runnable() {
            @Override
            public void run() {
                if (!event.getPlayer().getWorld().equals(event.getTo().getWorld())) {
                    return;
                }
                event.getFrom().getChunk().load();
                event.getTo().getChunk().load();
                npc.spawn(event.getTo());
            }
        }, 1);
    }
}
 
Example #5
Source File: ListenerTeleport.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTeleport(PlayerTeleportEvent e) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    if(!config.getBoolean("teleportation.prevent-teleport")) return;

    Player player = e.getPlayer();
    ICombatManager manager = this.plugin.getCombatManager();
    if(!manager.isInCombat(player)) return;

    PlayerTeleportEvent.TeleportCause cause = e.getCause();
    if(isAllowed(cause)) {
        if(cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL && config.getBoolean("teleportation.restart-timer-for-ender-pearl")) {
            manager.tag(player, null, PlayerPreTagEvent.TagType.UNKNOWN, PlayerPreTagEvent.TagReason.UNKNOWN);
        }
        return;
    }

    e.setCancelled(true);
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.teleportation.block-" + (cause == PlayerTeleportEvent.TeleportCause.ENDER_PEARL ? "pearl" : "other"));
    this.plugin.sendMessage(player, message);
}
 
Example #6
Source File: PlayerEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
    if (event.getTo() != null || !plugin.getWorldManager().isSkyWorld(event.getTo().getWorld())) {
        return;
    }
    final Player player = event.getPlayer();
    boolean isAdmin = player.isOp() || player.hasPermission("usb.mod.bypassprotection");
    IslandInfo islandInfo = uSkyBlock.getInstance().getIslandInfo(WorldGuardHandler.getIslandNameAt(event.getTo()));
    if (!isAdmin && islandInfo != null && islandInfo.isBanned(player.getUniqueId())) {
        event.setCancelled(true);
        player.sendMessage(tr("\u00a74That player has forbidden you from teleporting to their island."));
    }
    if (!isAdmin && islandInfo != null && islandInfo.isLocked() && !islandInfo.getMembers().contains(player.getName()) && !islandInfo.isTrusted(player)) {
        event.setCancelled(true);
        player.sendMessage(tr("\u00a74That island is \u00a7clocked.\u00a7e No teleporting to the island."));
    }
    if (!event.isCancelled()) {
        final PlayerInfo playerInfo = plugin.getPlayerInfo(player);
        playerInfo.onTeleport(player);
    }
}
 
Example #7
Source File: NoEntryListener.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onTeleport(PlayerTeleportEvent e) {
    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = e.getPlayer();
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    Location toLocation = e.getTo();
    TagType tagType = (enemy instanceof Player ? TagType.PLAYER : TagType.MOB);

    NoEntryHandler handler = this.expansion.getNoEntryHandler();
    if(!handler.isSafeZone(player, toLocation, tagType)) return;

    e.setCancelled(true);
    this.expansion.sendNoEntryMessage(player, enemy);
}
 
Example #8
Source File: PetOwnerListener.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    final Player p = event.getPlayer();
    final IPet pi = EchoPet.getManager().getPet(p);
    Iterator<IPet> i = EchoPet.getManager().getPets().iterator();
    while (i.hasNext()) {
        IPet pet = i.next();
        if (pet.getEntityPet() instanceof IEntityPacketPet && ((IEntityPacketPet) pet.getEntityPet()).hasInititiated()) {
            if (GeometryUtil.getNearbyEntities(event.getTo(), 50).contains(pet)) {
                ((IEntityPacketPet) pet.getEntityPet()).updatePosition();
            }
        }
    }
    if (pi != null) {
        if (!WorldUtil.allowPets(event.getTo())) {
            Lang.sendTo(p, Lang.PETS_DISABLED_HERE.toString().replace("%world%", WordUtils.capitalizeFully(event.getTo().getWorld().getName())));
            EchoPet.getManager().saveFileData("autosave", pi);
            EchoPet.getSqlManager().saveToDatabase(pi, false);
            EchoPet.getManager().removePet(pi, false);
        }
    }
}
 
Example #9
Source File: PlayerTeleportListener.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (event.isCancelled()) {
        return;
    }

    Location from = event.getFrom();
    Location to = event.getTo();

    if (from.getWorld().equals(to.getWorld())) {
        return;
    }

    ConsoleLogger.debug("[EVENTS] Player '" + event.getPlayer().getName() + "' going from world '" + from + "' to world '" + to + "'");

    Group groupFrom = groupManager.getGroupFromWorld(from.getWorld().getName());
    Group groupTo = groupManager.getGroupFromWorld(to.getWorld().getName());

    if (groupFrom.equals(groupTo)) {
        return;
    }

    playerManager.addPlayer(event.getPlayer(), groupFrom);
    event.getPlayer().closeInventory();
}
 
Example #10
Source File: PlayerTeleportListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void noInteractionsSameWorld() {
    // given
    Player player = mock(Player.class);

    World worldFrom = mock(World.class);
    Location from = new Location(worldFrom, 1, 2, 3);
    Location to = new Location(worldFrom, 4, 5, 6);

    PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);

    // when
    listener.onPlayerTeleport(event);

    // then
    verifyZeroInteractions(groupManager);
    verifyZeroInteractions(playerManager);
}
 
Example #11
Source File: PlayerTeleportListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void shouldAddPlayer() {
    // given
    Player player = mock(Player.class);

    World worldFrom = mock(World.class);
    given(worldFrom.getName()).willReturn("world");
    Location from = new Location(worldFrom, 1, 2, 3);
    World worldTo = mock(World.class);
    given(worldTo.getName()).willReturn("world2");
    Location to = new Location(worldTo, 4, 5, 6);

    Group groupFrom = TestHelper.mockGroup("world");
    Group groupTo = TestHelper.mockGroup("world2");
    given(groupManager.getGroupFromWorld("world")).willReturn(groupFrom);
    given(groupManager.getGroupFromWorld("world2")).willReturn(groupTo);

    PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);

    // when
    listener.onPlayerTeleport(event);

    // then
    verify(playerManager).addPlayer(player, groupFrom);
}
 
Example #12
Source File: PlayerTeleportListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void noPlayerInteractionsSameGroup() {
    // given
    Player player = mock(Player.class);

    World worldFrom = mock(World.class);
    given(worldFrom.getName()).willReturn("world");
    Location from = new Location(worldFrom, 1, 2, 3);
    World worldTo = mock(World.class);
    given(worldTo.getName()).willReturn("world_nether");
    Location to = new Location(worldTo, 4, 5, 6);

    Group group = TestHelper.mockGroup("world");
    given(groupManager.getGroupFromWorld("world")).willReturn(group);
    given(groupManager.getGroupFromWorld("world_nether")).willReturn(group);

    PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);

    // when
    listener.onPlayerTeleport(event);

    // then
    verifyZeroInteractions(playerManager);
}
 
Example #13
Source File: DPlayerListener.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    if (isCitizensNPC(player)) {
        return;
    }
    GlobalPlayer dPlayer = dPlayers.get(player);

    World toWorld = event.getTo().getWorld();

    if (dPlayer instanceof InstancePlayer && ((InstancePlayer) dPlayer).getWorld() == toWorld) {
        return;
    }

    if (plugin.getInstanceWorld(toWorld) != null) {
        dPlayer.sendMessage(DMessage.ERROR_JOIN_GROUP.getMessage());
        dPlayer.sendMessage(ChatColor.GOLD + DMessage.CMD_ENTER_HELP.getMessage());
        event.setCancelled(true);
    }
}
 
Example #14
Source File: PlayerTeleportListener.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (event.isCancelled()) {
        return;
    }

    Location from = event.getFrom();
    Location to = event.getTo();

    if (from.getWorld().equals(to.getWorld())) {
        return;
    }

    ConsoleLogger.debug("[EVENTS] Player '" + event.getPlayer().getName() + "' going from world '" + from + "' to world '" + to + "'");

    Group groupFrom = groupManager.getGroupFromWorld(from.getWorld().getName());
    Group groupTo = groupManager.getGroupFromWorld(to.getWorld().getName());

    if (groupFrom.equals(groupTo)) {
        return;
    }

    playerManager.addPlayer(event.getPlayer(), groupFrom);
    event.getPlayer().closeInventory();
}
 
Example #15
Source File: PlayerTeleportListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void noInteractionsSameWorld() {
    // given
    Player player = mock(Player.class);

    World worldFrom = mock(World.class);
    Location from = new Location(worldFrom, 1, 2, 3);
    Location to = new Location(worldFrom, 4, 5, 6);

    PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to);

    // when
    listener.onPlayerTeleport(event);

    // then
    verifyZeroInteractions(groupManager);
    verifyZeroInteractions(playerManager);
}
 
Example #16
Source File: InternalMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Prevent teleporting outside the map
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
    if(event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN) {
        double fromY = event.getFrom().getY();
        double toY = event.getTo().getY();

        if((fromY >= 0.0D && fromY < 255.0D) && (toY < 0.0D || toY >= 255.0D)) {
            event.setCancelled(true);
        }
    }
}
 
Example #17
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {

    final Player p = e.getPlayer();
    Location lfrom = e.getFrom();
    Location lto = e.getTo();

    if (e.getCause().equals(PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT)) {
        final Region rfrom = RedProtect.get().rm.getTopRegion(lfrom);
        final Region rto = RedProtect.get().rm.getTopRegion(lto);

        if (rfrom != null && !rfrom.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
        }
        if (rto != null && !rto.canTeleport(p)) {
            RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
            e.setCancelled(true);
        }
    }

    if (p.getInventory().getChestplate() != null &&
            p.getInventory().getChestplate().getType().equals(Material.ELYTRA) &&
            !RedProtect.get().config.globalFlagsRoot().worlds.get(lto.getWorld().getName()).player_glide.allow_elytra) {
        RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantworld");
        e.setCancelled(true);
    }
}
 
Example #18
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleportEvent(PlayerTeleportEvent event) {
	if (event.getCause().equals(TeleportCause.COMMAND) ||
			event.getCause().equals(TeleportCause.PLUGIN)) {
		CivLog.info("[TELEPORT] "+event.getPlayer().getName()+" to:"+event.getTo().getBlockX()+","+event.getTo().getBlockY()+","+event.getTo().getBlockZ()+
				" from:"+event.getFrom().getBlockX()+","+event.getFrom().getBlockY()+","+event.getFrom().getBlockZ());
	}
}
 
Example #19
Source File: Listeners.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
    if (event.getCause() == PlayerTeleportEvent.TeleportCause.UNKNOWN) {
        return;
    }
    Player p = event.getPlayer();
    // The player will either quit, die, or close the inventory at some point
    if (plugin.getInVault().containsKey(p.getUniqueId().toString())) {
        return;
    }
    saveVault(p, p.getOpenInventory().getTopInventory());
}
 
Example #20
Source File: DeathListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true) @SuppressWarnings("unused")
public void onPlayerTeleport(PlayerTeleportEvent event) {
    Player player = event.getPlayer();
    Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());

    if (!ConfigManager.getInstance().isAllowTeleportInCombat()) {
        if (civilian.isInCombat()) {
            event.setCancelled(true);
            player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
                    "in-combat"));
            return;
        }
    }

    if (!ConfigManager.getInstance().isAllowTeleportingOutOfHostileTowns()) {
        Town town = TownManager.getInstance().getTownAt(event.getFrom());
        if (town != null && !town.getPeople().containsKey(player.getUniqueId())) {
            Region region = RegionManager.getInstance().getRegionAt(event.getTo());
            if (region == null || !region.getEffects().containsKey("bypass_hostile_port")) {
                event.setCancelled(true);
                player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player,
                        "no-tp-out-of-town"));
                return;
            }
        }
    }
}
 
Example #21
Source File: EvtRegionBorder.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
private static void register() {
	if (registered)
		return;
	Bukkit.getPluginManager().registerEvent(PlayerMoveEvent.class, new Listener() {}, SkriptConfig.defaultEventPriority.value(), ee, Skript.getInstance(), true);
	Bukkit.getPluginManager().registerEvent(PlayerTeleportEvent.class, new Listener() {}, SkriptConfig.defaultEventPriority.value(), ee, Skript.getInstance(), true);
	Bukkit.getPluginManager().registerEvent(PlayerPortalEvent.class, new Listener() {}, SkriptConfig.defaultEventPriority.value(), ee, Skript.getInstance(), true);
	registered = true;
}
 
Example #22
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleportEvent(PlayerTeleportEvent event)
{
	Player player = event.getPlayer();
	
	player.removeMetadata(WorldGuardUtils.PREVENT_TELEPORT_LOOP_META, WorldGuardExtraFlagsPlugin.getPlugin());
}
 
Example #23
Source File: SentinelEventHandler.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Called when a player teleports, to handle NPC guard updates.
 */
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleports(final PlayerTeleportEvent event) {
    if (event.isCancelled()) {
        return;
    }
    UUID uuid = event.getPlayer().getUniqueId();
    for (SentinelTrait sentinel : cleanCurrentList()) {
        if (sentinel.getGuarding() != null && sentinel.getGuarding().equals(uuid)) {
            sentinel.onPlayerTeleports(event);
        }
    }
}
 
Example #24
Source File: PlayerTeleportListenerTest.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void noInteractionsEventCancelled() {
    // given
    PlayerTeleportEvent event = mock(PlayerTeleportEvent.class);
    given(event.isCancelled()).willReturn(true);

    // when
    listener.onPlayerTeleport(event);

    // then
    verifyZeroInteractions(groupManager);
    verifyZeroInteractions(playerManager);
}
 
Example #25
Source File: Bar.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event)
{
    if(event.getTo() != null && event.getPlayer() != null)
    {
        handleTeleport(event.getPlayer(), event.getTo().clone());
    }
}
 
Example #26
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (testObserver(event.getPlayer())) {
        if (event.getTo().getY() <= -64) {
            TeamModule teamModule = Teams.getTeamById("observers").get();
            ModuleCollection<SpawnModule> modules = new ModuleCollection<>();
            for (SpawnModule spawnModule : match.getModules().getModules(SpawnModule.class)) {
                if (spawnModule.getTeam() == teamModule) modules.add(spawnModule);
            }
            event.setTo(modules.getRandom().getLocation());
        }
    }
}
 
Example #27
Source File: ListenerTeleport.java    From CombatLogX with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAllowed(PlayerTeleportEvent.TeleportCause cause) {
    FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml");
    List<String> allowedCauseList = config.getStringList("teleportation.allowed-cause-list");

    String causeName = cause.name();
    return allowedCauseList.contains(causeName);
}
 
Example #28
Source File: KitRegion.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerTeleportEvent event) {
    if (ObserverModule.testObserverOrDead(event.getPlayer())) return;
    if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector()) && filter.evaluate(event.getPlayer(), event.getTo(), event).equals(FilterState.ALLOW)) {
        kit.apply(event.getPlayer(), null);
    } else if (lend && region.contains(event.getFrom().toVector()) && !region.contains(event.getTo().toVector())) {
        kit.remove(event.getPlayer());
    }
}
 
Example #29
Source File: CFIPacketListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onTeleport(PlayerTeleportEvent event) {
    final Player player = event.getPlayer();
    VirtualWorld gen = getGenerator(player);
    if (gen != null) {
        Location from = event.getFrom();
        Location to = event.getTo();
        if (to.getWorld().equals(from.getWorld()) && to.distanceSquared(from) < 8) {
            event.setTo(player.getLocation());
            event.setCancelled(true);
            player.setVelocity(player.getVelocity());
        }
    }
}
 
Example #30
Source File: CraftLivingEntity.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
    if (getHealth() == 0) {
        return false;
    }

    return super.teleport(location, cause);
}