Java Code Examples for org.bukkit.event.player.PlayerTeleportEvent#setTo()

The following examples show how to use org.bukkit.event.player.PlayerTeleportEvent#setTo() . 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: 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 2
Source File: SafeBoat.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onTeleport(final PlayerTeleportEvent e) {
    //
    // plugin.getLogger().info("DEBUG: Teleport called");
    Player player = e.getPlayer();
    if (SafeBoat.ignoreList.contains(player.getUniqueId())) {
        return;
    }
    // If the player is not teleporting due to boat exit, return
    if (!exitedBoat.containsKey(player.getUniqueId())) {
        return;
    }
    // Entity boat = exitedBoat.get(player.getUniqueId());
    // Reset the flag
    exitedBoat.remove(player.getUniqueId());
    // Okay, so a player is getting out of a boat in the the right world.
    // Now...
    //plugin.getLogger().info("DEBUG: Player just exited a boat");
    // Find a safe place for the player to land
    int radius = 0;
    while (radius++ < 2) {
        for (int x = player.getLocation().getBlockX() - radius; x < player.getLocation().getBlockX() + radius; x++) {
            for (int z = player.getLocation().getBlockZ() - radius; z < player.getLocation().getBlockZ() + radius; z++) {
                for (int y = player.getLocation().getBlockY(); y < player.getLocation().getBlockY() + 2; y++) {
                    // The safe location to tp to is actually +0.5 to x and
                    // z.
                    final Location loc = new Location(player.getWorld(), (double) (x + 0.5), (double) y, (double) (z + 0.5));
                    // plugin.getLogger().info("XYZ is " + x + " " + y + " "
                    // + z);
                    // Make sure the location is safe
                    if (GridManager.isSafeLocation(loc)) {
                        // plugin.getLogger().info("Safe!");
                        e.setTo(loc);
                        return;
                    }
                }
            }
        }
    }
}
 
Example 3
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());
        }
    }
}