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

The following examples show how to use org.bukkit.event.player.PlayerTeleportEvent#getFrom() . 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: 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 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: 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 4
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 5
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 6
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 7
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;
}