本文整理汇总了Java中org.bukkit.entity.Entity.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getLocation方法的具体用法?Java Entity.getLocation怎么用?Java Entity.getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Entity
的用法示例。
在下文中一共展示了Entity.getLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isInLineOfSight
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
/**
* @param check
* The entity to check whether
* @param distance
* The difference in distance to allow for.
* @return
*/
private boolean isInLineOfSight(Entity check, double distance) {
final Location entityLocation = check.getLocation();
final BlockIterator iterator = new BlockIterator(profile.getPlayer().getEyeLocation(), 0.0, 7);
while (iterator.hasNext()) {
final Location current = iterator.next().getLocation();
if (getLocationDifference(current, entityLocation, "X") < distance
&& getLocationDifference(current, entityLocation, "Y") < distance
&& getLocationDifference(current, entityLocation, "Z") < distance) {
return true;
}
}
// The entity has not been found in the player's line of sight.
return false;
}
示例2: pullEntityToLocation
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public void pullEntityToLocation(Entity e, Location loc) {
Location entityLoc = e.getLocation();
entityLoc.setY(entityLoc.getY() + 0.5D);
e.teleport(entityLoc);
double g = -0.08D;
if (loc.getWorld() != entityLoc.getWorld())
return;
double d = loc.distance(entityLoc);
double t = d;
double v_x = (1.0D + 0.07000000000000001D * t) * (loc.getX() - entityLoc.getX()) / t;
double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t - 0.5D * g * t;
double v_z = (1.0D + 0.07000000000000001D * t) * (loc.getZ() - entityLoc.getZ()) / t;
Vector v = e.getVelocity();
v.setX(v_x);
v.setY(v_y);
v.setZ(v_z);
e.setVelocity(v);
e.setFallDistance(0f);
}
示例3: handleBuff
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public static void handleBuff(Entity player, Entity e) {
if (!(player instanceof Player))
return;
Player p = (Player) player;
PlayerDataRPG pd = plugin.getPD(p);
if (pd != null && buffMap.containsKey(e.getUniqueId())) {
try {
Buff buff = buffMap.remove(e.getUniqueId());
buff.apply(p, pd);
} catch (Exception e2) {
e2.printStackTrace();
}
Location loc = e.getLocation();
RParticles.showWithOffsetPositiveY(ParticleEffect.EXPLOSION_LARGE, loc, 1.0, 10);
e.remove();
}
}
示例4: onPlayerMoveEvent
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@EventHandler
public void onPlayerMoveEvent(PlayerMoveEvent e) {
for (Entity en : e.getPlayer().getWorld().getEntities()) {
if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().distance(e.getTo()) <= 1) {
Location l = en.getLocation();
//e.getPlayer().sendMessage(getPlayerDirection(e.getPlayer()));
if (getPlayerDirection(e.getPlayer()).equals("north")) {
l.add(-1.2, 0, 0);
}
else if (getPlayerDirection(e.getPlayer()).equals("south")) {
l.add(1.2, 0, 0);
}
else if (getPlayerDirection(e.getPlayer()).equals("east")) {
l.add(0, 0, -1.2);
}
else if (getPlayerDirection(e.getPlayer()).equals("west")) {
l.add(0, 0, 1.2);
}
else {
l = e.getPlayer().getLocation();
}
l.setDirection(e.getPlayer().getLocation().getDirection());
e.setTo(l);
}
}
}
示例5: execute
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
protected void execute(Event e) {
Entity ent = entity.getSingle(e);
Location to = towards.getSingle(e);
if (ent == null || to == null) {
return;
}
Vector velocity = ent.getVelocity();
float fallDistance = ent.getFallDistance();
Location from = ent.getLocation();
Vector direction = isToward ? MathUtils.vectorFromLocations(from, to) : MathUtils.vectorFromLocations(to, from);
ent.teleport(new Location(
ent.getWorld(),
from.getX(),
from.getY(),
from.getZ(),
MathUtils.notchYaw(MathUtils.getYaw(direction)),
MathUtils.notchPitch(MathUtils.getPitch(direction))
));
ent.setVelocity(velocity);
ent.setFallDistance(fallDistance);
}
示例6: teleportPlayer
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public void teleportPlayer(Entity p, int dx, int dy, int dz) {
NavyCraft.instance.DebugMessage("Teleporting entity " + p.getEntityId(), 4);
Location pLoc = p.getLocation();
pLoc.setWorld(craft.world);
pLoc.setX(pLoc.getX() + dx);
pLoc.setY(pLoc.getY() + dy + .05);
pLoc.setZ(pLoc.getZ() + dz);
if (p instanceof Player) {
playerTeleports.put((Player) p, pLoc);
} else {
p.teleport(pLoc);
}
}
示例7: onHit
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@EventHandler
public void onHit(ProjectileHitEvent evt) {
Projectile projectile = evt.getEntity();
String customId = projectile.getCustomName();
if (customId == null || !customId.equals("recreator.structure.turret.tnt")) return;
Location loc;
Block block = evt.getHitBlock();
if (block != null) {
loc = block.getLocation();
block.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 1.8F, true, true);
return;
}
Entity entity = evt.getEntity();
if (entity != null) {
loc = entity.getLocation();
entity.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 1.8F, true, true);
}
}
示例8: onHit
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@EventHandler
public void onHit(ProjectileHitEvent evt) {
Projectile projectile = evt.getEntity();
String customId = projectile.getCustomName();
if (customId == null || !customId.equals("recreator.item.fatman")) return;
Location loc;
Block block = evt.getHitBlock();
if (block != null) {
loc = block.getLocation();
block.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 50F, true, true);
return;
}
Entity entity = evt.getEntity();
if (entity != null) {
loc = entity.getLocation();
entity.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 50F, true, true);
}
}
示例9: cast
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
public boolean cast(final Player p, PlayerDataRPG pd, int level) {
if(!pd.isStealthed()) {
p.sendMessage(ChatColor.RED + "Shadow Warp can only be used while in stealth.");
return false;
}
Vector dir = p.getLocation().getDirection().normalize().multiply(0.3);
Location start = p.getLocation().add(0, p.getEyeHeight() * 0.75, 0).clone();
Location curr = start.clone();
Entity target = null;
for (int k = 0; k < 30; k++) {
for (Entity e : RMath.getNearbyEntities(curr, 1.5)) {
if (e != p) {
if (Spell.canDamage(e, true)) {
target = e;
break;
}
}
}
if(target != null)
break;
curr.add(dir);
if(!RParticles.isAirlike(curr.getBlock()))
break;
}
if (target == null) {
p.sendMessage(ChatColor.RED + "Failed to find a Shadow Warp target.");
return false;
}
Location loc = target.getLocation();
loc = loc.add(0, 0.3, 0);
loc.add(target.getLocation().getDirection().normalize().multiply(-2));
p.teleport(loc);
Spell.notify(p, "You teleport behind your target.");
return true;
}
示例10: moveToward
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
private void moveToward(Entity entity, Location to, double speed) {
Location loc = entity.getLocation();
double x = loc.getX() - to.getX();
double y = loc.getY() - to.getY();
double z = loc.getZ() - to.getZ();
Vector velocity = new Vector(x, y, z).normalize().multiply(-speed);
entity.setVelocity(velocity);
}
示例11: resolveDamage
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
public @Nullable FallInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
FallState fall = getFall(victim);
if(fall != null) {
switch(damageType) {
case VOID: fall.to = FallInfo.To.VOID; break;
case FALL: fall.to = FallInfo.To.GROUND; break;
case LAVA: fall.to = FallInfo.To.LAVA; break;
case FIRE_TICK:
if(fall.isInLava) {
fall.to = FallInfo.To.LAVA;
} else {
return null;
}
break;
default: return null;
}
return fall;
} else {
switch(damageType) {
case FALL:
return new GenericFallInfo(FallInfo.To.GROUND, victim.getLocation(), victim.getFallDistance());
case VOID:
return new GenericFallInfo(FallInfo.To.VOID, victim.getLocation(), victim.getFallDistance());
}
return null;
}
}
示例12: movePlayer
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public void movePlayer(Entity p, int dx, int dy, int dz) {
NavyCraft.instance.DebugMessage("Moving player", 4);
int mccraftspeed = craft.speed;
if (mccraftspeed > 2) {
mccraftspeed = 2;
}
Vector pVel = p.getVelocity();
if (dx > 0) {
dx = craft.speed;
} else {
dx = craft.speed * -1;
}
if (dy > 0) {
dy = craft.speed;
} else {
dy = craft.speed * -1;
}
if (dz > 0) {
dz = craft.speed;
} else {
dz = craft.speed * -1;
}
pVel = pVel.add(new Vector(dx, dy, dz));
if ((pVel.getX() > 10) || (pVel.getZ() > 10) || (pVel.getY() > 10)) {
System.out.println("Velocity is too high, have to teleport " + p.getEntityId());
Location pLoc = p.getLocation();
pLoc.setX(pLoc.getX() + pVel.getX());
pLoc.setY(pLoc.getY() + pVel.getY() + .05);
pLoc.setZ(pLoc.getZ() + pVel.getZ());
p.teleport(pLoc);
} else {
p.setVelocity(pVel);
}
}
示例13: getNearbyEntities
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public static ArrayList<Entity> getNearbyEntities(Location loc, double radius) {
ArrayList<Entity> list = new ArrayList<Entity>();
ArrayList<Chunk> chunkList = new ArrayList<Chunk>();
int baseX, baseZ;
baseX = loc.getChunk().getX();
baseZ = loc.getChunk().getZ();
for (int dx = -1; dx <= 1; dx++)
for (int dz = -1; dz <= 1; dz++)
chunkList.add(loc.getWorld().getChunkAt(baseX + dx, baseZ + dz));
for (Chunk chunk : chunkList) {
for (Entity e : chunk.getEntities()) {
Location eLoc = e.getLocation();
if (e instanceof LivingEntity)
eLoc = eLoc.add(0, ((LivingEntity) e).getEyeHeight() * 0.75, 0);
double x1 = eLoc.getX();
double y1 = eLoc.getY();
double z1 = eLoc.getZ();
double x2 = loc.getX();
double y2 = loc.getY();
double z2 = loc.getZ();
double xdiff = x1 - x2;
double ydiff = Math.abs(y1 - y2) - 0.7;
if (ydiff < 0)
ydiff = 0;
double zdiff = z1 - z2;
double sq = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
if (sq <= radius * radius)
list.add(e);
}
}
return list;
}
示例14: getNearbyEntitiesCylinder
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public static ArrayList<Entity> getNearbyEntitiesCylinder(Location loc, double radius, double vertical) {
ArrayList<Entity> list = new ArrayList<Entity>();
ArrayList<Chunk> chunkList = new ArrayList<Chunk>();
int baseX, baseZ;
baseX = loc.getChunk().getX();
baseZ = loc.getChunk().getZ();
for (int dx = -1; dx <= 1; dx++)
for (int dz = -1; dz <= 1; dz++)
chunkList.add(loc.getWorld().getChunkAt(baseX + dx, baseZ + dz));
for (Chunk chunk : chunkList) {
for (Entity e : chunk.getEntities()) {
Location eLoc = e.getLocation();
if (e instanceof LivingEntity)
eLoc = eLoc.add(0, ((LivingEntity) e).getEyeHeight() * 0.75, 0);
double x1 = eLoc.getX();
double y1 = eLoc.getY();
double z1 = eLoc.getZ();
double x2 = loc.getX();
double y2 = loc.getY();
double z2 = loc.getZ();
double xdiff = x1 - x2;
double ydiff = Math.abs(y1 - y2);
if (ydiff > vertical)
continue;
double zdiff = z1 - z2;
double sq = xdiff * xdiff + zdiff * zdiff;
if (sq <= radius * radius)
list.add(e);
}
}
return list;
}
示例15: isInside
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public boolean isInside(Entity entity) {
Location loc = entity.getLocation();
return isInside(loc.getBlockX() >> 4, loc.getBlockZ() >> 4);
}