Java Code Examples for org.bukkit.entity.Player#teleport()
The following examples show how to use
org.bukkit.entity.Player#teleport() .
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: Portal.java From CardinalPGM with MIT License | 6 votes |
private void tryTeleport(Player player, Location from, RegionModule destination, int dir) { if ((filter == null || filter.evaluate(player).equals(FilterState.ALLOW)) || ObserverModule.testObserver(player)) { if (destination != null) { from.setPosition(destination.getRandomPoint().getLocation().position()); } else { from.setX(x.getLeft() ? from.getX() + (x.getRight() * dir) : x.getRight()); from.setY(y.getLeft() ? from.getY() + (y.getRight() * dir) : y.getRight()); from.setZ(z.getLeft() ? from.getZ() + (z.getRight() * dir) : z.getRight()); } from.setYaw((float) (yaw.getLeft() ? from.getYaw() + (yaw.getRight() * dir) : yaw.getRight())); from.setPitch((float) (pitch.getLeft() ? from.getPitch() + (pitch.getRight() * dir) : pitch.getRight())); player.setFallDistance(0); player.teleport(from); if (sound) player.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 0.2F, 1); } }
Example 2
Source File: Trade.java From TradePlus with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onMove(PlayerMoveEvent event) { if (cancelled || event.getTo() == null) return; Player player = event.getPlayer(); if (player.equals(player1) || player.equals(player2)) { if (event.getFrom().distanceSquared(event.getTo()) < 0.01) return; if (System.currentTimeMillis() < startTime + 1000) { return; } if (player.equals(player1)) { player.teleport(location1); } else { player.teleport(location2); } } }
Example 3
Source File: EntityListenerOnePointNine.java From WorldGuardExtraFlagsPlugin with MIT License | 6 votes |
@EventHandler(ignoreCancelled = true) public void onEntityToggleGlideEvent(EntityToggleGlideEvent event) { Entity entity = event.getEntity(); if (entity instanceof Player) { Player player = (Player)entity; ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()); ForcedState state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.GLIDE); if (state != ForcedState.ALLOW) { event.setCancelled(true); player.setGliding(state == ForcedState.FORCE); if (state == ForcedState.DENY) { player.teleport(player.getLocation()); } } } }
Example 4
Source File: LobbyMap.java From AnnihilationPro with MIT License | 6 votes |
public void sendToSpawn(final Player player) { if(spawn != null && player != null) { player.getInventory().clear(); player.getInventory().setArmorContents(null); player.setHealth(player.getMaxHealth()); player.setFoodLevel(20); player.setGameMode(GameVars.getDefaultGamemode()); player.getInventory().addItem(CustomItem.KITMAP.toItemStack()); player.getInventory().addItem(CustomItem.TEAMMAP.toItemStack()); if(GameVars.getVoting()) player.getInventory().addItem(CustomItem.VOTEMAP.toItemStack()); player.teleport(getSpawn()); } }
Example 5
Source File: ControllablePlayerBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public SpawnResult spawn(Location location) { if (isSpawned()) { return SpawnResult.ALREADY_SPAWNED; } this.handle = GameRegistry.get(IEntitySpawnHandler.class).createPlayerHandle(this, location, this.name, UUID.nameUUIDFromBytes(("EntityAPI-NPC:" + this.getId() + this.name).getBytes())); Player entity = this.getBukkitEntity(); if (entity != null) { entity.setMetadata(EntityAPI.ENTITY_METADATA_MARKER, new FixedMetadataValue(EntityAPI.getCore(), true)); // Perhaps make this a key somewhere entity.teleport(location); entity.setSleepingIgnored(true); } // Send the Packet handle.updateSpawn(); //return spawned; return isSpawned() ? SpawnResult.SUCCESS : SpawnResult.FAILED; }
Example 6
Source File: SpectateListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onSpectatorDamaged(EntityDamageEvent e) { if (e.getEntity() instanceof Player) { final Player player = (Player) e.getEntity(); final GameMap gameMap = MatchManager.get().getSpectatorMap(player); if (gameMap == null) { return; } e.setCancelled(true); if (e.getCause() == DamageCause.VOID) { World world = gameMap.getCurrentWorld(); Location spectateSpawn = new Location(world, 0, 0, 0); player.teleport(spectateSpawn); } } }
Example 7
Source File: Game.java From Survival-Games with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public void removeSpectator(Player p) { ArrayList < Player > players = new ArrayList < Player > (); players.addAll(activePlayers); players.addAll(inactivePlayers); if(p.isOnline()){ for (Player pl: Bukkit.getOnlinePlayers()) { pl.showPlayer(p); } } restoreInv(p); p.setAllowFlight(false); p.setFlying(false); p.setFallDistance(0); p.setHealth(p.getMaxHealth()); p.setFoodLevel(20); p.setSaturation(20); p.teleport(SettingsManager.getInstance().getLobbySpawn()); // Bukkit.getServer().broadcastPrefixType("Removing Spec "+p.getName()+" "+spectators.size()+" left"); spectators.remove(p.getName()); // Bukkit.getServer().broadcastPrefixType("Removed"); nextspec.remove(p); }
Example 8
Source File: Resident.java From civcraft with GNU General Public License v2.0 | 5 votes |
public void teleportHome(Player player) { if (this.hasTown()) { TownHall townhall = this.getTown().getTownHall(); if (townhall != null) { BlockCoord coord = townhall.getRandomRevivePoint(); player.teleport(coord.getLocation()); } } else { World world = Bukkit.getWorld("world"); player.teleport(world.getSpawnLocation()); } }
Example 9
Source File: GameMap.java From AnnihilationPro with MIT License | 5 votes |
public void unLoadMap() { //World tpworld = Bukkit.getWorlds().size() > 0 ? Bukkit.getWorlds().get(0) : null; World tpworld = Game.LobbyMap != null ? Game.LobbyMap.getWorld() : null; if(tpworld == null) tpworld = Bukkit.getWorlds().size() > 0 ? Bukkit.getWorlds().get(0) : null; for(Player p : Bukkit.getOnlinePlayers()) { if(p.getWorld().getName().equals(this.getWorldName())) { if(tpworld != null) p.teleport(tpworld.getSpawnLocation()); else p.kickPlayer("Unloading the world and we dont want you to get trapped or glitched!"); } } this.unregisterListeners(); boolean b = Bukkit.unloadWorld(super.getWorldName(), false); Bukkit.getLogger().info("[Annihilation] "+super.getNiceWorldName()+" was unloaded successfully: "+b); // try // { // FileUtils.deleteDirectory(this.mapDirec); // FileUtils.copyDirectory(this.tempDirec, this.mapDirec); // FileUtils.deleteDirectory(this.tempDirec); // } // catch (IOException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } }
Example 10
Source File: SecureModeTask.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public void run() { for (Player player : Bukkit.getOnlinePlayers()) { GlobalPlayer globalPlayer = plugin.getPlayerCache().get(player); if (globalPlayer == null) { globalPlayer = new DGlobalPlayer(plugin, player); } if (!(globalPlayer instanceof InstancePlayer)) { if (player.getWorld().getName().startsWith("DXL_Game_") | player.getWorld().getName().startsWith("DXL_Edit_") && !DPermission.hasPermission(player, DPermission.INSECURE)) { player.teleport(Bukkit.getWorlds().get(0).getSpawnLocation()); } } } }
Example 11
Source File: AxcTeleport.java From FunnyGuilds with Apache License 2.0 | 5 votes |
@Override public void execute(CommandSender sender, String[] args) { MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration(); Player player = (Player) sender; if (! FunnyGuilds.getInstance().getPluginConfiguration().regionsEnabled) { player.sendMessage(messages.regionsDisabled); return; } if (args.length < 1) { player.sendMessage(messages.generalNoTagGiven); return; } Guild guild = GuildUtils.getByTag(args[0]); if (guild == null) { player.sendMessage(messages.generalNoGuildFound); return; } Region region = guild.getRegion(); if (region == null || region.getCenter() == null) { player.sendMessage(messages.adminNoRegionFound); return; } player.sendMessage(messages.baseTeleport); player.teleport(region.getCenter()); }
Example 12
Source File: Swapper.java From AnnihilationPro with MIT License | 5 votes |
@Override protected boolean performSpecialAction(Player player, AnniPlayer p) { if(p.getTeam() != null) { Player e = instance.getPlayerInSightTest(player, 15); if(e != null) { AnniPlayer pl = AnniPlayer.getPlayer(e.getUniqueId()); if(pl != null && !pl.getTeam().equals(p.getTeam())) { Location playerLoc = player.getLocation().clone(); Location entityLoc = e.getLocation().clone(); Vector playerLook = playerLoc.getDirection(); Vector playerVec = playerLoc.toVector(); Vector entityVec = entityLoc.toVector(); Vector toVec = playerVec.subtract(entityVec).normalize(); e.teleport(playerLoc.setDirection(playerLook.normalize())); player.teleport(entityLoc.setDirection(toVec)); e.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 3, 1)); return true; } } } return false; }
Example 13
Source File: DEditPlayer.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
public DEditPlayer(DungeonsXL plugin, Player player, EditWorld world) { super(plugin, player, world); editWorld = world; // Set gamemode a few ticks later to avoid incompatibilities with plugins that force a gamemode new BukkitRunnable() { @Override public void run() { player.setGameMode(GameMode.CREATIVE); } }.runTaskLater(plugin, 10L); clearPlayerData(); Location teleport = world.getLobbyLocation(); if (teleport == null) { player.teleport(world.getWorld().getSpawnLocation()); } else { player.teleport(teleport); } // Permission bridge if (plugin.getPermissionProvider() != null) { for (String permission : plugin.getMainConfig().getEditPermissions()) { plugin.getPermissionProvider().playerAddTransient(world.getName(), player, permission); } } }
Example 14
Source File: WildTpBack.java From WildernessTp with MIT License | 4 votes |
public void back(Player p) { Location loc = locations.get(p.getUniqueId()); p.teleport(loc); locations.remove(p.getUniqueId()); }
Example 15
Source File: CommandHelper.java From GriefDefender with MIT License | 4 votes |
public static Consumer<CommandSender> createTeleportConsumer(CommandSender src, Location location, Claim claim, boolean isClaimSpawn) { return teleport -> { if (!(src instanceof Player)) { // ignore return; } final Player player = (Player) src; // check if world is loaded if (Bukkit.getWorld(location.getWorld().getUID()) == null) { TextAdapter.sendComponent(player, MessageCache.getInstance().TELEPORT_NO_SAFE_LOCATION); return; } final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getPlayerData(player.getWorld(), player.getUniqueId()); final int teleportDelay = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), player, Options.PLAYER_TELEPORT_DELAY, claim); if (isClaimSpawn) { if (teleportDelay > 0) { playerData.teleportDelay = teleportDelay + 1; playerData.teleportSourceLocation = player.getLocation(); playerData.teleportLocation = location; return; } player.teleport(location, TeleportCause.PLUGIN); return; } final double safeY = location.getWorld().getHighestBlockYAt(location); location.setY(safeY); int currentY = location.getBlockY(); while (currentY > 0 && currentY < location.getWorld().getMaxHeight()) { if (PlayerUtil.getInstance().isSafeLocation(location)) { if (teleportDelay > 0) { playerData.teleportDelay = teleportDelay + 1; playerData.teleportLocation = location; return; } player.teleport(location, TeleportCause.PLUGIN); return; } if (location.getWorld().getEnvironment() == Environment.NETHER) { currentY--; } else { currentY++; } location.setY(currentY); } TextAdapter.sendComponent(player, MessageCache.getInstance().TELEPORT_NO_SAFE_LOCATION); }; }
Example 16
Source File: Island.java From IridiumSkyblock with GNU General Public License v2.0 | 4 votes |
public void teleportHome(Player p) { if (getHome() == null) home = getCenter(); if (User.getUser(p).teleportingHome) { return; } if (isBanned(User.getUser(p)) && !members.contains(p.getUniqueId().toString())) { p.sendMessage(Utils.color(IridiumSkyblock.getMessages().bannedFromIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); return; } if (getSchematic() == null) { User u = User.getUser(p); if (u.getIsland().equals(this)) { if (IridiumSkyblock.getSchematics().schematics.size() == 1) { for (Schematics.FakeSchematic schematic : IridiumSkyblock.getSchematics().schematics) { setSchematic(schematic.name); setNetherschematic(schematic.netherisland); } } else { p.openInventory(getSchematicSelectGUI().getInventory()); } } return; } p.setFallDistance(0); if (members.contains(p.getUniqueId().toString())) { p.sendMessage(Utils.color(IridiumSkyblock.getMessages().teleportingHome.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } if (Utils.isSafe(getHome(), this)) { p.teleport(getHome()); sendBorder(p); } else { Location loc = Utils.getNewHome(this, this.home); if (loc != null) { this.home = loc; p.teleport(this.home); sendBorder(p); } else { User.getUser(p).teleportingHome = true; pasteSchematic(p, false); } } }
Example 17
Source File: Civilization.java From civcraft with GNU General Public License v2.0 | 4 votes |
public void repositionPlayers(String reason) { if (this.getDiplomacyManager().isAtWar() == false) { return; } for (Town t : this.getTowns()) { TownHall townhall = t.getTownHall(); if (townhall == null) { CivLog.error("Town hall was null for "+t.getName()+" when trying to reposition players."); continue; } // if (!townhall.isComplete()) { // CivLog.error("Town hall was not completed before war time. Unable to reposition players."); // continue; // } for (Resident resident : t.getResidents()) { //if (townhall.isActive()) { BlockCoord revive = townhall.getRandomRevivePoint(); try { Player player = CivGlobal.getPlayer(resident); ChunkCoord coord = new ChunkCoord(player.getLocation()); CultureChunk cc = CivGlobal.getCultureChunk(coord); if (cc != null && cc.getCiv() != this && cc.getCiv().getDiplomacyManager().atWarWith(this)) { CivMessage.send(player, CivColor.Purple+reason); player.teleport(revive.getLocation()); } } catch (CivException e) { // player not online.... } // } else { // // use player spawn point instead. // Player player; // try { // player = CivGlobal.getPlayer(resident); // // if (player.getBedSpawnLocation() != null) { // player.teleport(player.getBedSpawnLocation()); // CivMessage.send(player, CivColor.Purple+reason); // } else { // player.gets // } // } catch (CivException e) { // // player not online // } // } } } }
Example 18
Source File: GrapplingHookListener.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
private void handleGrapplingHook(Arrow arrow) { if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player) { Player p = (Player) arrow.getShooter(); GrapplingHookEntity hook = activeHooks.get(p.getUniqueId()); if (hook != null) { Location target = arrow.getLocation(); hook.drop(target); Vector velocity = new Vector(0.0, 0.2, 0.0); if (p.getLocation().distance(target) < 3.0) { if (target.getY() <= p.getLocation().getY()) { velocity = target.toVector().subtract(p.getLocation().toVector()); } } else { Location l = p.getLocation(); l.setY(l.getY() + 0.5); p.teleport(l); double g = -0.08; double d = target.distance(l); double t = d; double vX = (1.0 + 0.08 * t) * (target.getX() - l.getX()) / t; double vY = (1.0 + 0.04 * t) * (target.getY() - l.getY()) / t - 0.5D * g * t; double vZ = (1.0 + 0.08 * t) * (target.getZ() - l.getZ()) / t; velocity = p.getVelocity(); velocity.setX(vX); velocity.setY(vY); velocity.setZ(vZ); } p.setVelocity(velocity); hook.remove(); Slimefun.runSync(() -> activeHooks.remove(p.getUniqueId()), 20L); } } }
Example 19
Source File: CommandHandler.java From NyaaUtils with MIT License | 4 votes |
@SubCommand(value = "tpall", permission = "nu.tpall") public void tpall(CommandSender sender, Arguments args) { Player p = asPlayer(sender); int r = args.nextInt(); Block center = p.getLocation().getBlock(); int minX = center.getX() - r; int minZ = center.getZ() - r; int maxX = center.getX() + r; int maxZ = center.getZ() + r; int maxY = center.getY() + 1; List<Location> locations = new ArrayList<>(); int playerCount = Bukkit.getOnlinePlayers().size() - 1; for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { for (int i = 0; i <= 16; i++) { Block b = p.getWorld().getBlockAt(x, maxY - i, z); if (b.getType().isSolid()) { Block b2 = b.getRelative(BlockFace.UP, 1); Block b3 = b.getRelative(BlockFace.UP, 2); if ((b2.isEmpty() || b2.isPassable()) && (b3.isEmpty() || b3.isPassable()) && !b2.isLiquid() && !b3.isLiquid()) { Location loc = b.getBoundingBox().getCenter().toLocation(b.getWorld()); loc.setY(b.getBoundingBox().getMaxY()); locations.add(loc.clone()); break; } } } } } if (locations.size() < playerCount) { msg(sender, "user.tpall.error"); return; } Collections.shuffle(locations); int success = 0; for (Player player : Bukkit.getOnlinePlayers()) { if (!player.isDead() && player.getUniqueId() != p.getUniqueId()) { if (player.getWorld() == p.getWorld() && player.getLocation().distance(p.getLocation()) + 3 <= r) { continue; } Location old = player.getLocation().clone(); if (player.teleport(locations.get(success))) { success++; plugin.ess.getUser(player).setLastLocation(old); } } } msg(sender, "user.tpall.success", success); }
Example 20
Source File: PlayerStateHolder.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
public void apply(Player player, boolean teleport) { PlayerInventory playerInv = player.getInventory(); boolean is1_9 = MinecraftVersion.getImplementationVersion().compareTo(MinecraftVersion.V1_9) >= 0; boolean isSimpleSize = playerInv.getContents().length <= SIMPLE_INVENTORY_SIZE; ItemStack[] inventoryContents = new ItemStack[is1_9 && !isSimpleSize ? playerInv.getSize() : SIMPLE_INVENTORY_SIZE]; System.arraycopy(inventory, 0, inventoryContents, 0, inventoryContents.length); if (!is1_9 || isSimpleSize) { ItemStack[] armorContents = new ItemStack[ARMOR_INVENTORY_SIZE]; System.arraycopy(inventory, inventory.length - ARMOR_INVENTORY_SIZE, armorContents, 0, armorContents.length); playerInv.setArmorContents(armorContents); } playerInv.setContents(inventoryContents); player.setItemOnCursor(null); Map<Integer, ItemStack> exceeded = playerInv.addItem(onCursor); for (ItemStack stack : exceeded.values()) { if (stack.getType() == Material.AIR) { continue; } player.getWorld().dropItem(player.getLocation(), stack); } player.updateInventory(); player.setMaxHealth(maxHealth); player.setHealth(health); player.setFoodLevel(foodLevel); player.setLevel(level); player.setExp(experience); player.setAllowFlight(allowFlight); player.setFlying(isFlying); /* Remove current potion effects */ Collection<PotionEffect> effects = player.getActivePotionEffects(); for (PotionEffect effect : effects) { player.removePotionEffect(effect.getType()); } player.addPotionEffects(activeEffects); player.setExhaustion(exhaustion); player.setSaturation(saturation); player.setFallDistance(fallDistance); player.setFireTicks(fireTicks); if (scoreboard != player.getScoreboard()) { Scoreboard showBoard = scoreboard; if (scoreboard == null) { showBoard = Bukkit.getScoreboardManager().getMainScoreboard(); } player.setScoreboard(showBoard); } if (teleport) { player.teleport(location); } Location compassTarget = this.compassTarget; if (compassTarget == null) { compassTarget = player.getWorld().getSpawnLocation(); } player.setCompassTarget(compassTarget); for (WeakReference<Player> ref : cantSee) { Player cantSeePlayer = ref.get(); if (cantSeePlayer == null) { // Player object has been garbage-collected continue; } if (!cantSeePlayer.isOnline()) { continue; } player.hidePlayer(cantSeePlayer); } player.setGameMode(gamemode); }