cn.nukkit.event.player.PlayerTeleportEvent Java Examples
The following examples show how to use
cn.nukkit.event.player.PlayerTeleportEvent.
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: Entity.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) { double yaw = location.yaw; double pitch = location.pitch; Location from = this.getLocation(); Location to = location; if (cause != null) { EntityTeleportEvent ev = new EntityTeleportEvent(this, from, to); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } to = ev.getTo(); } this.ySize = 0; this.setMotion(this.temporalVector.setComponents(0, 0, 0)); if (this.setPositionAndRotation(to, yaw, pitch)) { this.resetFallDistance(); this.onGround = true; this.updateMovement(); return true; } return false; }
Example #2
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) { double yaw = location.yaw; double pitch = location.pitch; Location from = this.getLocation(); Location to = location; if (cause != null) { EntityTeleportEvent ev = new EntityTeleportEvent(this, from, to); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } to = ev.getTo(); } this.ySize = 0; this.setMotion(this.temporalVector.setComponents(0, 0, 0)); if (this.setPositionAndRotation(to, yaw, pitch)) { this.resetFallDistance(); this.onGround = true; this.updateMovement(); return true; } return false; }
Example #3
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) { double yaw = location.yaw; double pitch = location.pitch; Location from = this.getLocation(); Location to = location; if (cause != null) { EntityTeleportEvent ev = new EntityTeleportEvent(this, from, to); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } to = ev.getTo(); } this.ySize = 0; this.setMotion(this.temporalVector.setComponents(0, 0, 0)); if (this.setPositionAndRotation(to, yaw, pitch)) { this.resetFallDistance(); this.onGround = true; this.updateMovement(); return true; } return false; }
Example #4
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Location location) { return this.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #5
Source File: TeleportCommand.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length < 1 || args.length > 6) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; } CommandSender target; CommandSender origin = sender; if (args.length == 1 || args.length == 3) { if (sender instanceof Player) { target = sender; } else { sender.sendMessage(new TranslationContainer("commands.generic.ingame")); return true; } if (args.length == 1) { target = sender.getServer().getPlayer(args[0]); if (target == null) { sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]); return true; } } } else { target = sender.getServer().getPlayer(args[0]); if (target == null) { sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]); return true; } if (args.length == 2) { origin = target; target = sender.getServer().getPlayer(args[1]); if (target == null) { sender.sendMessage(TextFormat.RED + "Can't find player " + args[1]); return true; } } } if (args.length < 3) { ((Player) origin).teleport((Player) target, PlayerTeleportEvent.TeleportCause.COMMAND); Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success", new String[]{origin.getName(), target.getName()})); return true; } else if (((Player) target).getLevel() != null) { int pos; if (args.length == 4 || args.length == 6) { pos = 1; } else { pos = 0; } double x; double y; double z; double yaw; double pitch; try { x = Double.parseDouble(args[pos++]); y = Double.parseDouble(args[pos++]); z = Double.parseDouble(args[pos++]); yaw = ((Player) target).getYaw(); pitch = ((Player) target).getPitch(); } catch (NumberFormatException e1) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; } if (y < 0) y = 0; if (y > 256) y = 256; if (args.length == 6 || (args.length == 5 && pos == 3)) { yaw = Integer.parseInt(args[pos++]); pitch = Integer.parseInt(args[pos++]); } ((Player) target).teleport(new Location(x, y, z, yaw, pitch, ((Player) target).getLevel()), PlayerTeleportEvent.TeleportCause.COMMAND); Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success.coordinates", new String[]{target.getName(), String.valueOf(NukkitMath.round(x, 2)), String.valueOf(NukkitMath.round(y, 2)), String.valueOf(NukkitMath.round(z, 2))})); return true; } sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; }
Example #6
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Location location) { return this.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #7
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Position pos, PlayerTeleportEvent.TeleportCause cause) { return this.teleport(Location.fromObject(pos, pos.level, this.yaw, this.pitch), cause); }
Example #8
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Position pos) { return this.teleport(pos, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #9
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Vector3 pos, PlayerTeleportEvent.TeleportCause cause) { return this.teleport(Location.fromObject(pos, this.level, this.yaw, this.pitch), cause); }
Example #10
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Vector3 pos) { return this.teleport(pos, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #11
Source File: TeleportCommand.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length < 1 || args.length > 6) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; } CommandSender target; CommandSender origin = sender; if (args.length == 1 || args.length == 3) { if (sender instanceof Player) { target = sender; } else { sender.sendMessage(new TranslationContainer("commands.generic.ingame")); return true; } if (args.length == 1) { target = sender.getServer().getPlayer(args[0].replace("@s", sender.getName())); if (target == null) { sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]); return true; } } } else { target = sender.getServer().getPlayer(args[0].replace("@s", sender.getName())); if (target == null) { sender.sendMessage(TextFormat.RED + "Can't find player " + args[0]); return true; } if (args.length == 2) { origin = target; target = sender.getServer().getPlayer(args[1].replace("@s", sender.getName())); if (target == null) { sender.sendMessage(TextFormat.RED + "Can't find player " + args[1]); return true; } } } if (args.length < 3) { ((Player) origin).teleport((Player) target, PlayerTeleportEvent.TeleportCause.COMMAND); Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success", origin.getName(), target.getName())); return true; } else if (((Player) target).getLevel() != null) { int pos; if (args.length == 4 || args.length == 6) { pos = 1; } else { pos = 0; } double x; double y; double z; double yaw; double pitch; try { x = Double.parseDouble(args[pos++].replace("~", "" + ((Player) target).x)); y = Double.parseDouble(args[pos++].replace("~", "" + ((Player) target).y)); z = Double.parseDouble(args[pos++].replace("~", "" + ((Player) target).z)); yaw = ((Player) target).getYaw(); pitch = ((Player) target).getPitch(); } catch (NumberFormatException e1) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; } if (y < 0) y = 0; if (y > 256) y = 256; if (args.length == 6 || (args.length == 5 && pos == 3)) { yaw = Integer.parseInt(args[pos++]); pitch = Integer.parseInt(args[pos++]); } ((Player) target).teleport(new Location(x, y, z, yaw, pitch, ((Player) target).getLevel()), PlayerTeleportEvent.TeleportCause.COMMAND); Command.broadcastCommandMessage(sender, new TranslationContainer("commands.tp.success.coordinates", target.getName(), String.valueOf(NukkitMath.round(x, 2)), String.valueOf(NukkitMath.round(y, 2)), String.valueOf(NukkitMath.round(z, 2)))); return true; } sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; }
Example #12
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 #13
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Vector3 pos) { return this.teleport(pos, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #14
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Position pos, PlayerTeleportEvent.TeleportCause cause) { return this.teleport(Location.fromObject(pos, pos.level, this.yaw, this.pitch), cause); }
Example #15
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Position pos) { return this.teleport(pos, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #16
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Vector3 pos, PlayerTeleportEvent.TeleportCause cause) { return this.teleport(Location.fromObject(pos, this.level, this.yaw, this.pitch), cause); }
Example #17
Source File: Entity.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Vector3 pos) { return this.teleport(pos, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #18
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Location location) { return this.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #19
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Position pos, PlayerTeleportEvent.TeleportCause cause) { return this.teleport(Location.fromObject(pos, pos.level, this.yaw, this.pitch), cause); }
Example #20
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Position pos) { return this.teleport(pos, PlayerTeleportEvent.TeleportCause.PLUGIN); }
Example #21
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean teleport(Vector3 pos, PlayerTeleportEvent.TeleportCause cause) { return this.teleport(Location.fromObject(pos, this.level, this.yaw, this.pitch), cause); }