下面列出了org.bukkit.Location#getZ ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static NPCPath find(NPCEntity entity, Location to, double range, double speed) {
if(speed > 1) {
throw new IllegalArgumentException("Speed cannot be higher than 1!");
}
try {
BlockPosition posFrom = new BlockPosition(entity);
BlockPosition posTo = new BlockPosition(to.getX(), to.getY(), to.getZ());
int k = (int) (range + 8.0);
ChunkCache chunkCache = new ChunkCache(entity.world, posFrom.a(-k, -k, -k), posFrom.a(k, k, k), 0);
PathEntity path = entity.getPathfinder().a(chunkCache, entity, posTo, (float) range);
if(path != null) {
return new NPCPath(entity, path, speed);
} else {
return null;
}
} catch(Exception e) {
return null;
}
}
private boolean hasCleanShot(Location shootHere, Location targetHere) {
double x = shootHere.getX();
double y = shootHere.getY();
double z = shootHere.getZ();
double x1 = targetHere.getX();
double y1 = targetHere.getY();
double z1 = targetHere.getZ();
Vector start = new Vector(x, y, z);
Vector end = new Vector (x1, y1, z1);
BlockIterator bi = new BlockIterator(shootHere.getWorld(), start, end, 0, (int) shootHere.distance(targetHere));
while (bi.hasNext()) {
Block block = bi.next();
// System.out.println(Civs.getPrefix() + ((int) block.getLocation().getX()) +
// ":" + ((int) block.getLocation().getY()) + ":" +
// ((int) block.getLocation().getZ()) + " " + !Util.isSolidBlock(block.getType()));
if (!Util.isSolidBlock(block.getType())) {
return false;
}
}
return true;
}
public static void showFakeItems(Plugin plugin, Player viewer, Location location, org.bukkit.inventory.ItemStack item, int count, Duration duration) {
if(count <= 0) return;
final EntityPlayer nmsPlayer = ((CraftPlayer) viewer).getHandle();
final int[] entityIds = new int[count];
for(int i = 0; i < count; i++) {
final EntityItem entity = new EntityItem(nmsPlayer.getWorld(), location.getX(), location.getY(), location.getZ(), CraftItemStack.asNMSCopy(item));
entity.motX = randomEntityVelocity();
entity.motY = randomEntityVelocity();
entity.motZ = randomEntityVelocity();
sendPacket(viewer, new PacketPlayOutSpawnEntity(entity, ENTITY_TYPE_IDS.get(org.bukkit.entity.Item.class)));
sendPacket(viewer, new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));
entityIds[i] = entity.getId();
}
scheduleEntityDestroy(plugin, viewer.getUniqueId(), duration, entityIds);
}
public static boolean clampToBorder(Location location) {
WorldBorder border = location.getWorld().getWorldBorder();
Location center = border.getCenter();
double radius = border.getSize() / 2d;
double xMin = center.getX() - radius;
double xMax = center.getX() + radius;
double zMin = center.getZ() - radius;
double zMax = center.getZ() + radius;
boolean moved = false;
if(location.getX() < xMin) {
location.setX(xMin);
moved = true;
}
if(location.getX() > xMax) {
location.setX(xMax);
moved = true;
}
if(location.getZ() < zMin) {
location.setZ(zMin);
moved = true;
}
if(location.getZ() > zMax) {
location.setZ(zMax);
moved = true;
}
return moved;
}
public Object newPacketPlayOutEntityTeleport(Object entityliving, Location loc) {
EntityLiving entity = (EntityLiving) entityliving;
entity.locX = loc.getX();
entity.locY = loc.getY();
entity.locZ = loc.getZ();
entity.yaw = loc.getYaw();
entity.pitch = loc.getPitch();
return new PacketPlayOutEntityTeleport(entity);
}
public Object newPacketPlayOutEntityTeleport(Object entityliving, Location loc) {
EntityLiving entity = (EntityLiving) entityliving;
entity.locX = loc.getX();
entity.locY = loc.getY();
entity.locZ = loc.getZ();
entity.yaw = loc.getYaw();
entity.pitch = loc.getPitch();
return new PacketPlayOutEntityTeleport(entity);
}
@Override
public void setFlowerPotBlock(Block block, ItemStack itemStack) {
Location loc = block.getLocation();
CraftWorld cw = (CraftWorld)block.getWorld();
BlockPosition bp = new BlockPosition(loc.getX(), loc.getY(), loc.getZ());
TileEntityFlowerPot te = (TileEntityFlowerPot)cw.getHandle().getTileEntity(bp);
//Bukkit.getLogger().info("Debug: flowerpot materialdata = " + (new ItemStack(potItem, 1,(short) potItemData).toString()));
net.minecraft.server.v1_8_R2.ItemStack cis = CraftItemStack.asNMSCopy(itemStack);
te.a(cis.getItem(), cis.getData());
te.update();
}
public CVItem getBlock(Location location) {
CVItem returnBlock = blocks.get(Region.locationToString(location));
if (returnBlock == null) {
Location newLocation = new Location(location.getWorld(), location.getX() + 0.5,
location.getY() + 0.5, location.getZ() + 0.5);
returnBlock = blocks.get(Region.locationToString(newLocation));
}
return returnBlock;
}
public static boolean isInArea(Location l, Location p1, Location p2) {
if (!p1.getWorld().equals(l.getWorld())) {
return false;
}
Location min = new Location(p1.getWorld(), Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()),
Math.min(p1.getZ(), p2.getZ()));
Location max = new Location(p1.getWorld(), Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()),
Math.max(p1.getZ(), p2.getZ()));
return (min.getX() <= l.getX() && min.getY() <= l.getY() && min.getZ() <= l.getZ() && max.getX() >= l.getX()
&& max.getY() >= l.getY() && max.getZ() >= l.getZ());
}
public TNTSheep(Location location, Player target) {
super(((CraftWorld) location.getWorld()).getHandle());
this.world = location.getWorld();
this.locX = location.getX();
this.locY = location.getY();
this.locZ = location.getZ();
try {
Field b = this.goalSelector.getClass().getDeclaredField("b");
b.setAccessible(true);
b.set(this.goalSelector, new ArrayList<>());
this.getAttributeInstance(GenericAttributes.b).setValue(128D);
this.getAttributeInstance(GenericAttributes.d)
.setValue(
BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
} catch (Exception e) {
BedwarsRel.getInstance().getBugsnag().notify(e);
e.printStackTrace();
}
this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
static boolean isInside(Vector point, Location blockLocation) {
return blockLocation.getX() <= point.getX()
&& point.getX() <= blockLocation.getX() + 1
&& blockLocation.getY() <= point.getY()
&& point.getY() <= blockLocation.getY() + 1
&& blockLocation.getZ() <= point.getZ()
&& point.getZ() <= blockLocation.getZ() + 1;
}
protected boolean inPickupRange(Location playerLoc) {
Location flagLoc = this.getLocation();
if (playerLoc.getY() < flagLoc.getY() + 2 && playerLoc.getY() >= flagLoc.getY() - 2) {
double dx = playerLoc.getX() - flagLoc.getX();
double dz = playerLoc.getZ() - flagLoc.getZ();
if (dx * dx + dz * dz <= 1) {
return true;
}
}
return false;
}
private void reorganize() {
Location location = getLocation();
double y = location.getY();
for (int i = 0 ; i < lines.size() ; i++) {
HologramLine line = getLine(i);
if (line instanceof ItemLine) {
y -= 0.2;
}
Location lineLocation = new Location(location.getWorld(), location.getX(), y, location.getZ());
y -= line.getHeight();
y -= HologramLine.SPACE_BETWEEN_LINES;
line.setLocation(lineLocation);
}
}
public Town getTownAt(Location location) {
ItemManager itemManager = ItemManager.getInstance();
for (Town town : sortedTowns) {
TownType townType = (TownType) itemManager.getItemType(town.getType());
int radius = townType.getBuildRadius();
int radiusY = townType.getBuildRadiusY();
Location townLocation = town.getLocation();
if (townLocation.getWorld() == null) {
continue;
}
if (!townLocation.getWorld().equals(location.getWorld())) {
continue;
}
if (townLocation.getX() - radius >= location.getX()) {
break;
}
if (townLocation.getX() + radius >= location.getX() &&
townLocation.getZ() + radius >= location.getZ() &&
townLocation.getZ() - radius <= location.getZ() &&
townLocation.getY() - radiusY <= location.getY() &&
townLocation.getY() + radiusY >= location.getY()) {
return town;
}
}
return null;
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
if ((int) from.getX() >> 2 != (int) to.getX() >> 2 || (int) from.getZ() >> 2 != (int) to.getZ() >> 2 || (int) from.getY() >> 2 != (int) to.getY() >> 2) {
FawePlayer<Object> player = FawePlayer.wrap(event.getPlayer());
CUI cui = player.getMeta("CUI");
if (cui instanceof StructureCUI) {
StructureCUI sCui = (StructureCUI) cui;
sCui.update();
}
}
}
/**
* Initializes a new LocationBuilder from the given BukkitLocation
*
* @param location location
*/
public LocationBuilder(Location location) {
super();
if (location == null)
throw new IllegalArgumentException("Location cannot be null!");
this.world = location.getWorld().getName();
this.x = location.getX();
this.y = location.getY();
this.z = location.getZ();
this.yaw = location.getYaw();
this.pitch = location.getPitch();
}
public static void sendArrowParticle(Projectile arrow, float x, float y, float z) {
Location loc = arrow.getLocation();
PacketPlayOutWorldParticles packet = new PacketPlayOutWorldParticles(EnumParticle.REDSTONE, true,
(float)loc.getX(), (float)loc.getY(), (float)loc.getZ(), x, y, z, 1f, 0);
PacketUtils.broadcastPacketByUUID(packet, allArrows);
if (arrow.getShooter() instanceof Player && selfArrows.contains(((Player) arrow.getShooter()).getUniqueId()))
PacketUtils.sendPacket((Player) arrow.getShooter(), packet);
}
public static boolean within2DWidth(Entity e, Location closest, double minDist, double centerOffset) {
double xS = (e.getLocation().getX()) - (closest.getX());
xS *= xS;
double zS = (e.getLocation().getZ()) - (closest.getZ());
zS *= zS;
double distancesqr = xS + zS;
return distancesqr <= (minDist*minDist);
}
@SuppressWarnings("null")
@Override
public Double convert(final Location l) {
return axis == 0 ? l.getX() : axis == 1 ? l.getY() : l.getZ();
}
public static String setLocationToString(Location location) {
return location.getX() + ";" + location.getY() + ";" + location.getZ() + ";" + location.getYaw() + ";"
+ location.getPitch();
}