Java Code Examples for org.bukkit.event.player.PlayerTeleportEvent#isCancelled()
The following examples show how to use
org.bukkit.event.player.PlayerTeleportEvent#isCancelled() .
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 |
@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: PlayerEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@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 3
Source File: PlayerTeleportListener.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@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 4
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerTeleport(PlayerTeleportEvent event) { if (event.isCancelled()) return; Player player = event.getPlayer(); Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> { sendDurabilityBossBar(player, player.getInventory().getItemInMainHand(), EquipmentSlot.HAND); sendDurabilityBossBar(player, player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND); }); }
Example 5
Source File: SentinelEventHandler.java From Sentinel with MIT License | 5 votes |
/** * 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 6
Source File: CraftPlayer.java From Kettle with GNU General Public License v3.0 | 4 votes |
@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 |
@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; }