下面列出了org.bukkit.Location#getBlockZ ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@EventHandler
public void onPlayerMove(PlayerMoveEvent ev) {
Location l = ev.getTo();
Integer mapSize = p.getConfig().getInt("map.size");
Integer halfMapSize = (int) Math.floor(mapSize/2);
Integer x = l.getBlockX();
Integer z = l.getBlockZ();
Location spawn = ev.getPlayer().getWorld().getSpawnLocation();
Integer limitXInf = spawn.add(-halfMapSize, 0, 0).getBlockX();
spawn = ev.getPlayer().getWorld().getSpawnLocation();
Integer limitXSup = spawn.add(halfMapSize, 0, 0).getBlockX();
spawn = ev.getPlayer().getWorld().getSpawnLocation();
Integer limitZInf = spawn.add(0, 0, -halfMapSize).getBlockZ();
spawn = ev.getPlayer().getWorld().getSpawnLocation();
Integer limitZSup = spawn.add(0, 0, halfMapSize).getBlockZ();
if (x < limitXInf || x > limitXSup || z < limitZInf || z > limitZSup) {
ev.setCancelled(true);
}
}
@Override
public String getProperty(String name, String playerID) {
if (name.equalsIgnoreCase("location")) {
Location location;
try {
location = loc.getLocation(playerID);
} catch (QuestRuntimeException e) {
LogUtils.getLogger().log(Level.WARNING, "Error while getting location property in '" + instruction.getID() + "' objective: "
+ e.getMessage());
LogUtils.logThrowable(e);
return "";
}
return "X: " + location.getBlockX() + ", Y: " + location.getBlockY() + ", Z: " + location.getBlockZ();
}
return "";
}
public Uncarried(Flag flag, Post post, @Nullable Location location) {
super(flag, post);
if (location == null) location = flag.getReturnPoint(post);
this.location =
new Location(
location.getWorld(),
location.getBlockX() + 0.5,
location.getBlockY(),
location.getBlockZ() + 0.5,
location.getYaw(),
location.getPitch());
Block block = this.location.getBlock();
if (block.getType() == Material.STANDING_BANNER) {
// Banner may already be here at match start
this.oldBlock = BlockStates.cloneWithMaterial(block, Material.AIR);
} else {
this.oldBlock = block.getState();
}
this.oldBase = block.getRelative(BlockFace.DOWN).getState();
}
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void MoveListeners(PlayerMoveEvent event)
{
///block under your feet
Block to = event.getTo().getBlock().getRelative(BlockFace.DOWN);
if(to.getType() == Material.QUARTZ_ORE)
{
Location x = event.getTo();
Location y = event.getFrom();
if(x.getBlockX() != y.getBlockX() || x.getBlockY() != y.getBlockY() || x.getBlockZ() != y.getBlockZ())
{
AnniPlayer user = AnniPlayer.getPlayer(event.getPlayer().getUniqueId());
UUID owner = getBlocksOwner(to);
if(owner != null && user != null)
{
Teleporter tele = this.teleporters.get(owner);
if(tele != null && tele.isLinked() && tele.getOwner().getTeam() == user.getTeam())
{
event.getPlayer().sendMessage(ChatColor.AQUA+"This is a teleporter owned by "+ChatColor.WHITE+tele.getOwner().getName()+ChatColor.AQUA+", Sneak to go through it.");
}
}
}
}
}
protected Location adjustTurretLocation(Location turretLoc, Location playerLoc) {
// Keep the y position the same, but advance 1 block in the direction of the player..?
int diff = 2;
int xdiff = 0;
int zdiff = 0;
if (playerLoc.getBlockX() > turretLoc.getBlockX()) {
xdiff = diff;
} else if (playerLoc.getBlockX() < turretLoc.getBlockX()){
xdiff = -diff;
}
if (playerLoc.getBlockZ() > turretLoc.getBlockZ()) {
zdiff = diff;
} else if (playerLoc.getBlockZ() < turretLoc.getBlockZ()){
zdiff = -diff;
}
return turretLoc.getBlock().getRelative(xdiff, 0, zdiff).getLocation();
}
/**
* Sets the stored location of this Shopkeeper.
* This will not actually move the shopkeeper entity until the next time teleport() is called.
*
* @param location
* The new stored location of this shopkeeper.
*/
public void setLocation(Location location) {
ChunkData oldChunk = this.getChunkData();
x = location.getBlockX();
y = location.getBlockY();
z = location.getBlockZ();
worldName = location.getWorld().getName();
this.updateChunkData();
// update shopkeeper in chunk map:
ShopkeepersPlugin.getInstance().onShopkeeperMove(this, oldChunk);
}
public int getProximityFrom(ParticipantState player, Location location) {
if (Double.isInfinite(location.lengthSquared())) return Integer.MAX_VALUE;
ProximityMetric metric = getProximityMetric(player.getParty());
if (metric == null) return Integer.MAX_VALUE;
int minimumDistance = Integer.MAX_VALUE;
for (Location v : getProximityLocations(player)) {
// If either point is at infinity, the distance is infinite
if (Double.isInfinite(v.lengthSquared())) continue;
int dx = location.getBlockX() - v.getBlockX();
int dy = location.getBlockY() - v.getBlockY();
int dz = location.getBlockZ() - v.getBlockZ();
// Note: distances stay squared as long as possible
int distance;
if (metric.horizontal) {
distance = dx * dx + dz * dz;
} else {
distance = dx * dx + dy * dy + dz * dz;
}
if (distance < minimumDistance) {
minimumDistance = distance;
}
}
return minimumDistance;
}
@Override
public boolean canCreateShopHere(@NotNull Player player, @NotNull Location location) {
com.plotsquared.core.location.Location pLocation =
new com.plotsquared.core.location.Location(
location.getWorld().getName(),
location.getBlockX(),
location.getBlockY(),
location.getBlockZ());
Plot plot = pLocation.getPlot();
if (plot == null) {
return !whiteList;
}
return plot.getFlag(createFlag);
}
@Override
public boolean canTradeShopHere(@NotNull Player player, @NotNull Location location) {
com.plotsquared.core.location.Location pLocation =
new com.plotsquared.core.location.Location(
location.getWorld().getName(),
location.getBlockX(),
location.getBlockY(),
location.getBlockZ());
Plot plot = pLocation.getPlot();
if (plot == null) {
return !whiteList;
}
return plot.getFlag(tradeFlag);
}
/**
* @return a list of unowned islands
*/
public HashMap<String, Island> getUnownedIslands() {
HashMap<String, Island> result = new HashMap<String,Island>();
for (Entry<Integer, TreeMap<Integer, Island>> x : islandGrid.entrySet()) {
for (Island island : x.getValue().values()) {
//plugin.getLogger().info("DEBUG: checking island at " + island.getCenter());
if (island.getOwner() == null && !island.isSpawn() && !island.isPurgeProtected()) {
Location center = island.getCenter();
String serialized = island.getCenter().getWorld().getName() + ":" + center.getBlockX() + ":" + center.getBlockY() + ":" + center.getBlockZ();
result.put(serialized,island);
}
}
}
return result;
}
/**
* Registers packet the handler
*/
protected void registerUpdateHandling() {
new AbstractPacketHandler("PacketPlayInUpdateSign", PacketExtension.PacketHandler.Direction.IN) {
@Override
public void handle(PacketEvent event) {
try {
final PacketPlayInUpdateSign packetPlayInUpdateSign = new PacketPlayInUpdateSign(event.getPacket());
final Player player = event.getPlayer();
Location v = getSignLocations().remove(player.getUniqueId());
if(v == null
|| packetPlayInUpdateSign.getBlockPositionWrapper().getX() != v.getBlockX()
|| packetPlayInUpdateSign.getBlockPositionWrapper().getY() != v.getBlockY()
|| packetPlayInUpdateSign.getBlockPositionWrapper().getZ() != v.getBlockZ()) {
return;
}
final SignGUIListener response = getListeners().remove(player.getUniqueId());
if(response != null) {
event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
response.onSignDone(player, packetPlayInUpdateSign.getLines());
}
});
}
}
catch(IllegalAccessException | InvocationTargetException e) {
LoggerUtils.exception(e);
}
}
};
}
/**
* <pre>
* z
* x = -z ^ x = z
* \ -x < z | x < z /
* \ | /
* \ | /
* \ | /
* \ | / x > z
* -x > z \ | /
* \ | /
* -----------------------+-----------------------------> x
* / | \
* -x > -z / | \
* (x < z) / | \ x > -z
* / | \
* / | \
* / -x < -z | x < -z \
* x = z | x = -z
* |
* v
* </pre>
*/
static Location nextIslandLocation(final Location lastIsland) {
int d = Settings.island_distance;
LocationUtil.alignToDistance(lastIsland, d);
int x = lastIsland.getBlockX();
int z = lastIsland.getBlockZ();
if (x < z) {
if (-1 * x < z) {
x += d;
} else {
z += d;
}
} else if (x > z) {
if (-1 * x >= z) {
x -= d;
} else {
z -= d;
}
} else { // x == z
if (x <= 0) {
z += d;
} else {
z -= d;
}
}
lastIsland.setX(x);
lastIsland.setZ(z);
return lastIsland;
}
private void handleFrozenPlayers(PlayerMoveEvent e){
UhcPlayer uhcPlayer = playersManager.getUhcPlayer(e.getPlayer());
if (uhcPlayer.isFrozen()){
Location freezeLoc = uhcPlayer.getFreezeLocation();
Location toLoc = e.getTo();
if (toLoc.getBlockX() != freezeLoc.getBlockX() || toLoc.getBlockZ() != freezeLoc.getBlockZ()){
Location newLoc = toLoc.clone();
newLoc.setX(freezeLoc.getBlockX() + .5);
newLoc.setZ(freezeLoc.getBlockZ() + .5);
e.getPlayer().teleport(newLoc);
}
}
}
private static String locationToChunkString(Location l) {
return l.getWorld().getName() + ";Chunk;" + (l.getBlockX() >> 4) + ';' + (l.getBlockZ() >> 4);
}
private String getStringLocation(final Location l) {
if (l == null) {
return "";
}
return l.getWorld().getName() + ":" + l.getBlockX() + ":" + l.getBlockY() + ":" + l.getBlockZ();
}
/**
* This is a generic scan that can work in the overworld or the nether
* @param l - location around which to scan
* @param i - the range to scan for a location less than 0 means the full island.
* @return - safe location, or null if none can be found
*/
public Location bigScan(Location l, int i) {
final int height;
final int depth;
if (i > 0) {
height = i;
depth = i;
} else {
Island island = plugin.getGrid().getIslandAt(l);
if (island == null) {
return null;
}
i = island.getProtectionSize();
height = l.getWorld().getMaxHeight() - l.getBlockY();
depth = l.getBlockY();
}
//plugin.getLogger().info("DEBUG: ranges i = " + i);
//plugin.getLogger().info(" " + minX + "," + minZ + " " + maxX + " " + maxZ);
//plugin.getLogger().info("DEBUG: height = " + height);
//plugin.getLogger().info("DEBUG: depth = " + depth);
//plugin.getLogger().info("DEBUG: trying to find a safe spot at " + l.toString());
// Work outwards from l until the closest safe location is found.
int minXradius = 0;
int maxXradius = 0;
int minZradius = 0;
int maxZradius = 0;
int minYradius = 0;
int maxYradius = 0;
do {
int minX = l.getBlockX()-minXradius;
int minZ = l.getBlockZ()-minZradius;
int minY = l.getBlockY()-minYradius;
int maxX = l.getBlockX()+maxXradius;
int maxZ = l.getBlockZ()+maxZradius;
int maxY = l.getBlockY()+maxYradius;
for (int x = minX; x<= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
if (!((x > minX && x < maxX) && (z > minZ && z < maxZ) && (y > minY && y < maxY))) {
//plugin.getLogger().info("DEBUG: checking " + x + "," + y + "," + z);
Location ultimate = new Location(l.getWorld(), x + 0.5D, y, z + 0.5D);
if (isSafeLocation(ultimate)) {
//plugin.getLogger().info("DEBUG: Found! " + ultimate);
return ultimate;
}
}
}
}
}
if (minXradius < i) {
minXradius++;
}
if (maxXradius < i) {
maxXradius++;
}
if (minZradius < i) {
minZradius++;
}
if (maxZradius < i) {
maxZradius++;
}
if (minYradius < depth) {
minYradius++;
}
if (maxYradius < height) {
maxYradius++;
}
//plugin.getLogger().info("DEBUG: Radii " + minXradius + "," + minYradius + "," + minZradius +
// "," + maxXradius + "," + maxYradius + "," + maxZradius);
} while (minXradius < i || maxXradius < i || minZradius < i || maxZradius < i || minYradius < depth
|| maxYradius < height);
// Nothing worked
return null;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerMove(PlayerMoveEvent event) {
if (settings.getProperty(ALLOW_UNAUTHED_MOVEMENT) && settings.getProperty(ALLOWED_MOVEMENT_RADIUS) <= 0) {
return;
}
Location from = event.getFrom();
Location to = event.getTo();
if (to == null) {
return;
}
/*
* Limit player X and Z movements to 1 block
* Deny player Y+ movements (allows falling)
*/
if (from.getBlockX() == to.getBlockX()
&& from.getBlockZ() == to.getBlockZ()
&& from.getY() - to.getY() >= 0) {
return;
}
Player player = event.getPlayer();
if (!listenerService.shouldCancelEvent(player)) {
return;
}
if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
// "cancel" the event
event.setTo(event.getFrom());
return;
}
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return;
}
Location spawn = spawnLoader.getSpawnLocation(player);
if (spawn != null && spawn.getWorld() != null) {
if (!player.getWorld().equals(spawn.getWorld())) {
player.teleport(spawn);
} else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
player.teleport(spawn);
}
}
}
/**
* Determines if an island is at a location in this area
* location. Also checks if the spawn island is in this area.
* Used for creating new islands ONLY
*
* @param loc location to query
* @return true if found, otherwise false
*/
public boolean islandAtLocation(Location loc) {
if (loc == null) {
return true;
}
// Make sure location is on the grid
loc = getClosestIsland(loc);
// getLogger().info("DEBUG checking islandAtLocation for location " +
// loc.toString());
// Check the island grid
if (getIslandAt(loc) != null) {
// This checks if loc is inside the island spawn radius too
return true;
}
final int px = loc.getBlockX();
final int pz = loc.getBlockZ();
// Extra spawn area check
// If island protection distance is less than island distance then the
// check above will cover it
// Island edge must be > protection edge spawn
Island spawn = getSpawn();
if (spawn != null && spawn.getProtectionSize() > spawn.getIslandDistance()) {
if (Math.abs(px - spawn.getCenter().getBlockX()) < ((spawn.getProtectionSize() + Settings.islandDistance) / 2)
&& Math.abs(pz - spawn.getCenter().getBlockZ()) < ((spawn.getProtectionSize() + Settings.islandDistance) / 2)) {
// getLogger().info("DEBUG: island is within spawn space " + px
// + " " + pz);
return true;
}
}
if (!Settings.useOwnGenerator) {
// Block check
if (!loc.getBlock().isEmpty() && !loc.getBlock().isLiquid()) {
// Get the closest island
plugin.getLogger().info("Found solid block at island height - adding to " + ISLANDS_FILENAME + " " + px + "," + pz);
addIsland(px, pz);
return true;
}
// Look around
for (int x = -5; x <= 5; x++) {
for (int y = 10; y <= 255; y++) {
for (int z = -5; z <= 5; z++) {
if (!loc.getWorld().getBlockAt(x + px, y, z + pz).isEmpty() && !loc.getWorld().getBlockAt(x + px, y, z + pz).isLiquid()) {
plugin.getLogger().info("Solid block found during long search - adding to " + ISLANDS_FILENAME + " " + px + "," + pz);
addIsland(px, pz);
return true;
}
}
}
}
}
return false;
}
public static boolean isSolid(Block b, Location l) {
if(b.getType().name().equals("SNOW"))
return false;
if(b.getType().name().contains("SIGN"))
return false;
if (b.getType().name().endsWith("CARPET")) {
return false;
}
if (b.getType() == Material.WATER) {
if (QAMain.blockbullet_water)
return true;
}
if (b.getType().name().contains("LEAVE")) {
if (QAMain.blockbullet_leaves)
return true;
}
if (b.getType().name().contains("SLAB") || b.getType().name().contains("STEP")) {
if (!QAMain.blockbullet_halfslabs && ((l.getY() - l.getBlockY() > 0.5 && b.getData() == 0)
|| (l.getY() - l.getBlockY() <= 0.5 && b.getData() == 1)))
return false;
return true;
}
if (b.getType().name().contains("BED_") || b.getType().name().contains("_BED")
|| b.getType().name().contains("DAYLIGHT_DETECTOR")) {
if (!QAMain.blockbullet_halfslabs && (l.getY() - l.getBlockY() > 0.5))
return false;
return true;
}
if (b.getType().name().contains("DOOR")) {
if (QAMain.blockbullet_door)
return true;
return false;
}
if (b.getType().name().contains("GLASS")) {
if (QAMain.blockbullet_glass)
return true;
return false;
}
if (b.getType().name().contains("STAIR")) {
if (b.getData() < 4 && (l.getY() - l.getBlockY() < 0.5))
return true;
if (b.getData() >= 4 && (l.getY() - l.getBlockY() > 0.5))
return true;
switch (b.getData()) {
case 0:
case 4:
return l.getX() - (0.5 + l.getBlockX()) > 0;
case 1:
case 5:
return l.getX() - (0.5 + l.getBlockX()) < 0;
case 2:
case 6:
return l.getZ() - (0.5 + l.getBlockZ()) > 0;
case 3:
case 7:
return l.getZ() - (0.5 + l.getBlockZ()) < 0;
}
}
if (b.getType().name().endsWith("FERN")) {
return false;
}
if (b.getType().isOccluding()) {
return true;
}
return false;
}
@Override
public FaweLocation getLocation() {
final Location loc = this.parent.getLocation();
return new FaweLocation(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}