@Override public SpellResult step(CastContext context) { if (entity == null) { return SpellResult.FAIL; } SpellResult result = super.step(context); Location target = actionContext.getTargetLocation(); // TODO: locationOffset and velocityOffset should be made relative if (locationOffset != null) { target = target.clone().add(locationOffset); } if (doVelocity) { Vector velocity = this.velocity.clone().multiply(distanceTravelledThisTick); if (velocityOffset != null) { velocity = velocity.add(velocityOffset); } entity.setVelocity(velocity); } Location currentLocation = entity.getLocation(); if (doTeleport) { if (!orient) { target.setYaw(currentLocation.getYaw()); target.setPitch(currentLocation.getPitch()); } entity.teleport(target); } return result; }
/** {@inheritDoc} */ @Override public TeleportResult safelyTeleport( CommandSender teleporter, Entity teleportee, MVDestination d) { if (d instanceof InvalidDestination) { this.plugin.log(Level.FINER, "Entity tried to teleport to an invalid destination"); return TeleportResult.FAIL_INVALID; } Player teleporteePlayer = null; if (teleportee instanceof Player) { teleporteePlayer = ((Player) teleportee); } else if (teleportee.getPassenger() instanceof Player) { teleporteePlayer = ((Player) teleportee.getPassenger()); } if (teleporteePlayer == null) { return TeleportResult.FAIL_INVALID; } MultiverseCore.addPlayerToTeleportQueue(teleporter.getName(), teleporteePlayer.getName()); Location safeLoc = d.getLocation(teleportee); if (d.useSafeTeleporter()) { safeLoc = this.getSafeLocation(teleportee, d); } if (safeLoc != null) { if (teleportee.teleport(safeLoc)) { if (!d.getVelocity().equals(new Vector(0, 0, 0))) { teleportee.setVelocity(d.getVelocity()); } return TeleportResult.SUCCESS; } return TeleportResult.FAIL_OTHER; } return TeleportResult.FAIL_UNSAFE; }
public void teleport(final Vehicle vehicle) { Location traveller = new Location( this.world, vehicle.getLocation().getX(), vehicle.getLocation().getY(), vehicle.getLocation().getZ()); Location exit = getExit(traveller); double velocity = vehicle.getVelocity().length(); // Stop and teleport vehicle.setVelocity(new Vector()); // Get new velocity final Vector newVelocity = new Vector(); switch ((int) id.getBlock().getData()) { case 2: newVelocity.setZ(-1); break; case 3: newVelocity.setZ(1); break; case 4: newVelocity.setX(-1); break; case 5: newVelocity.setX(1); break; } newVelocity.multiply(velocity); final Entity passenger = vehicle.getPassenger(); if (passenger != null) { final Vehicle v = exit.getWorld().spawn(exit, vehicle.getClass()); vehicle.eject(); vehicle.remove(); passenger.teleport(exit); Stargate.server .getScheduler() .scheduleSyncDelayedTask( Stargate.stargate, new Runnable() { public void run() { v.setPassenger(passenger); v.setVelocity(newVelocity); } }, 1); } else { Vehicle mc = exit.getWorld().spawn(exit, vehicle.getClass()); if (mc instanceof StorageMinecart) { StorageMinecart smc = (StorageMinecart) mc; smc.getInventory().setContents(((StorageMinecart) vehicle).getInventory().getContents()); } mc.setVelocity(newVelocity); vehicle.remove(); } }
@EventHandler public void onEntityDamageEvent(EntityDamageEvent event) { if (Lobby.get().isLobbyEnabled()) { if (event.getCause() == EntityDamageEvent.DamageCause.VOID) { Entity entity = event.getEntity(); if (entity != null) { entity.teleport(Settings.get().getLobbyLocation()); } } event.setCancelled(true); } }
/** {@inheritDoc} */ @Override public TeleportResult safelyTeleport( CommandSender teleporter, Entity teleportee, Location location, boolean safely) { if (safely) { location = this.getSafeLocation(location); } if (location != null) { if (teleportee.teleport(location)) { return TeleportResult.SUCCESS; } return TeleportResult.FAIL_OTHER; } return TeleportResult.FAIL_UNSAFE; }
@Override public boolean playCommand(final EffectArgs ca) { if (ca.getParams().size() == 2 && ca.getParams().get(0) instanceof Entity[] && ca.getParams().get(1) instanceof Number) { Entity[] ents = (Entity[]) ca.getParams().get(0); float yaw = ((Number) ca.getParams().get(1)).floatValue(); for (Entity e : ents) { if (e == null) { continue; } Location l = e.getLocation(); l.setYaw(yaw); e.teleport(l); } return true; } return false; }
/** * Teleport a player to a location. * * @param player The player. * @param to The location to teleport to. * @param keepVehicle Whether or not to keep the vehicle. */ public static void teleport(Player player, Location to, boolean keepVehicle) { if (to == null || player == null) return; if (player.isInsideVehicle()) { // Eject the vehicle... Entity vehicle = player.getVehicle(); vehicle.eject(); // Teleport the player... player.teleport(to); // Remove the vehicle if it's not persisting. if (!keepVehicle) vehicle.remove(); else { // Otherwise teleport the vehicle and remount. vehicle.teleport(to); vehicle.setPassenger(player); } return; } player.teleport(to); }
public static void walkTo( final Entity entity, Location location, double speed, final Runnable callback) { if (entity == null || location == null) return; net.minecraft.server.v1_8_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle(); if (!(nmsEntityEntity instanceof EntityInsentient)) return; final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity; final NavigationAbstract entityNavigation = nmsEntity.getNavigation(); final PathEntity path; final boolean aiDisabled = isAIDisabled(entity); if (aiDisabled) { toggleAI(entity, true); nmsEntity.onGround = true; } path = entityNavigation.a(location.getX(), location.getY(), location.getZ()); if (path != null) { entityNavigation.a(path, 1D); entityNavigation.a(2D); final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b(); nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed); new BukkitRunnable() { @Override public void run() { if (entityNavigation.m() || path.b()) { if (callback != null) callback.run(); nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed); if (aiDisabled) toggleAI(entity, false); cancel(); } } }.runTaskTimer(DenizenAPI.getCurrentInstance(), 1, 1); } // if (!Utilities.checkLocation(location, entity.getLocation(), 20)) { // TODO: generate waypoints to the target location? else { entity.teleport(location); } }
@Override public boolean onCommand(CommandSender sender, Command command, String name, String[] args) { switch (command.getName().toLowerCase()) { case "spawn": if (sender instanceof Player) { ((Player) sender).teleport(config.spawn.LOCATION); sender.sendMessage(ChatColor.RED + "Wooosh!"); } else { sender.sendMessage(ChatColor.RED + "Only usable by players, sorry!"); } break; case "o3-reload": config.reload(); sender.sendMessage(String.format("%sDone.", ChatColor.RED)); break; case "world": if (args.length == 0) return false; if (!(args.length == 4 || args.length == 1)) return false; if (!(sender instanceof Player)) { sender.sendMessage("Only usable by players"); return false; } World world = getServer().getWorld(args[0]); if (world == null) { sender.sendMessage( "This world doesn't exist. Try 'world', 'world_nether', or 'world_the_end'"); return true; } if (args.length == 4) { ((Player) sender) .teleport( new Location( world, Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3]))); } else { ((Player) sender).teleport(world.getSpawnLocation()); } break; case "coords": if (sender instanceof Player) { Location loc = ((Player) sender).getLocation(); sender.sendMessage( String.format( "%sx: %d %sy: %d %sz: %d", ChatColor.RED, loc.getBlockX(), ChatColor.BLUE, loc.getBlockY(), ChatColor.AQUA, loc.getBlockZ())); } else { sender.sendMessage( String.format("%sThis command is only usable by players", ChatColor.RED)); } break; case "item": if (sender instanceof Player) { Player player = (Player) sender; if (args.length < 1 || args.length > 2) return false; String blockID = ""; String blockData = ""; String amount = "64"; if (args[0].contains(":")) { String[] temp = args[0].split(":"); blockID = temp[0]; blockData = temp[1]; } else { blockID = args[0]; } if (args.length == 2) { amount = args[1]; } getServer() .dispatchCommand( player, String.format("give %s %s %s %s", player.getName(), blockID, amount, blockData)); } else { sender.sendMessage( String.format("%sThis command is only usable by players", ChatColor.RED)); } break; case "staffchest": getServer().dispatchCommand(sender, "cmodify g:base_assistance"); break; case "unstaff": getServer().dispatchCommand(sender, "cmodify -g:base_assistance"); break; case "trace": if (args.length < 1 || args.length > 2) { return false; } else if (args.length == 1) { getServer() .dispatchCommand( sender, String.format( "lb lookup player %s sum blocks block 1 block 56 block 14 block 129", args[0])); } else if (args.length == 2) { getServer() .dispatchCommand( sender, String.format( "lb lookup player %s sum blocks block 1 block 56 block 14 block 129 since %s days", args[0], args[1])); } break; case "tppos": if (args.length == 4) { getServer() .dispatchCommand( sender, String.format("world %s %s %s %s", args[0], args[1], args[2], args[3])); } else if (args.length == 3) { getServer() .dispatchCommand(sender, String.format("tp %s %s %s", args[0], args[1], args[2])); } else { return false; } break; case "entity-magnet": if (args.length != 2) { return false; } else { if (sender instanceof Player) { Player player = (Player) sender; EntityType entityType = null; try { entityType = EntityType.valueOf(args[0].toUpperCase()); } catch (Exception e) { player.sendMessage("Entity type does not exist"); return true; } double range = 0; if (range > 50) { sender.sendMessage( "You don't have enough power! Entity magnet only works up to 50 blocks away."); return true; } if (blockedEntities.contains(entityType)) { sender.sendMessage("Magnet doesn't work on this block :("); return true; } try { range = Double.parseDouble(args[1]) / 2; } catch (Exception e) { player.sendMessage("Invalid range"); return true; } for (Entity e : player.getNearbyEntities(range, range, range)) { if (e.getType().equals(entityType)) { e.teleport(player); } } } } break; case "swap-player": if (args.length != 2) { return false; } Player p = getServer().getPlayer(args[0]); bungeePluginChannel = new DataOutputStream(new ByteArrayOutputStream()); ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try { out.writeUTF("Connect"); out.writeUTF(args[1]); p.sendPluginMessage(this, "BungeeCord", b.toByteArray()); } catch (Exception e) { e.printStackTrace(); } break; case "give-pet": if (sender instanceof Player) { Player player = (Player) sender; if (args.length == 1) { if (getServer().getPlayer(args[0]) != null) { player.setMetadata("give-pet", new FixedMetadataValue(this, args[0])); player.sendMessage( "Right click the pet you want to give away. This cannot be undone"); } else { player.sendMessage("This player is not online"); } } else { return false; } } break; case "thor": if (args.length == 1) { Player player = getServer().getPlayer(args[0]); if (player == null) return false; player.getWorld().strikeLightning(player.getLocation()); player.setHealth(0); sender.sendMessage( String.format( "%sThou hast smote the evil player %s with thy mighty hand.", ChatColor.LIGHT_PURPLE, player.getDisplayName())); player.sendMessage( String.format("%sYou have been smote by Thor's Hammer!", ChatColor.RED)); getServer() .dispatchCommand( sender, String.format( "transmission:staffchat I have smitten %s", player.getDisplayName())); } else { return false; } break; case "lsd": for (int j = 0; j < 10; j++) { StringBuilder lsd = new StringBuilder(); for (int i = 0; i < 40; i++) { lsd.append(colors.get(rand.nextInt(colors.size()))); lsd.append(ChatColor.MAGIC); lsd.append('x'); } sender.sendMessage(String.format("%s%s", ChatColor.MAGIC, lsd.toString())); } if (sender instanceof Player) { Player player = (Player) sender; player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 600, 1)); } break; } return true; }
public boolean teleport(List<TeleportEntry> entries) { for (TeleportEntry entry : entries) { Entity entity = entry.getEntity(); Location destination = entry.getDestination(); Field sourceField = entry.getSourceField(); Vec currentPosition = null; if (entity instanceof Player) { Player player = (Player) entity; plugin.getPlayerManager().getPlayerEntry(player.getName()).setTeleporting(false); // done teleport players with bypass permission if (plugin.getPermissionsManager().has(player, "preciousstones.bypass.teleport")) { continue; } // don't teleport if sneaking bypasses if (sourceField.hasFlag(FieldFlag.SNEAKING_BYPASS) && !sourceField.hasFlag(FieldFlag.TELEPORT_ON_SNEAK)) { if (player.isSneaking()) { continue; } } currentPosition = new Vec(player.getLocation()); } // prepare teleport destination World world = destination.getWorld(); Vec safe = findSafeLocation(destination); double x = safe.getX() + .5D; double y = safe.getY(); double z = safe.getZ() + .5D; if (y == -1) { continue; } if (!world.isChunkLoaded(destination.getBlockX() >> 4, destination.getBlockZ() >> 4)) { world.loadChunk(destination.getBlockX() >> 4, destination.getBlockZ() >> 4); } Location loc = new Location( world, x, y, z, entity.getLocation().getYaw(), entity.getLocation().getPitch()); // teleport the player if (sourceField.hasFlag(FieldFlag.TELEPORT_EXPLOSION_EFFECT)) { world.createExplosion(entity.getLocation(), -1); } entity.teleport(loc); if (sourceField.hasFlag(FieldFlag.TELEPORT_EXPLOSION_EFFECT)) { world.createExplosion(loc, -1); } if (entity instanceof Player) { Player player = (Player) entity; if (sourceField.hasFlag(FieldFlag.TELEPORT_ANNOUNCE)) { if (!entry.getAnnounce().isEmpty()) { ChatBlock.send(player, entry.getAnnounce()); } } // start teleport back countdown if (sourceField.getSettings().getTeleportBackAfterSeconds() > 0) { if (sourceField.hasFlag(FieldFlag.TELEPORT_ANNOUNCE)) { ChatBlock.send( player, "teleportAnnounceBack", sourceField.getSettings().getTeleportBackAfterSeconds()); } PlayerEntry playerEntry = plugin.getPlayerManager().getPlayerEntry(player.getName()); playerEntry.setTeleportSecondsRemaining( sourceField.getSettings().getTeleportBackAfterSeconds()); playerEntry.setTeleportVec(currentPosition); playerEntry.startTeleportCountDown(); plugin.getStorageManager().offerPlayer(player.getName()); } } } return true; }
public boolean teleport(MCLocation location, MCTeleportCause cause) { return e.teleport( ((BukkitMCLocation) location).asLocation(), TeleportCause.valueOf(cause.name())); }
public boolean teleport(MCLocation location) { return e.teleport(((BukkitMCLocation) location).asLocation()); }
public boolean teleport(MCEntity destination, MCTeleportCause cause) { return e.teleport( ((BukkitMCEntity) destination).asEntity(), TeleportCause.valueOf(cause.name())); }
public boolean teleport(MCEntity destination) { Entity ent = ((BukkitMCEntity) destination).asEntity(); return e.teleport(ent.getLocation()); }