本文整理了Java中org.bukkit.entity.Entity
类的一些代码示例,展示了Entity
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity
类的具体详情如下:
包路径:org.bukkit.entity.Entity
类名称:Entity
[英]Represents a base entity in the world
[中]表示世界上的基本实体
代码示例来源:origin: GlowstoneMC/Glowstone
final Location location = sender instanceof Entity ? ((Entity) sender).getLocation()
: ((BlockCommandSender) sender).getBlock().getLocation();
final Entity[] entities = new CommandTarget(sender, args[0]).getMatched(location);
targets = new ArrayList<>();
final Player player = Bukkit.getPlayerExact(playerPattern);
return false;
} else {
currentLocation = sender instanceof Entity ? ((Entity) sender).getLocation()
: ((BlockCommandSender) sender).getBlock().getLocation();
currentLocation = new Location(world, 0, 0, 0);
spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation()
: ((BlockCommandSender) sender).getBlock().getLocation();
} else {
sender.sendMessage(ChatColor.RED
target.setBedSpawnLocation(spawnLocation, true);
sender.sendMessage("Set " + target.getName() + "'s spawn point to "
+ spawnLocation.getBlockX() + ", " + spawnLocation.getBlockY() + ", "
+ spawnLocation.getBlockZ() + ".");
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
BlockFace facing = BlockDispenser.getFacing(block);
Location targetLocation = block.getLocation().clone()
.add(facing.getModX(), facing.getModY(), facing.getModZ());
for (Entity entity : targetLocation.getWorld().getNearbyEntities(targetLocation, 3, 3, 3)) {
switch (entity.getType()) {
case PLAYER:
case ARMOR_STAND:
&& player.getEyeLocation().getBlockZ() == targetLocation.getZ());
if ((targetLocationTest1 || targetLocationTest2)) {
return ((GlowInventory) ((Player) player).getInventory())
.tryToFillSlots(stack, 36, 40);
代码示例来源:origin: EngineHub/WorldEdit
@Override
public boolean remove() {
org.bukkit.entity.Entity entity = entityRef.get();
if (entity != null) {
entity.remove();
return entity.isDead();
} else {
return true;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
private GlowItem getFirstDroppedItem(Location location) {
for (Entity entity : location.getChunk().getEntities()) {
if (location.getBlockX() != entity.getLocation().getBlockX()
|| location.getBlockY() != entity.getLocation().getBlockY()
|| location.getBlockZ() != entity.getLocation().getBlockZ()) {
continue;
}
if (entity.getType() != EntityType.DROPPED_ITEM) {
continue;
}
return ((GlowItem) entity);
}
return null;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Gets the name of an entity.
*
* @param entity an entity
* @return the first of the following that exists and is non-empty: {@code
* entity.getCustomName()}, {@code entity.getName()}, {@code
* entity.getType().getName()}
*/
public static String getName(Entity entity) {
String customName = entity.getCustomName();
if (customName != null && !customName.isEmpty()) {
return customName;
}
String name = entity.getName();
if (name == null || name.isEmpty()) {
name = entity.getType().getName();
}
return name;
}
代码示例来源:origin: GlowstoneMC/Glowstone
targets = new CommandTarget(sender, args[0]).getMatched(location);
} else {
Player targetPlayer = Bukkit.getPlayerExact(args[0]);
if (targetPlayer != null) {
location = targetPlayer.getLocation();
String yaw = args[4];
String pitch = args[5];
targetLocation = CommandUtils.getRotation(target.getLocation(), yaw, pitch);
} else {
targetLocation.setYaw(target.getLocation().getYaw());
targetLocation.setPitch(target.getLocation().getPitch());
target.teleport(targetLocation);
sender.sendMessage(
"Teleported " + target.getName() + " to " + targetLocation.getX() + " "
+ targetLocation.getY() + " " + targetLocation.getZ());
代码示例来源:origin: GlowstoneMC/Glowstone
for (Entity entity : source.getWorld().getEntities()) {
if (entity.getLocation().distanceSquared(source) < minRadius) {
continue;
if (!(maxRadius == 0 || entity.getLocation().distanceSquared(source) < maxRadius)) {
continue;
if (!types.contains(entity.getType())) {
continue;
if (getX() != null && getX() != entity.getLocation().getBlockX()) {
continue;
if (getY() != null && getY() != entity.getLocation().getBlockY()) {
continue;
if (getZ() != null && getZ() != entity.getLocation().getBlockZ()) {
continue;
if (gameModes != null && entity.getType() != EntityType.PLAYER) {
continue;
if (maxLevel != null && entity.getType() != EntityType.PLAYER) {
continue;
if (minLevel != null && entity.getType() != EntityType.PLAYER) {
continue;
代码示例来源:origin: TheBusyBiscuit/Slimefun4
private static ArmorStand getArmorStand(Block b) {
Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.7F, b.getZ() + 0.5);
for (Entity n: l.getChunk().getEntities()) {
if (n instanceof ArmorStand) {
if (n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n;
}
}
ArmorStand hologram = ArmorStandFactory.createHidden(l);
return hologram;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Checks whether the entity is within the specified distance from the block.
*
* @param entity the entity
* @param block the block
* @param x maximum distance on x axis
* @param y maximum distance on y axis
* @param z maximum distance on z axis
* @return Whether the entity is within distance
*/
private boolean isWithinDistance(Entity entity, Block block, int x, int y, int z) {
Location loc = entity.getLocation();
return Math.abs(loc.getX() - block.getX()) <= x
&& Math.abs(loc.getY() - block.getY()) <= y
&& Math.abs(loc.getZ() - block.getZ()) <= z;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation()
: ((BlockCommandSender) sender).getBlock().getLocation();
} else {
sender.sendMessage(ChatColor.RED
return false;
} else {
senderLocation = sender instanceof Entity ? ((Entity) sender).getLocation()
: ((BlockCommandSender) sender).getBlock().getLocation();
senderLocation = new Location(world, 0, 0, 0);
if (spawnLocation.getBlockY() < 0) {
sender.sendMessage(ChatColor.RED + "The y coordinate (" + spawnLocation.getBlockY()
+ ") is too small, it must be at least 0.");
return false;
} else if (spawnLocation.getBlockY() > world.getMaxHeight()) {
sender.sendMessage(ChatColor.RED + "'" + spawnLocation.getBlockY()
+ "' is too high for the current world. Max value is '" + world.getMaxHeight()
+ "'.");
return false;
world.setSpawnLocation(spawnLocation.getBlockX(), spawnLocation.getBlockY(),
spawnLocation.getBlockZ());
sender.sendMessage(
代码示例来源:origin: mcmonkeyprojects/Sentinel
/**
* Fires a snowball from the NPC at a target.
*/
public void fireSnowball(Location target) {
sentinel.swingWeapon();
sentinel.stats_snowballsThrown++;
sentinel.faceLocation(target);
Vector forward = getLivingEntity().getEyeLocation().getDirection();
Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange()));
Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SNOWBALL);
((Projectile) ent).setShooter(getLivingEntity());
ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'.
}
代码示例来源:origin: elBukkit/MagicPlugin
public static void swingOffhand(Entity entity, int range) {
int rangeSquared = range * range;
String worldName = entity.getWorld().getName();
Location center = entity.getLocation();
for (Player player : Bukkit.getOnlinePlayers()) {
if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > rangeSquared) {
continue;
}
swingOffhand(player, entity);
}
}
代码示例来源:origin: bitquest/bitquest
public boolean run(
CommandSender sender, Command cmd, String label, String[] args, Player player) {
Chunk c = player.getLocation().getChunk();
for (World w : Bukkit.getWorlds()) {
List<Entity> entities = w.getEntities();
int killed = 0;
for (Entity entity : entities) {
if (entity instanceof Player) {
} else if (entity.getLocation().getChunk().getX() == c.getX()
&& entity.getLocation().getChunk().getZ() == c.getZ()) {
killed = killed + 1;
entity.remove();
System.out.println("[butcher] removed " + entity.getName());
}
}
player.sendMessage(ChatColor.GREEN + "Killed " + killed + " entities on " + w.getName());
}
return false;
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
double modX = random.nextDouble() - 0.5;
double modZ = random.nextDouble() - 0.5;
Location xpLocation = new Location(world,
location.getBlockX() + 0.5 + modX, location.getY(),
location.getBlockZ() + 0.5 + modZ);
GlowExperienceOrb orb = (GlowExperienceOrb) world
orb.setSourceEntityId(this.getUniqueId());
if (getLastDamager() != null) {
orb.setTriggerEntityId(getLastDamager().getUniqueId());
代码示例来源:origin: eccentricdevotion/TARDIS
@EventHandler(ignoreCancelled = true)
public void onCompanionEntityClick(PlayerInteractEntityEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
ResultSetAntiBuild rs = new ResultSetAntiBuild(plugin, uuid);
if (!rs.resultSet() || !plugin.getTrackerKeeper().getAntiBuild().containsKey(rs.getTardis_id())) {
return;
}
Vector v = event.getRightClicked().getLocation().toVector();
TARDISAntiBuild tab = plugin.getTrackerKeeper().getAntiBuild().get(rs.getTardis_id());
if (v.isInAABB(tab.getMin(), tab.getMax())) {
event.setCancelled(true);
TARDISMessage.send(event.getPlayer(), "ANTIBUILD_TIMELORD", tab.getTimelord());
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
GlowWorld world = (GlowWorld) location.getWorld();
setBlockOnFire(block);
for (int i = 0; i < 4; i++) {
int x = location.getBlockX() - 1 + ThreadLocalRandom.current().nextInt(3);
int z = location.getBlockZ() - 1 + ThreadLocalRandom.current().nextInt(3);
int y = location.getBlockY() - 1 + ThreadLocalRandom.current().nextInt(3);
block = world.getBlockAt(x, y, z);
if (entity.isDead()) {
continue;
.damage(5, this, EntityDamageEvent.DamageCause.LIGHTNING);
entity.setFireTicks(entity.getMaxFireTicks());
代码示例来源:origin: TheBusyBiscuit/Slimefun4
@Override
public void run() {
if (Bukkit.getPlayer(uuid) == null) Bukkit.getScheduler().cancelTask(id);
else if (Bukkit.getPlayer(uuid).isDead()) Bukkit.getScheduler().cancelTask(id);
else if (!Bukkit.getPlayer(uuid).isSneaking()) Bukkit.getScheduler().cancelTask(id);
else {
for (Entity item: Bukkit.getPlayer(uuid).getNearbyEntities(6D, 6D, 6D)) {
if (item instanceof Item) {
if (!item.hasMetadata("no_pickup") && ((Item) item).getPickupDelay() <= 0) {
item.teleport(Bukkit.getPlayer(uuid).getEyeLocation());
Bukkit.getPlayer(uuid).getWorld().playSound(Bukkit.getPlayer(uuid).getEyeLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5L, 2L);
}
}
}
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
@EventHandler(priority = EventPriority.LOW)
public void onEntityDamage(EntityDamageByEntityEvent e) {
if (e.getCause() != DamageCause.ENTITY_EXPLOSION) {
return;
}
String l = e.getDamager().getLocation().getWorld().getName();
if (l.contains("TARDIS") || l.equals(plugin.getConfig().getString("creation.default_world_name"))) {
e.setCancelled(true);
}
}
}
代码示例来源:origin: elBukkit/MagicPlugin
protected void teleportTo(Entity sourceEntity, Entity targetEntity) {
Location targetLocation = targetEntity.getLocation();
// Try to place you in front of the other player, and facing them
BlockFace targetFacing = getFacing(targetEntity.getLocation());
Location candidate = findPlaceToStand(targetLocation.getBlock().getRelative(targetFacing).getRelative(targetFacing).getLocation(), 4, 4);
if (candidate != null) {
candidate.setPitch(0);
candidate.setYaw(360 - targetLocation.getYaw());
targetLocation = candidate;
}
sourceEntity.teleport(targetLocation);
}
代码示例来源:origin: eccentricdevotion/TARDIS
private List<Entity> getJunkTravellers() {
// spawn an entity
Entity orb = junkLoc.getWorld().spawnEntity(junkLoc, EntityType.EXPERIENCE_ORB);
List<Entity> ents = orb.getNearbyEntities(4.0, 4.0, 4.0);
orb.remove();
return ents;
}
内容来源于网络,如有侵权,请联系作者删除!