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

The following examples show how to use org.bukkit.event.player.PlayerTeleportEvent#getTo() . 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: 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 2
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 3
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 4
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 5
Source File: PlayerTeleportListener.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
    try {
        final Location toLocation = event.getTo();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        final Island island = islandManager.getIslandViaLocation(toLocation);
        if (island == null) return;

        final Player player = event.getPlayer();
        final User user = User.getUser(player);

        if (user.islandID == island.getId()) return;

        if ((island.isVisit() && !island.isBanned(user)) || user.bypassing) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(IridiumSkyblock.getInstance(), () -> island.sendBorder(player), 1);
            if (user.islandID != island.getId()) {
                player.sendMessage(Utils.color(IridiumSkyblock.getMessages().visitingIsland.replace("%player%", User.getUser(island.getOwner()).name).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                for (String pl : island.getMembers()) {
                    Player p = Bukkit.getPlayer(User.getUser(pl).name);
                    if (p != null) {
                        p.sendMessage(Utils.color(IridiumSkyblock.getMessages().visitedYourIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                    }
                }
            }
        } else {
            event.setCancelled(true);
            player.sendMessage(Utils.color(IridiumSkyblock.getMessages().playersIslandIsPrivate.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 6
Source File: TickRate.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onTeleport(PlayerTeleportEvent e) {
    Location loc = e.getTo();
    if(!loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4)) {
        lastBigTeleportTime.put(e.getPlayer().getUniqueId(), hawk.getHawkPlayer(e.getPlayer()).getCurrentTick());
    }
}
 
Example 7
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 8
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 9
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 10
Source File: ShopUpdateListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {
    Location from = e.getFrom();
    Location to = e.getTo();
    final Player p = e.getPlayer();

    // Wait till the chunk should have loaded on the client
    if (!from.getWorld().getName().equals(to.getWorld().getName())
            || from.getChunk().getX() != to.getChunk().getX()
            || from.getChunk().getZ() != to.getChunk().getZ()) {
        new BukkitRunnable() {
            @Override
            public void run() {
                plugin.getUpdater().queue(() -> {
                    if (p.isOnline()) {
                        for (Shop shop : plugin.getShopUtils().getShops()) {
                            if (shop.hasItem()) {
                                shop.getItem().hidePlayer(p);
                            }
                            if (shop.hasHologram()) {
                                shop.getHologram().hidePlayer(p);
                            }
                        }
                        plugin.getShopUtils().resetPlayerLocation(p);
                    }
                });
                plugin.getUpdater().updateShops(p);
            }
        }.runTaskLater(plugin, 15L);
    }
}
 
Example 11
Source File: CraftPlayer.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
    Preconditions.checkArgument(location != null, "location");
    Preconditions.checkArgument(location.getWorld() != null, "location.world");
    location.checkFinite();
    EntityPlayerMP entity = getHandle();

    if (getHealth() == 0 || entity.isDead || entity instanceof FakePlayer) {
        return false;
    }

    if (entity.connection == null) {
        return false;
    }

    if (entity.isBeingRidden()) {
        return false;
    }

    // From = Players current Location
    Location from = this.getLocation();
    // To = Players new Location if Teleport is Successful
    Location to = location;
    // Create & Call the Teleport Event.
    PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause);
    server.getPluginManager().callEvent(event);

    // Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
    if (event.isCancelled()) {
        return false;
    }

    // If this player is riding another entity, we must dismount before teleporting.
    entity.dismountRidingEntity();

    // Update the From Location
    from = event.getFrom();
    // Grab the new To Location dependent on whether the event was cancelled.
    to = event.getTo();
    // Grab the To and From World Handles.
    WorldServer fromWorld = ((CraftWorld) from.getWorld()).getHandle();
    WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle();

    // Close any foreign inventory
    if (getHandle().openContainer != getHandle().inventoryContainer) {
        getHandle().closeScreen();
    }

    // Check if the fromWorld and toWorld are the same.
    if (fromWorld == toWorld) {
        entity.connection.teleport(to);
    } else {
        server.getHandle().moveToWorld(entity, toWorld.dimension, true, to, true);
    }
    return true;
}
 
Example 12
Source File: CraftPlayer.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) {
    net.minecraft.entity.player.EntityPlayerMP entity = getHandle();

    if (getHealth() == 0 || entity.isDead || entity instanceof net.minecraftforge.common.util.FakePlayer) {
        return false;
    }

    if (entity.playerNetServerHandler == null || entity.playerNetServerHandler.isDisconnected()) {
        return false;
    }

    // Spigot Start
    // if (entity.vehicle != null || entity.passenger != null) {
    // return false;
    // }
    // Spigot End

    // From = Players current Location
    Location from = this.getLocation();
    // To = Players new Location if Teleport is Successful
    Location to = location;
    // Create & Call the Teleport Event.
    PlayerTeleportEvent event = new PlayerTeleportEvent(this, from, to, cause);
    server.getPluginManager().callEvent(event);

    // Return False to inform the Plugin that the Teleport was unsuccessful/cancelled.
    if (event.isCancelled()) {
        return false;
    }
    
    // Spigot Start
    eject();
    leaveVehicle();
    // Spigot End

    // Update the From Location
    from = event.getFrom();
    // Grab the new To Location dependent on whether the event was cancelled.
    to = event.getTo();
    // Grab the To and From World Handles.
    net.minecraft.world.WorldServer fromWorld = ((CraftWorld) from.getWorld()).getHandle();
    net.minecraft.world.WorldServer toWorld = ((CraftWorld) to.getWorld()).getHandle();
    // Close any foreign inventory
    if (getHandle().openContainer != getHandle().inventoryContainer) {
        getHandle().closeScreen();
    }

    // Check if the fromWorld and toWorld are the same.
    if (fromWorld == toWorld) {
        entity.playerNetServerHandler.teleport(to);
    } else {
    	//Thermos....transfer them correctly?!
        this.getHandle().mountEntity(null);
    	thermos.thermite.ThermiteTeleportationHandler.transferPlayerToDimension(this.getHandle(), toWorld.dimension, this.getHandle().mcServer.getConfigurationManager(), to.getWorld().getEnvironment()); 
    	 //this.getHandle().playerNetServerHandler.teleport(to);
    	 this.getHandle().playerNetServerHandler.teleport(to);
    	 //this.getHandle().playerNetServerHandler.setPlayerLocation(to.getX(), to.getY(), to.getZ(), this.getHandle().rotationYaw, this.getHandle().rotationPitch);
    	//server.getHandle().respawnPlayer(entity, toWorld.dimension, false, to, false); // Cauldron
    }
    return true;
}