Java Code Examples for cn.nukkit.Player#teleport()
The following examples show how to use
cn.nukkit.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: BackCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 0) { this.sendUsage(sender); return false; } Player player = (Player) sender; Location pos = api.getLastLocation(player); if (pos == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.back.notavalible")); return false; } player.teleport(pos); sender.sendMessage(Language.translate("commands.generic.teleporting")); return true; }
Example 2
Source File: TPHereCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 1) { this.sendUsage(sender); return false; } Player player = api.getServer().getPlayer(args[0]); if (player == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } player.teleport((Player) sender); player.sendMessage(Language.translate("commands.tphere.other", ((Player) sender).getDisplayName())); sender.sendMessage(Language.translate("commands.tphere.success", player.getDisplayName())); return true; }
Example 3
Source File: TopCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 0) { this.sendUsage(sender); return false; } Player player = (Player) sender; sender.sendMessage(Language.translate("commands.generic.teleporting")); player.teleport(api.getHighestStandablePositionAt(player)); return true; }
Example 4
Source File: JumpCommand.java From EssentialsNK with GNU General Public License v3.0 | 6 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length != 0) { this.sendUsage(sender); return false; } Player player = (Player) sender; Block block = player.getTargetBlock(120, EssentialsAPI.NON_SOLID_BLOCKS); if (block == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.jump.unreachable")); return false; } player.teleport(api.getStandablePositionAt(block)); return true; }
Example 5
Source File: Level.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public boolean unload(boolean force) { LevelUnloadEvent ev = new LevelUnloadEvent(this); if (this == this.server.getDefaultLevel() && !force) { ev.setCancelled(); } this.server.getPluginManager().callEvent(ev); if (!force && ev.isCancelled()) { return false; } this.server.getLogger().info(this.server.getLanguage().translateString("nukkit.level.unloading", TextFormat.GREEN + this.getName() + TextFormat.WHITE)); Level defaultLevel = this.server.getDefaultLevel(); for (Player player : new ArrayList<>(this.getPlayers().values())) { if (this == defaultLevel || defaultLevel == null) { player.close(player.getLeaveMessage(), "Forced default level unload"); } else { player.teleport(this.server.getDefaultLevel().getSafeSpawn()); } } if (this == defaultLevel) { this.server.setDefaultLevel(null); } this.close(); return true; }
Example 6
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean unload(boolean force) { LevelUnloadEvent ev = new LevelUnloadEvent(this); if (this == this.server.getDefaultLevel() && !force) { ev.setCancelled(); } this.server.getPluginManager().callEvent(ev); if (!force && ev.isCancelled()) { return false; } this.server.getLogger().info(this.server.getLanguage().translateString("nukkit.level.unloading", TextFormat.GREEN + this.getName() + TextFormat.WHITE)); Level defaultLevel = this.server.getDefaultLevel(); for (Player player : new ArrayList<>(this.getPlayers().values())) { if (this == defaultLevel || defaultLevel == null) { player.close(player.getLeaveMessage(), "Forced default level unload"); } else { player.teleport(this.server.getDefaultLevel().getSafeSpawn()); } } if (this == defaultLevel) { this.server.setDefaultLevel(null); } this.close(); return true; }
Example 7
Source File: TeleportNPC.java From FNPC-Nukkit with Do What The F*ck You Want To Public License | 5 votes |
@Override public void onTouch(Player player) { if(this.teleport.getOrDefault("ip",null)!=null && this.teleport.getOrDefault("port",null)!=null) { StrangePacket pk=new StrangePacket(); pk.address=Utils.cast(this.teleport.getOrDefault("ip","")); pk.port=Short.parseShort(Utils.cast(this.teleport.getOrDefault("port",0))); player.dataPacket(pk); } else if(this.teleport.getOrDefault("x",null)==null || this.teleport.getOrDefault("y",null)==null || this.teleport.getOrDefault("z",null)==null) { player.sendMessage("[System] "+TextFormat.RED+"该NPC未设置传送目标"); } else if(this.teleport.getOrDefault("level",null)!=null) { Level level=Main.getInstance().getServer().getLevelByName(Utils.cast(this.teleport.get("level"))); if(level==null) { player.sendMessage("[System] "+TextFormat.RED+"目标传送世界不存在"); } else { player.teleport(new Position(Utils.cast(this.teleport.getOrDefault("x",0)),Utils.cast(this.teleport.getOrDefault("y",0)),Utils.cast(this.teleport.getOrDefault("z",0)),level)); player.sendMessage("[System] "+TextFormat.GREEN+"传送成功"); } } else { player.teleport(new Vector3(Utils.cast(this.teleport.getOrDefault("x",0)),Utils.cast(this.teleport.getOrDefault("y",0)),Utils.cast(this.teleport.getOrDefault("z",0)))); player.sendMessage("[System] "+TextFormat.GREEN+"传送成功"); } }
Example 8
Source File: HomeCommand.java From EssentialsNK with GNU General Public License v3.0 | 5 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length > 1) { this.sendUsage(sender); return false; } Player player = (Player) sender; if (args.length == 0) { String[] list = api.getHomesList(player); if (list.length == 0) { sender.sendMessage(TextFormat.RED + Language.translate("commands.home.nohome")); return false; } sender.sendMessage(Language.translate("commands.home.list") + "\n" + String.join(", ", list)); return true; } Location home = api.getHome(player, args[0].toLowerCase()); if (home == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.home.notexists", args[0])); return false; } player.teleport(home); sender.sendMessage(Language.translate("commands.home.success", args[0])); return true; }
Example 9
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean unload(boolean force) { LevelUnloadEvent ev = new LevelUnloadEvent(this); if (this == this.server.getDefaultLevel() && !force) { ev.setCancelled(); } this.server.getPluginManager().callEvent(ev); if (!force && ev.isCancelled()) { return false; } this.server.getLogger().info(this.server.getLanguage().translateString("nukkit.level.unloading", TextFormat.GREEN + this.getName() + TextFormat.WHITE)); Level defaultLevel = this.server.getDefaultLevel(); for (Player player : new ArrayList<>(this.getPlayers().values())) { if (this == defaultLevel || defaultLevel == null) { player.close(player.getLeaveMessage(), "Forced default level unload"); } else { player.teleport(this.server.getDefaultLevel().getSafeSpawn()); } } if (this == defaultLevel) { this.server.setDefaultLevel(null); } this.close(); return true; }
Example 10
Source File: FoodChorusFruit.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override protected boolean onEatenBy(Player player) { super.onEatenBy(player); // Teleportation int minX = player.getFloorX() - 8; int minY = player.getFloorY() - 8; int minZ = player.getFloorZ() - 8; int maxX = minX + 16; int maxY = minY + 16; int maxZ = minZ + 16; Level level = player.getLevel(); if (level == null) return false; NukkitRandom random = new NukkitRandom(); for (int attempts = 0; attempts < 128; attempts++) { int x = random.nextRange(minX, maxX); int y = random.nextRange(minY, maxY); int z = random.nextRange(minZ, maxZ); if (y < 0) continue; while (y >= 0 && !level.getBlock(new Vector3(x, y + 1, z)).isSolid()) { y--; } y++; // Back up to non solid Block blockUp = level.getBlock(new Vector3(x, y + 1, z)); Block blockUp2 = level.getBlock(new Vector3(x, y + 2, z)); if (blockUp.isSolid() || blockUp instanceof BlockLiquid || blockUp2.isSolid() || blockUp2 instanceof BlockLiquid) { continue; } // Sounds are broadcast at both source and destination level.addSound(player.asBlockVector3().asVector3(), Sound.MOB_ENDERMEN_PORTAL); player.teleport(new Vector3(x + 0.5, y + 1, z + 0.5), PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT); level.addSound(player.asBlockVector3().asVector3(), Sound.MOB_ENDERMEN_PORTAL); break; } return true; }
Example 11
Source File: TPAcceptCommand.java From EssentialsNK with GNU General Public License v3.0 | 4 votes |
public boolean execute(CommandSender sender, String label, String[] args) { if (!this.testPermission(sender)) { return false; } if (!this.testIngame(sender)) { return false; } if (args.length > 1) { this.sendUsage(sender); return false; } Player to = (Player) sender; if (api.getLatestTPRequestTo(to) == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.noRequest")); return false; } TPRequest request; Player from; if (args.length == 0) { if ((request = api.getLatestTPRequestTo(to)) == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.unavailable")); return false; } from = request.getFrom(); } else { from = api.getServer().getPlayer(args[0]); if (from == null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.generic.player.notfound", args[0])); return false; } if ((request = api.getTPRequestBetween(from, to)) != null) { sender.sendMessage(TextFormat.RED + Language.translate("commands.tpaccept.noRequestFrom", from.getDisplayName())); return false; } } from.sendMessage(Language.translate("commands.tpaccept.accepted", to.getDisplayName())); sender.sendMessage(Language.translate("commands.generic.teleporting")); if (request.isTo()) { from.teleport(to); } else { to.teleport(from); } api.removeTPRequestBetween(from, to); return true; }