public static Location lookAt(Location loc, Location lookat) { loc = loc.clone(); double dx = lookat.getX() - loc.getX(); double dy = lookat.getY() - loc.getY(); double dz = lookat.getZ() - loc.getZ(); if (dx != 0) { if (dx < 0) { loc.setYaw((float) (1.5 * Math.PI)); } else { loc.setYaw((float) (0.5 * Math.PI)); } loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx)); } else if (dz < 0) { loc.setYaw((float) Math.PI); } double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2)); loc.setPitch((float) -Math.atan(dy / dxz)); loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI); loc.setPitch(loc.getPitch() * 180f / (float) Math.PI); return loc; }
public Banker spawnBanker(String name, Location l, String id, String bankName) { if (bankers.containsKey(id)) { Log.warning("NPC with that id already exists, existing NPC returned"); return bankers.get(id); } else { if (name.length() > 16) { // Check and nag if name is too long, spawn NPC anyway with shortened name. String tmp = name.substring(0, 16); Log.warning("NPCs can't have names longer than 16 characters,"); Log.warning(name + " has been shortened to " + tmp); name = tmp; } WorldServer ws = getWorldServer(l.getWorld()); NPCEntity npcEntity = new NPCEntity(this, ws, name, new ItemInWorldManager(ws)); npcEntity.setPositionRotation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch()); ws.addEntity(npcEntity); // the right way Banker npc = new Banker(npcEntity, bankName); npc.setYaw(l.getYaw()); if (Bukkit.getPluginManager().isPluginEnabled("Spout")) { SpoutPlayer sp = npc.getSpoutPlayer(); sp.setSkin("http://dl.dropbox.com/u/18216599/images/bankersskin.png"); sp.setTitle(ChatColor.GOLD + "Banker\n" + ChatColor.WHITE + "[" + bankName + "]"); } bankers.put(id, npc); return npc; } }
public boolean executeCommand( CommandSender sender, String command, String[] args, TweakcraftUtils plugin) throws PermissionsException, CommandSenderException, CommandUsageException, CommandException { if (sender instanceof Player) if (!plugin.check((Player) sender, "getpos")) throw new PermissionsException(command); Location loc = null; /** Permissions checking! */ if (args.length == 0 && !(sender instanceof Player)) throw new CommandUsageException( "If you're going to call this from a console i need a player to check!"); if (args.length == 0 && sender instanceof Player) loc = ((Player) sender).getLocation().clone(); if (args.length > 0 && sender instanceof Player) if (!plugin.check((Player) sender, "getpos.other")) throw new PermissionsException(command); if (args.length > 0) { List<Player> plist = plugin.getServer().matchPlayer(args[0]); if (plist.size() == 0) { throw new CommandUsageException(ChatColor.YELLOW + "Can't find player!"); } else if (plist.size() > 1) { throw new CommandUsageException( ChatColor.YELLOW + "Can't match player, got more than one result!"); } else { loc = plist.get(0).getLocation().clone(); } } if (loc != null) { Integer x, y, z, yaw, pitch; x = Math.round((float) loc.getX()); y = Math.round((float) loc.getY()); z = Math.round((float) loc.getZ()); yaw = Math.round((float) loc.getYaw()); pitch = Math.round((float) loc.getPitch()); sender.sendMessage(ChatColor.YELLOW + "Pos X: " + x + " Y: " + y + " Z: " + z); sender.sendMessage(ChatColor.YELLOW + "Rotation: " + yaw + " Pitch: " + pitch); sender.sendMessage(ChatColor.YELLOW + "World: " + loc.getWorld().getName()); String dir = plugin.getCompassDirection(loc.getYaw()); double degreeRotation = ((loc.getYaw() - 90) % 360); if (degreeRotation < 0) degreeRotation += 360.0; sender.sendMessage( ChatColor.YELLOW + "Compass: "******" (" + (Math.round(degreeRotation * 10) / 10.0) + ")"); } else { throw new CommandException("This isn't supposed to happen!"); } return true; }
public static boolean isPlayerLookingAtAnother(Player p1, Player p2) { boolean isLooking = false; Location loc = lookAt(p1.getLocation(), p2.getLocation()); Location loc1 = p1.getLocation(); int yaw1 = (int) Math.floor(loc.getYaw()); int yaw2 = (int) Math.floor(loc1.getYaw()); int pitch1 = (int) Math.floor(loc.getPitch()); int pitch2 = (int) Math.floor(loc1.getPitch()); if (yaw1 == yaw2 && pitch1 == pitch2) { isLooking = true; } return isLooking; }
@Test public void shouldReadDataFromFile() { // given Player player = mock(Player.class); given(player.getUniqueId()).willReturn(SAMPLE_UUID); World world = mock(World.class); given(bukkitService.getWorld("nether")).willReturn(world); // when LimboPlayer data = limboPlayerStorage.readData(player); // then assertThat(data, not(nullValue())); assertThat(data.isOperator(), equalTo(true)); assertThat(data.isCanFly(), equalTo(true)); assertThat(data.getWalkSpeed(), equalTo(0.2f)); assertThat(data.getFlySpeed(), equalTo(0.1f)); assertThat(data.getGroup(), equalTo("players")); Location location = data.getLocation(); assertThat(location.getX(), equalTo(-113.219)); assertThat(location.getY(), equalTo(72.0)); assertThat(location.getZ(), equalTo(130.637)); assertThat(location.getWorld(), equalTo(world)); assertThat(location.getPitch(), equalTo(24.15f)); assertThat(location.getYaw(), equalTo(-292.484f)); }
/** * Set the values, all constructors uses this function * * @param loc location of the view * @param maxDistance how far it checks for blocks * @param viewHeight where the view is positioned in y-axis * @param checkDistance how often to check for blocks, the smaller the more precise */ private void setValues( Location loc, int maxDistance, double viewHeight, double checkDistance, TIntHashSet transparent) { this.maxDistance = maxDistance; this.checkDistance = checkDistance; curDistance = 0; int xRotation = (int) (loc.getYaw() + 90) % 360; int yRotation = (int) loc.getPitch() * -1; double h = checkDistance * Math.cos(Math.toRadians(yRotation)); offset = new Vector( (h * Math.cos(Math.toRadians(xRotation))), (checkDistance * Math.sin(Math.toRadians(yRotation))), (h * Math.sin(Math.toRadians(xRotation)))); targetPosDouble = loc.add(0, viewHeight, 0).toVector(); targetPos = targetPosDouble.toBlockVector(); prevPos = targetPos; transparentBlocks = transparent; if (transparentBlocks == null) { transparentBlocks = new TIntHashSet(new int[] {0}); } }
@Override public void send(Player player) { final PacketPlayOutSpawnEntity p23 = new PacketPlayOutSpawnEntity(); final Location position = player.getLocation(); p23.a = entityId; // v1_7_R1 p23.b = MathHelper.floor(position.getX() * 32.0D); // v1_7_R1 p23.c = MathHelper.floor(position.getY() * 32.0D); // v1_7_R1 p23.d = MathHelper.floor(position.getZ() * 32.0D); // v1_7_R1 p23.h = MathHelper.d(position.getPitch() * 256.0F / 360.0F); // v1_7_R1 p23.i = MathHelper.d(position.getYaw() * 256.0F / 360.0F); // v1_7_R1 p23.j = vehicleTypeId; // v1_7_R1 p23.k = dataValue; // v1_7_R1 if (dataValue > 0) { final Vector velocity = getVelocity(); double d1 = velocity.getX(); double d2 = velocity.getY(); double d3 = velocity.getZ(); double d4 = 3.9D; if (d1 < -d4) d1 = -d4; if (d2 < -d4) d2 = -d4; if (d3 < -d4) d3 = -d4; if (d1 > d4) d1 = d4; if (d2 > d4) d2 = d4; if (d3 > d4) d3 = d4; p23.e = (int) (d1 * 8000.0D); // v1_7_R1 p23.f = (int) (d2 * 8000.0D); // v1_7_R1 p23.g = (int) (d3 * 8000.0D); // v1_7_R1 } PlayerHelper.sendPacketToPlayer(player, p23); }
public static void UpdateBuild(Player player, Location loc) { String query = "UPDATE `perks_build` SET " + "world = '" + loc.getWorld().getName() + "', " + "x = '" + loc.getX() + "', " + "y = '" + loc.getY() + "', " + "z = '" + loc.getZ() + "', " + "yaw = '" + loc.getYaw() + "', " + "pitch = '" + loc.getPitch() + "' " + "WHERE player = '" + player.getName() + "';"; m_perksDB.query(query); }
// ######################################################################################################################################## public int getLocationId(Location location) { ResultSet rs = this.databaseConnection.insertSafeQueryAndKeys( "INSERT INTO `locations` (`X`, `Y`, `Z`, `H`, `P`, `world`)" + "VALUES(" + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ() + ", " + (int) location.getYaw() + ", " + (int) location.getPitch() + ", '" + location.getWorld().getName() + "')"); try { while (rs.next()) { return rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } return -1; }
public static void AddBuild(String player, Location loc) { String query = "INSERT INTO `perks_build` " + "(`player`,`world`,`x`,`y`,`z`,`yaw`,`pitch`) VALUES (" + "'" + player + "'," + "'" + loc.getWorld().getName() + "'," + "'" + loc.getX() + "'," + "'" + loc.getY() + "'," + "'" + loc.getZ() + "'," + "'" + loc.getYaw() + "'," + "'" + loc.getPitch() + "');"; m_perksDB.query(query); }
public static CustomEntityPlayer newInstance(org.bukkit.entity.Player playerDuplicate) { WorldServer worldServer = ((CraftWorld) playerDuplicate.getWorld()).getHandle(); CustomEntityPlayer player = new CustomEntityPlayer( worldServer.getMinecraftServer(), worldServer, ((CraftPlayer) playerDuplicate).getHandle().getProfile(), new PlayerInteractManager(worldServer)); Location loc = playerDuplicate.getLocation(); player.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); ((Player) player.getBukkitEntity()).setItemInHand(playerDuplicate.getItemInHand()); ((Player) player.getBukkitEntity()).setCustomName(playerDuplicate.getName()); ((Player) player.getBukkitEntity()) .getEquipment() .setArmorContents(playerDuplicate.getInventory().getArmorContents()); player.setInventory( new ArrayList<ItemStack>(Arrays.asList(playerDuplicate.getInventory().getContents()))); player.getBukkitEntity().setGameMode(GameMode.SURVIVAL); player.getBukkitEntity().setCanPickupItems(false); ((Player) player.getBukkitEntity()).setHealthScale(playerDuplicate.getHealthScale()); ((Player) player.getBukkitEntity()).setMaxHealth(playerDuplicate.getMaxHealth()); ((Player) player.getBukkitEntity()).setHealth(playerDuplicate.getHealth()); ((Player) player.getBukkitEntity()).setRemoveWhenFarAway(false); worldServer.addEntity(player, SpawnReason.CUSTOM); return player; }
public void save() { if (hasUpdated) { hasUpdated = false; String sql = "UPDATE " + DeityNPCMain.getNPCTableName() + " SET name = ?, name_color = ?, x_coord = ?, y_coord = ?, z_coord = ?, yaw = ?, pitch = ?, held_item_row_id = ?, armor_helm_row_id = ?, armor_chest_row_id = ?, armor_legging_row_id = ?, armor_boot_row_id = ? WHERE id = ?;"; DeityAPI.getAPI() .getDataAPI() .getMySQL() .write( sql, name, (nameColor.getChar() + "").toUpperCase(), location.getBlockX(), location.getBlockY(), location.getBlockZ(), location.getYaw(), location.getPitch(), heldItem.getId(), armorHelm.getId(), armorChest.getId(), armorLegging.getId(), armorBoot.getId(), databaseId); } }
public static org.bukkit.entity.Entity spawnCustomEntity( org.bukkit.World world, Location at, Class<? extends Entity> clazz, EntityType type) { World handle = ((CraftWorld) world).getHandle(); Entity entity = null; try { Constructor<?> constructor = getCustomEntityConstructor(clazz, type); entity = (Entity) constructor.newInstance(handle); } catch (Exception e) { Messaging.logTr(Messages.ERROR_SPAWNING_CUSTOM_ENTITY, e.getMessage()); return null; } entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch()); handle.addEntity(entity); entity.setLocation(at.getX(), at.getY(), at.getZ(), at.getYaw(), at.getPitch()); return entity.getBukkitEntity(); }
@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; }
public Location getExit(Location traveller) { Location loc = null; // Check if the gate has an exit block if (gate.getExit() != null) { Blox exit = getBlockAt(gate.getExit()); int back = (isBackwards()) ? -1 : 1; loc = exit.modRelativeLoc( 0D, 0D, 1D, traveller.getYaw(), traveller.getPitch(), modX * back, 1, modZ * back); } else { Stargate.log.log( Level.WARNING, "[Stargate] Missing destination point in .gate file " + gate.getFilename()); } if (loc != null) { if (getWorld().getBlockTypeIdAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()) == Material.STEP.getId()) { loc.setY(loc.getY() + 0.5); } loc.setPitch(traveller.getPitch()); return loc; } return traveller; }
public static void LocationRegister(Location Loc, String MainMsg, String SubMsg, String Index) { File file = new File("plugins/rTutorialReloaded/Location.yml"); YamlConfiguration LocationYaml = YamlConfiguration.loadConfiguration(file); ConfigurationSection CS = LocationYaml.getConfigurationSection("Locations"); CS.createSection(Index); World world = Loc.getWorld(); double x = Double.valueOf(Loc.getX()); double y = Double.valueOf(Loc.getY()); double z = Double.valueOf(Loc.getZ()); float pitch = Loc.getPitch(); float yaw = Loc.getYaw(); ConfigurationSection CS2 = CS.getConfigurationSection(Index); CS2.createSection("Location"); CS2.createSection("Message"); ConfigurationSection CS3 = FileSection.PlusSelect(CS2, "Location"); CS3.set("World", world.getName()); CS3.set("Coordinate", x + "," + y + "," + z); CS3.set("Angle", String.valueOf(yaw + "," + pitch)); ConfigurationSection CS4 = FileSection.PlusSelect(CS2, "Message"); CS4.set("Main", MainMsg); if (!(SubMsg.equalsIgnoreCase("¾øÀ½") || SubMsg.equalsIgnoreCase("None"))) { CS4.set("Sub", SubMsg); } try { LocationYaml.save(file); } catch (IOException e) { e.printStackTrace(); } LocationLoader.LocationCfg(); return; }
public void teleportAway(Player player) { // prepare teleport destination Location destination = player.getLocation(); 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) { return; } 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, destination.getYaw(), destination.getPitch()); // teleport the player player.teleport(loc); }
public boolean spawn() { if (location.getChunk().isLoaded()) { NPCHuman entity = (NPCHuman) getHandle(); getHandle() .setPositionRotation( location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); if (heldItem != null) { entity.getBukkitEntity().setItemInHand(heldItem.getItemStack()); } if (armorHelm != null) { entity.getBukkitEntity().getInventory().setHelmet(armorHelm.getItemStack()); } if (armorChest != null) { entity.getBukkitEntity().getInventory().setChestplate(armorChest.getItemStack()); } if (armorLegging != null) { entity.getBukkitEntity().getInventory().setLeggings(armorLegging.getItemStack()); } if (armorBoot != null) { entity.getBukkitEntity().getInventory().setBoots(armorBoot.getItemStack()); } ((CraftWorld) location.getWorld()).getHandle().addEntity(entity); return true; } return false; }
private boolean start(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { return true; } Player player = (Player) sender; WorldInstance instance = plugin.getWorldInstance(player); if (instance == null) { player.sendMessage("You are not in an instance."); return true; } Location loc = player.getLocation(); String location = loc.getX() + "," + loc.getY() + "," + loc.getZ() + "," + loc.getYaw() + "," + loc.getPitch(); instance.getBase().setStartLocationString(location); setConfigValue(instance, "start", location); return true; }
public boolean teleport(Location location, TeleportCause cause) { entity.world = ((CraftWorld) location.getWorld()).getHandle(); entity.setLocation( location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // entity.setLocation() throws no event, and so cannot be cancelled return true; }
@Override public SpellResult perform(CastContext context) { Entity entity = context.getEntity(); if (entity == null) { return SpellResult.ENTITY_REQUIRED; } Location targetLocation = context.getLocation(); for (int i = 0; i < 2; i++) { if (!context.allowPassThrough(targetLocation.getBlock().getType())) return SpellResult.NO_TARGET; targetLocation.setY(targetLocation.getY() + 1); } Location location = context.findPlaceToStand(targetLocation, verticalSearchDistance, true); if (location == null && !safe) { location = context.getTargetLocation(); location.setPitch(targetLocation.getPitch()); location.setYaw(targetLocation.getYaw()); verticalSearchDistance = 0; } if (location != null) { teleport(context, entity, location); return SpellResult.CAST; } return SpellResult.NO_TARGET; }
public TicketLocation(Location location) { this.worldName = location.getWorld().getName(); this.x = location.getX(); this.y = location.getY(); this.z = location.getZ(); this.yaw = location.getYaw(); this.pitch = location.getPitch(); }
public void setProperty(final String path, final Location loc) { set((path == null ? "" : path + ".") + "world", loc.getWorld().getName()); set((path == null ? "" : path + ".") + "x", loc.getX()); set((path == null ? "" : path + ".") + "y", loc.getY()); set((path == null ? "" : path + ".") + "z", loc.getZ()); set((path == null ? "" : path + ".") + "yaw", loc.getYaw()); set((path == null ? "" : path + ".") + "pitch", loc.getPitch()); }
public static MinecartMember spawn(Location at, int type) { MinecartMember mm = new MinecartMember( WorldUtil.getNative(at.getWorld()), at.getX(), at.getY(), at.getZ(), type); mm.yaw = at.getYaw(); mm.pitch = at.getPitch(); mm.world.addEntity(mm); return mm; }
public void setLobby(Location l) { DataConfiguration.getData().getDataFile().set("lobby.w", l.getWorld().getName()); DataConfiguration.getData().getDataFile().set("lobby.x", l.getBlockX()); DataConfiguration.getData().getDataFile().set("lobby.y", l.getBlockY()); DataConfiguration.getData().getDataFile().set("lobby.z", l.getBlockZ()); DataConfiguration.getData().getDataFile().set("lobby.pitch", l.getPitch()); DataConfiguration.getData().getDataFile().set("lobby.yaw", l.getYaw()); DataConfiguration.getData().saveData(); }
public void setTeamSpawn(String map, String team, Location l) { MapConfiguration.getMaps().getMap(map).set(team + ".spawn.w", l.getWorld().getName()); MapConfiguration.getMaps().getMap(map).set(team + ".spawn.x", l.getBlockX()); MapConfiguration.getMaps().getMap(map).set(team + ".spawn.y", l.getBlockY()); MapConfiguration.getMaps().getMap(map).set(team + ".spawn.z", l.getBlockZ()); MapConfiguration.getMaps().getMap(map).set(team + ".spawn.pitch", l.getPitch()); MapConfiguration.getMaps().getMap(map).set(team + ".spawn.yaw", l.getYaw()); MapConfiguration.getMaps().saveMap(map); }
public static List<String> getLocationString(Location location) { ArrayList<String> stringLocation = new ArrayList<String>(); stringLocation.add(location.getWorld().getName()); stringLocation.add(location.getX() + ""); stringLocation.add(location.getY() + ""); stringLocation.add(location.getZ() + ""); stringLocation.add(location.getPitch() + ""); stringLocation.add(location.getYaw() + ""); return stringLocation; }
/** * Modifies location information of the given Spawn Packet. * * @param entitySpawnPacket SquidSpawn or GuardianSpawn packet for the entity. * @param location location the entity should be spawned at. * @return beam packet used to spawn for players. */ public static WrappedBeamPacket modifyPacketEntitySpawn( WrappedBeamPacket entitySpawnPacket, Location location) { PacketContainer container = entitySpawnPacket.getHandle(); container.getIntegers().write(2, (int) Math.floor(location.getX() * 32.0)); container.getIntegers().write(3, (int) Math.floor(location.getY() * 32.0)); container.getIntegers().write(4, (int) Math.floor(location.getZ() * 32.0)); container.getBytes().write(0, (byte) (location.getYaw() * 256.0F / 360.0F)); container.getBytes().write(1, (byte) (location.getPitch() * 256.0F / 360.0F)); return entitySpawnPacket; }
public boolean teleport(Location location, TeleportCause cause) { if (entity.ridingEntity != null || entity.riddenByEntity != null || entity.isDead) { return false; } entity.worldObj = ((CraftWorld) location.getWorld()).getHandle(); entity.setPositionAndRotation( location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); // entity.setLocation() throws no event, and so cannot be cancelled return true; }
public static String serializeLocation(Location l, boolean exact) { if (l != null) { String key = l.getWorld().getName() + ","; if (exact) { key += l.getX() + "," + l.getY() + "," + l.getZ() + "," + l.getYaw() + "," + l.getPitch(); } else { key += l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ(); } return key; } return null; }