public boolean addResidence(String name, String owner, Location loc1, Location loc2) { if (!Residence.validName(name)) return false; if (loc1 == null || loc2 == null || !loc1.getWorld().getName().equals(loc2.getWorld().getName())) { return false; } PermissionGroup group = Residence.getPermissionManager().getGroup(owner, loc1.getWorld().getName()); CuboidArea newArea = new CuboidArea(loc1, loc2); ClaimedResidence newRes = new ClaimedResidence(owner, loc1.getWorld().getName()); newRes.getPermissions().applyDefaultFlags(); newRes.setEnterMessage(group.getDefaultEnterMessage()); newRes.setLeaveMessage(group.getDefaultLeaveMessage()); ResidenceCreationEvent resevent = new ResidenceCreationEvent(null, name, newRes, newArea); Residence.getServ().getPluginManager().callEvent(resevent); if (resevent.isCancelled()) { return false; } newArea = resevent.getPhysicalArea(); name = resevent.getResidenceName(); if (residences.containsKey(name)) { return false; } newRes.addArea(newArea, "main"); if (newRes.getAreaCount() != 0) { residences.put(name, newRes); } return true; }
public void play(Location location) { if (type != null) { if (data == null) location.getWorld().playEffect(location, type, 0, EffectData.DEFAULT_RADIUS); else location.getWorld().playEffect(location, type, data.getData(), data.getRadius()); } }
@EventHandler(priority = EventPriority.HIGH) public void enterSnitchProximity(PlayerMoveEvent event) { Location from = event.getFrom(); Location to = event.getTo(); if (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ() && from.getWorld().equals(to.getWorld())) { // Player didn't move by at least one block. return; } Player player = event.getPlayer(); if (vanishNoPacket.isPlayerInvisible(player)) { return; } String playerName = player.getName(); Location location = player.getLocation(); World world = location.getWorld(); Set<Snitch> inList = playersInSnitches.get(playerName); if (inList == null) { inList = new TreeSet<Snitch>(); playersInSnitches.put(player.getName(), inList); } Set<Snitch> snitches = snitchManager.findSnitches(world, location); for (Snitch snitch : snitches) { if (!isOnSnitch(snitch, playerName) && doesSnitchExist(snitch, true) || isDebugging()) { if (!inList.contains(snitch)) { inList.add(snitch); for (Player remoteplayer : playerManager.getPlayers()) { String remoteName = remoteplayer.getName(); if (isOnSnitch(snitch, remoteName)) { remoteplayer.sendMessage( ChatColor.AQUA + " * " + playerName + " entered snitch at " + snitch.getName() + " [" + snitch.getX() + " " + snitch.getY() + " " + snitch.getZ() + "]"); } } plugin.getJaLogger().logSnitchEntry(snitch, location, player); } } } Set<Snitch> rmList = new TreeSet<Snitch>(); for (Snitch snitch : inList) { if (snitches.contains(snitch)) { continue; } rmList.add(snitch); } inList.removeAll(rmList); }
private String getLocal(final IUser user, final long radius) { final Location loc = user.getPlayer().getLocation(); final World world = loc.getWorld(); final StringBuilder output = new StringBuilder(); final long radiusSquared = radius * radius; Player userPlayer = user.getPlayer(); for (Player onlinePlayer : server.getOnlinePlayers()) { if (!onlinePlayer.getName().equals(user.getName()) && userPlayer.canSee(onlinePlayer)) { final Location playerLoc = onlinePlayer.getLocation(); if (playerLoc.getWorld() != world) { continue; } final long delta = (long)playerLoc.distanceSquared(loc); if (delta < radiusSquared) { if (output.length() > 0) { output.append(", "); } output.append(onlinePlayer.getDisplayName()).append("§f(§4").append((long)Math.sqrt(delta)).append("m§f)"); } } } return output.length() > 1 ? output.toString() : _("none"); }
public static void perform(Fx fx, String dataString, Collection<Location> locations) { if (fx == TNT) { for (Location location : locations) { if (location == null) continue; SmokeUtil.fakeExplosion(location); } return; } else if (fx == STRIKE) { for (Location location : locations) { if (location == null) continue; location.getWorld().strikeLightningEffect(location); } return; } else if (fx == SMOKE) { SmokeUtil.spawnCloudSimple(locations); return; } // Decide the data Integer data = 0; try { data = Integer.parseInt(dataString); } catch (Exception e) { } for (Location location : locations) { if (location == null) continue; location.getWorld().playEffect(location, fx.bukkitEffect, data.intValue()); } }
public static void speedUpZombie(Zombie z) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Location loc = z.getLocation(); EntityZombie zombie = ((CraftZombie) z).getHandle(); Field fGoalSelector = EntityLiving.class.getDeclaredField("goalSelector"); fGoalSelector.setAccessible(true); Float speed = 0.5F; PathfinderGoalSelector gs = new PathfinderGoalSelector( ((CraftWorld) loc.getWorld()).getHandle() != null && ((CraftWorld) loc.getWorld()).getHandle().methodProfiler != null ? ((CraftWorld) loc.getWorld()).getHandle().methodProfiler : null); gs.a(0, new PathfinderGoalFloat(zombie)); gs.a(1, new PathfinderGoalBreakDoor(zombie)); gs.a(2, new PathfinderGoalMeleeAttack(zombie, EntityHuman.class, speed, false)); gs.a(3, new PathfinderGoalMeleeAttack(zombie, EntityVillager.class, speed, true)); gs.a(4, new PathfinderGoalMoveTowardsRestriction(zombie, speed)); gs.a(5, new PathfinderGoalMoveThroughVillage(zombie, speed, false)); gs.a(6, new PathfinderGoalRandomStroll(zombie, speed)); gs.a(7, new PathfinderGoalLookAtPlayer(zombie, EntityHuman.class, 15.0F)); gs.a(7, new PathfinderGoalRandomLookaround(zombie)); fGoalSelector.set(zombie, gs); }
/** * @param location the {@link Location} around which players must be to see the effect * @param effectName list of effects: https://gist.github.com/riking/5759002 * @param offsetX the amount to be randomly offset by in the X axis * @param offsetY the amount to be randomly offset by in the Y axis * @param offsetZ the amount to be randomly offset by in the Z axis * @param speed the speed of the particles * @param count the number of particles * @param radius the radius around the location */ public static void playParticleEffect( Location location, String effectName, float offsetX, float offsetY, float offsetZ, float speed, int count, int radius) { Validate.notNull(location, "Location cannot be null"); Validate.notNull(effectName, "Effect cannot be null"); Validate.notNull(location.getWorld(), "World cannot be null"); PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles( effectName, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, count); for (Player player : location.getWorld().getPlayers()) { if ((int) player.getLocation().distance(location) <= radius) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); } } }
public void createMap(String id, Player p) throws EmptyClipboardException { Selection sel = WorldEditUtilities.getWorldEdit().getSelection(p); if (sel != null) { MapConfiguration.getMaps().reloadMap(id); Location b1 = new Location( p.getWorld(), sel.getNativeMinimumPoint().getBlockX(), sel.getNativeMinimumPoint().getBlockY(), sel.getNativeMinimumPoint().getBlockZ()); Location b2 = new Location( p.getWorld(), sel.getNativeMaximumPoint().getBlockX(), sel.getNativeMaximumPoint().getBlockY(), sel.getNativeMaximumPoint().getBlockZ()); MapConfiguration.getMaps().getMap(id).set("region.p1.w", b1.getWorld().getName()); MapConfiguration.getMaps().getMap(id).set("region.p1.x", b1.getBlockX()); MapConfiguration.getMaps().getMap(id).set("region.p1.y", b1.getBlockY()); MapConfiguration.getMaps().getMap(id).set("region.p1.z", b1.getBlockZ()); MapConfiguration.getMaps().getMap(id).set("region.p2.w", b2.getWorld().getName()); MapConfiguration.getMaps().getMap(id).set("region.p2.x", b2.getBlockX()); MapConfiguration.getMaps().getMap(id).set("region.p2.y", b2.getBlockY()); MapConfiguration.getMaps().getMap(id).set("region.p2.z", b2.getBlockZ()); MapConfiguration.getMaps().saveMap(id); List<String> enabled = DataConfiguration.getData().getDataFile().getStringList("enabled-maps"); enabled.add(id); DataConfiguration.getData().getDataFile().set("enabled-maps", enabled); DataConfiguration.getData().saveData(); } else { throw new EmptyClipboardException(); } }
private void placePlayerSafely(final Player player, final Location spawnLoc) { Location loc = null; if (spawnLoc == null) return; if (!Settings.noTeleport) return; if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) return; if (!database.isAuthAvailable(player.getName().toLowerCase()) || !player.hasPlayedBefore()) return; Block b = player.getLocation().getBlock(); if (b.getType() == Material.PORTAL || b.getType() == Material.ENDER_PORTAL) { m.send(player, "unsafe_spawn"); if (spawnLoc.getWorld() != null) loc = spawnLoc; } else { Block c = player.getLocation().add(0D, 1D, 0D).getBlock(); if (c.getType() == Material.PORTAL || c.getType() == Material.ENDER_PORTAL) { m.send(player, "unsafe_spawn"); if (spawnLoc.getWorld() != null) loc = spawnLoc; } } if (loc != null) { final Location floc = loc; Bukkit.getScheduler() .scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { player.teleport(floc); } }); } }
public static Location getEvacuation(Player player) { World world = player.getWorld(); String[] portalnames; if (Permission.has(player, "world.spawn") || Permission.has(player, "tpp")) { for (Position pos : getSpawnPoints()) { Location loc = pos.toLocation(); if (loc.getWorld() == null) continue; if (Permission.canEnter(player, loc.getWorld())) { return loc; } } portalnames = Portal.getPortals(); } else { portalnames = Portal.getPortals(world); } for (String name : portalnames) { if (Permission.canEnterPortal(player, name)) { Location loc = Portal.getPortalLocation(name, player.getWorld().getName(), true); if (loc == null) continue; if (loc.getWorld() == null) continue; if (Permission.canEnter(player, loc.getWorld())) { return loc; } } } return null; }
public void remShelf(Location loc) { Shelf shelf = null; for (int i = 0; i < shelves.size(); i++) { Location key = (Location) shelves.keySet().toArray()[i]; if (key.getBlockX() == loc.getBlockX() && key.getBlockY() == loc.getBlockY() && key.getBlockZ() == loc.getBlockZ() && key.getWorld().getName().equals(loc.getWorld().getName())) { shelf = shelves.get(key); break; } } if (shelf != null) { shelves.remove(shelf.getLocation()); getFile() .remove( loc.getWorld().getName() + "," + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ()); saveFile(); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onVehicleMove(VehicleMoveEvent event) { if (((event.getTo().getBlockX() != event.getFrom().getBlockX()) || (event.getTo().getBlockY() != event.getFrom().getBlockY()) || (event.getTo().getBlockZ() != event.getFrom().getBlockZ()))) { Location from, to; Player player = (event.getVehicle().getPassenger() instanceof Player ? (Player) event.getVehicle().getPassenger() : null); if (player == null) { return; } if (!shouldTrackPlayer(player, Refs.TRACK_PLAYER_MOVE)) { return; } from = event.getFrom(); to = event.getTo(); if (from.getWorld().equals(to.getWorld())) { if (from.distance(to) < 10) { StatUtils.instance.modifyStatEntity( player, "vehicle", event.getVehicle(), (int) Math.ceil(from.distance(to))); } } } }
public static int[] getSums( Location firstPoint, Location secndPoint, List<List<CountBlock>> ArrayPaints) { World world = firstPoint.getWorld(); if (world.equals(secndPoint.getWorld())) { int[] sum_paint = new int[ArrayPaints.size()]; int[] cords = area(firstPoint, secndPoint); for (int x = cords[0]; x <= cords[1]; x++) { for (int y = cords[2]; y <= cords[3]; y++) { for (int z = cords[4]; z <= cords[5]; z++) { Block block = new Location(world, x, y, z).getBlock(); for (int i = 0; i < ArrayPaints.size(); i++) { for (CountBlock paint : ArrayPaints.get(i)) { if (paint.equals(block)) { sum_paint[i]++; break; } } } } } } return sum_paint; } return new int[] {-1}; }
/** * Various corner cases that would cause this check to fail or require special treatment * * @param player * @param data * @param from * @param to * @return */ public boolean shouldBeApplied( final Player player, final MovingData data, final Location from, final Location to) { if (player.isDead() || player.isInsideVehicle() || data.insideVehicle) return false; if (data.wasTeleported) { // Remember this location data.teleportedTo = from.clone(); data.wasTeleported = false; data.jumpPhase = 0; } if (data.teleportedTo != null && data.teleportedTo.getWorld().equals(from.getWorld())) { // As long as the from-Location doesn't change, the player didn't accept the teleport if (data.teleportedTo.distanceSquared(from) < 0.01D) { // Event after Teleport ignored return false; } else { // The player finally accepted the teleport with the previous event data.teleportedTo = null; } } // If the target is a bed, don't check (going to bed is a kind of mini teleport...) if (to.getWorld().getBlockTypeIdAt(to) == Material.BED_BLOCK.getId()) { return false; } return true; }
@EventHandler(ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent event) { Location loc = event.getEntity().getLocation(); WorldSettings settings = plugin.getConfigManager().getWorldSettings(event.getEntity().getWorld().getName()); boolean above = loc.getY() >= settings.getWorldSplit(); switch (event.getEntityType()) { case CREEPER: switch (settings.getCreeperType()) { case DESPAWN: event.getEntity().remove(); break; case ABOVE_DESPAWN: event.setCancelled(above); break; default: event.setCancelled(true); loc.getWorld().createExplosion(loc, settings.getCreeperRadius()); } break; case PRIMED_TNT: switch (settings.getTntType()) { case DESPAWN: event.setCancelled(true); break; case ABOVE_DESPAWN: event.setCancelled(above); break; default: event.setCancelled(true); loc.getWorld().createExplosion(loc, settings.getTntRadius()); } } }
protected void die() { String message = spell.getMessage("death_broadcast").replace("$name", commandName); if (message.length() > 0) { controller.sendToMages(message, center); } // Kill power block if (castCommandBlock == null) { castCommandBlock = center.getBlock(); } for (BlockFace powerFace : POWER_FACES) { Block checkForPower = castCommandBlock.getRelative(powerFace); if (commandReload) { controller.unregisterAutomata(checkForPower); } if (checkForPower.getType() == POWER_MATERIAL) { BlockData commitBlock = UndoList.register(checkForPower); commitBlock.setMaterial(Material.AIR); commitBlock.modify(checkForPower); commitBlock.commit(); } else { BlockData commitBlock = UndoList.getBlockData(checkForPower.getLocation()); if (commitBlock != null) { commitBlock.setMaterial(Material.AIR); } } } // Drop item if (dropItem != null && dropItem.length() > 0) { Wand magicItem = controller.createWand(dropItem); if (magicItem != null) { center.getWorld().dropItemNaturally(center, magicItem.getItem()); } } // Drop Xp if (dropXp > 0) { Entity entity = center.getWorld().spawnEntity(center, EntityType.EXPERIENCE_ORB); if (entity != null && entity instanceof ExperienceOrb) { ExperienceOrb orb = (ExperienceOrb) entity; orb.setExperience(dropXp); } } if (includeCommands && castCommandBlock != null) { BlockData commitBlock = UndoList.register(castCommandBlock); commitBlock.setMaterial(Material.AIR); commitBlock.modify(castCommandBlock); commitBlock.commit(); } if (level != null) { level.onDeath(mage, birthMaterial); } if (!mage.isPlayer()) { controller.removeMage(mage); } }
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(); } }
public Boolean outOfRange(Location l) { if (!location.getWorld().equals(l.getWorld())) return true; if (location.equals(l)) return false; if (location.distanceSquared(l) > range_squared) return true; return false; }
/** * Calculates the distance in 2d (x,z) * * @param loc1 location of the first entity * @param loc2 location of the first entity * @return The distant */ public static double calcDistance2d(Location loc1, Location loc2) { if (loc1.getWorld().equals(loc2.getWorld())) { double x = Math.pow(loc1.getX() - loc2.getX(), 2); double z = Math.pow(loc1.getZ() - loc2.getZ(), 2); return Math.sqrt(x + z); } else { return Integer.MAX_VALUE; } }
private void runPhaseTwo(final Beacon beacon, final int repeat) { final Location loc = beacon.getLocation().add(0.0D, 1.0D, 0.0D); final Block aboveBlock = loc.getWorld().getBlockAt(loc); final Random rnd = new Random(); loc.getWorld().playSound(loc, Sound.EXPLODE, 1.0F, 1.0F); aboveBlock.setType(Material.WATER); spawnPressurePlates(beacon); final int itemDropTask = this.plugin .getServer() .getScheduler() .scheduleSyncRepeatingTask( this.plugin, new Runnable() { @SuppressWarnings("deprecation") public void run() { beacon .getWorld() .dropItemNaturally( loc, new ItemStack( BeaconDrops.this.config.getItemId(), rnd.nextInt(64) + 1)); } }, 10L, 10L); this.plugin .getServer() .getScheduler() .scheduleSyncDelayedTask( this.plugin, new Runnable() { public void run() { BeaconDrops.this.plugin.getServer().getScheduler().cancelTask(itemDropTask); aboveBlock.setType(Material.AIR); BeaconDrops.this .plugin .getServer() .getScheduler() .scheduleSyncDelayedTask( BeaconDrops.this.plugin, new Runnable() { public void run() { BeaconDrops.this.removePressurePlates(beacon); BeaconDrops.this.runPhaseOne(beacon, repeat + 1); } }, 60L); } }, this.config.getPhaseTwo() * 20L); }
/** * This method is useful in determining if the player is too far away from the pearl and needs to * be damaged. Keep in mind this method will not damage the player, it is only used for notifying * that the player should be. * * @return Returns true if the player should be damaged, false otherwise. */ public boolean shouldDamage() { Player p; if ((p = Bukkit.getPlayer(uuid)) == null) return false; Location pearlLoc = pp.getLocation(); if (pearlLoc instanceof FakeLocation) // Somehow the summoned player is not where he should be. return true; Location playerLoc = p.getLocation(); if (!pearlLoc.getWorld().equals(playerLoc.getWorld())) return true; return pearlLoc.distance(playerLoc) <= distance; }
@EventHandler(priority = EventPriority.NORMAL) public void onBlockBreak(BlockBreakEvent event) { Player p = event.getPlayer(); Location block_pos = event.getBlock().getLocation(); if (TotalFreedomMod.nukeMonitor) { TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p); Location player_pos = p.getLocation(); boolean out_of_range = false; if (!player_pos.getWorld().equals(block_pos.getWorld())) { out_of_range = true; } else if (player_pos.distanceSquared(block_pos) > (TotalFreedomMod.nukeMonitorRange * TotalFreedomMod.nukeMonitorRange)) { out_of_range = true; } if (out_of_range) { playerdata.incrementFreecamDestroyCount(); if (playerdata.getFreecamDestroyCount() > TotalFreedomMod.freecamTriggerCount) { TFM_Util.bcastMsg( p.getName() + " has been flagged for possible freecam nuking.", ChatColor.RED); TFM_Util.autoEject( p, "Freecam (extended range) block breaking is not permitted on this server."); playerdata.resetFreecamDestroyCount(); event.setCancelled(true); return; } } playerdata.incrementBlockDestroyCount(); if (playerdata.getBlockDestroyCount() > TotalFreedomMod.nukeMonitorCountBreak) { TFM_Util.bcastMsg(p.getName() + " is breaking blocks too fast!", ChatColor.RED); TFM_Util.autoEject( p, "You are breaking blocks too fast. Nukers are not permitted on this server."); playerdata.resetBlockDestroyCount(); event.setCancelled(true); return; } } if (TotalFreedomMod.protectedAreasEnabled) { if (!TFM_SuperadminList.isUserSuperadmin(p)) { if (TFM_ProtectedArea.isInProtectedArea(block_pos)) { event.setCancelled(true); return; } } } }
/** * Finds a teleport location for a spectator NEAR to another location * * <p>If possible, they will be placed 5 blocks away, facing towards the destination player. * * @param l the location they are to be teleported near to */ public static Location getSpectatorTeleportLocation(Location l) { Location lp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location lxp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location lxn = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location lzp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location lzn = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); Location tpl = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ()); boolean xp = true, xn = true, zp = true, zn = true; for (int i = 0; i < 5; i++) { if (xp) { lxp.setX(lxp.getX() + 1); if (!TeleportUtils.isSpaceForPlayer(lxp)) xp = false; } if (xn) { lxn.setX(lxn.getX() - 1); if (!TeleportUtils.isSpaceForPlayer(lxn)) xn = false; } if (zp) { lzp.setZ(lzp.getZ() + 1); if (!TeleportUtils.isSpaceForPlayer(lzp)) zp = false; } if (zn) { lzn.setZ(lzn.getZ() - 1); if (!TeleportUtils.isSpaceForPlayer(lzn)) zn = false; } } if (!xp) lxp.setX(lxp.getX() - 1); if (!xn) lxn.setX(lxn.getX() + 1); if (!zp) lzp.setZ(lzp.getZ() - 1); if (!zn) lzn.setZ(lzn.getZ() + 1); tpl.setYaw(90); tpl.setPitch(0); if (lxp.distanceSquared(lp) > tpl.distanceSquared(lp)) { tpl = lxp; tpl.setYaw(90); } if (lxn.distanceSquared(lp) > tpl.distanceSquared(lp)) { tpl = lxn; tpl.setYaw(270); } if (lzp.distanceSquared(lp) > tpl.distanceSquared(lp)) { tpl = lzp; tpl.setYaw(180); } if (lzn.distanceSquared(lp) > tpl.distanceSquared(lp)) { tpl = lzn; tpl.setYaw(0); } return tpl; }
public List<Block> getBlocks() { List<Block> blocks = new ArrayList<Block>(); for (int x = minLoc.getBlockX(); x < maxLoc.getBlockX() + 1; x++) { for (int y = minLoc.getBlockY(); y < maxLoc.getBlockY() + 1; y++) { for (int z = minLoc.getBlockZ(); z < maxLoc.getBlockZ() + 1; z++) { blocks.add(minLoc.getWorld().getBlockAt(new Location(minLoc.getWorld(), x, y, z))); } } } return blocks; }
public static Block GetLowestBlock(Location Loc) { Location loc = Loc.clone(); Block Use = loc.getWorld().getBlockAt(loc); if (isBlockSolid(Use) || Use.isLiquid()) { return Use; } else { while (!isBlockSolid(Use) && !Use.isLiquid() && loc.getBlockY() > 0) { Use = loc.getWorld().getBlockAt(loc.add(0, -1, 0)); } return loc.getWorld().getBlockAt(loc); } }
public Shelf getShelf(Location loc) { for (int i = 0; i < shelves.size(); i++) { Location key = (Location) shelves.keySet().toArray()[i]; if (key.getBlockX() == loc.getBlockX() && key.getBlockY() == loc.getBlockY() && key.getBlockZ() == loc.getBlockZ() && key.getWorld().getName().equals(loc.getWorld().getName())) { return shelves.get(key); } } return null; }
@Override public void respawn(Location loc) { this.health = 20; boolean changedWorlds = !this.loc.getWorld().getName().equals(loc.getWorld().getName()); CraftServer cserver = (CraftServer) Bukkit.getServer(); PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this, loc, false); cserver.getPluginManager().callEvent(respawnEvent); if (changedWorlds) { PlayerChangedWorldEvent pcwe = new PlayerChangedWorldEvent(this, loc.getWorld()); cserver.getPluginManager().callEvent(pcwe); } }
@EventHandler(priority = EventPriority.HIGHEST) public void limitRedstone(BlockRedstoneEvent event) { Block block = event.getBlock(); if (!materials.contains(block.getType()) || event.getOldCurrent() != 0) { return; } Location loc = block.getLocation(); BlockPosition blockPos = new BlockPosition(loc); AtomicInteger score = scores.putIfAbsent(blockPos, new AtomicInteger()); if (score == null) { score = scores.get(blockPos); if (score == null) { limitRedstone(event); return; } } int newScore = score.incrementAndGet(); int threshold = getConfig().getInt("threshold"); if (newScore < threshold) { return; } if (newScore > threshold) { score.compareAndSet(newScore, threshold); } else { Bukkit.broadcast( "§cToo much redstone @ §e" + loc.getWorld().getName() + " §b" + loc.getBlockX() + " " + loc.getBlockY() + " " + loc.getBlockZ() + " §8[§7" + block.getType().name() + "§8]", "redstonelimiter.notify"); } event.setNewCurrent(0); for (int i = 0; i < 3; ++i) { Location l = loc.clone() .add(random.nextDouble() * 1.1, random.nextDouble() - 0.5, random.nextDouble() * 1.1); loc.getWorld().playEffect(l, Effect.SMOKE, 64); } }
/** * Checks if location is anywhere in the island space (island distance) * * @param target * @return true if in the area */ public boolean inIslandSpace(Location target) { if (target.getWorld().equals(ASkyBlock.getIslandWorld()) || target.getWorld().equals(ASkyBlock.getNetherWorld())) { if (target.getX() >= center.getBlockX() - islandDistance / 2 && target.getX() < center.getBlockX() + islandDistance / 2 && target.getZ() >= center.getBlockZ() - islandDistance / 2 && target.getZ() < center.getBlockZ() + islandDistance / 2) { return true; } } return false; }
public List<Player> getNearbyEntities(Location where, int range) { List<Player> found = new ArrayList<Player>(); if (where.getWorld().getPlayers().size() > 0) { for (Player entity : where.getWorld().getPlayers()) { if (isInBorder(where, entity.getLocation(), range)) { found.add(entity); } } } return found; }