本文整理匯總了Java中org.bukkit.entity.Entity類的典型用法代碼示例。如果您正苦於以下問題:Java Entity類的具體用法?Java Entity怎麽用?Java Entity使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Entity類屬於org.bukkit.entity包,在下文中一共展示了Entity類的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: onEntityDamageByEntity
import org.bukkit.entity.Entity; //導入依賴的package包/類
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Player attacker = getDamageSource(event.getDamager());
Entity eDefender = event.getEntity();
if (!(eDefender instanceof Player)) {
forbidIfInProtectedTerritory(attacker, eDefender, event, ATTACK);
return;
}
Player defender = (Player) eDefender;
Faction aFaction = plugin.getFactionCache().getByMember(attacker);
Faction dFaction = plugin.getFactionCache().getByMember(defender);
Faction rFaction = plugin.getFactionCache().getByLocation(defender.getLocation());
if (aFaction.getRelation(dFaction).isProtected()) {
ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_PLAYER.getMessage(), dFaction);
event.setCancelled(true);
} else if (rFaction != null && rFaction.getRelation(dFaction).isProtected()) {
if (plugin.getFConfig().isTerritoryProtectionEnabled() && (!plugin.getFConfig().isCapitalProtectionEnabled()
|| rFaction.getCapital().equals(plugin.getBoard().getByLocation(eDefender.getLocation())))) {
ParsingUtil.sendMessage(attacker, FMessage.PROTECTION_CANNOT_ATTACK_FACTION.getMessage(), rFaction);
event.setCancelled(true);
} else if (plugin.getFConfig().getTerritoryShield() != 0) {
event.setDamage(event.getDamage() * plugin.getFConfig().getTerritoryShield());
}
}
}
示例3: getEntities
import org.bukkit.entity.Entity; //導入依賴的package包/類
public static List<Entity> getEntities(Location location, double radius) {
List<Entity> entities = new ArrayList<Entity>();
World world = location.getWorld();
// Find chunck by coordinates
int smallX = MathHelper.floor((location.getX() - radius) / 16.0D);
int bigX = MathHelper.floor((location.getX() + radius) / 16.0D);
int smallZ = MathHelper.floor((location.getZ() - radius) / 16.0D);
int bigZ = MathHelper.floor((location.getZ() + radius) / 16.0D);
for (int x = smallX; x <= bigX; x++)
for (int z = smallZ; z <= bigZ; z++)
if (world.isChunkLoaded(x, z)) entities.addAll(Arrays.asList(world.getChunkAt(x, z).getEntities()));
Iterator<Entity> entityIterator = entities.iterator();
while (entityIterator.hasNext())
if (entityIterator.next().getLocation().distanceSquared(location) > radius * radius) entityIterator.remove();
return entities;
}
示例4: getNearbyEnemies
import org.bukkit.entity.Entity; //導入依賴的package包/類
/**
* Gets the amount of enemies nearby a {@link Player}.
*
* @param player
* the {@link Player} to get for
* @param distance
* the radius to get within
* @return the amount of players within enemy distance
*/
public int getNearbyEnemies(Player player, int distance) {
FactionManager factionManager = plugin.getFactionManager();
Faction playerFaction = factionManager.getPlayerFaction(player.getUniqueId());
int count = 0;
Collection<Entity> nearby = player.getNearbyEntities(distance, distance, distance);
for (Entity entity : nearby) {
if (entity instanceof Player) {
Player target = (Player) entity;
// If the nearby player or sender cannot see each-other, continue.
if (!target.canSee(player) || !player.canSee(target)) {
continue;
}
if (playerFaction == null || factionManager.getPlayerFaction(target) != playerFaction) {
count++;
}
}
}
return count;
}
示例5: ProjectileDefinitionImpl
import org.bukkit.entity.Entity; //導入依賴的package包/類
public ProjectileDefinitionImpl(@Nullable String name,
@Nullable Double damage,
double velocity,
ClickAction clickAction,
Class<? extends Entity> entity,
List<PotionEffect> potion,
Filter destroyFilter,
Duration coolDown,
boolean throwable) {
this.name = name;
this.damage = damage;
this.velocity = velocity;
this.clickAction = clickAction;
this.projectile = entity;
this.potion = potion;
this.destroyFilter = destroyFilter;
this.coolDown = coolDown;
this.throwable = throwable;
}
示例6: pass
import org.bukkit.entity.Entity; //導入依賴的package包/類
/**
* Passes the ball with the given strength parameters
*
* @param entity entity
* @param horizontalStrength horizontalStrength
* @param verticalStrength verticalStrength
*/
@Override
public void pass(Entity entity, double horizontalStrength, double verticalStrength) {
BallKickEvent event = null;
if (entity instanceof Player) {
event = new BallKickEvent((Player) entity, this);
Bukkit.getPluginManager().callEvent(new BallKickEvent((Player) entity, this));
}
if (event == null || !event.isCancelled()) {
this.startVector = this.slime.getSpigotEntity().getLocation().toVector().subtract(entity.getLocation().toVector()).normalize().multiply(horizontalStrength * 0.8);
this.startVector.setY(verticalStrength * 0.5);
try {
this.slime.getSpigotEntity().setVelocity(this.startVector.clone());
} catch (final IllegalArgumentException ex) {
}
if (this.isRotating)
this.getSpigotEntity().setHeadPose(new EulerAngle(1, this.getSpigotEntity().getHeadPose().getY(), this.getSpigotEntity().getHeadPose().getZ()));
this.rvalue = this.random.nextInt(5) + 9;
this.jumps = this.random.nextInt(5) + 5;
}
}
示例7: walkToPlayer
import org.bukkit.entity.Entity; //導入依賴的package包/類
public static void walkToPlayer(Entity e, Player p) {
// Tamed animals already handle their own following
if (e instanceof Tameable) {
if (((Tameable) e).isTamed()) {
return;
}
}
if (e.getPassenger() instanceof Player) {
return;
}
// Moving the dragon is too buggy
if (e instanceof EnderDragon) {
return;
}
// Once this is set we can't unset it.
//((Creature)e).setTarget(p);
// If the pet is too far just teleport instead of attempt navigation
if (e.getLocation().distance(p.getLocation()) > 20) {
e.teleport(p);
} else {
Navigation n = ((CraftLivingEntity) e).getHandle().getNavigation();
n.a(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 0.30f);
}
}
示例8: removeBlock
import org.bukkit.entity.Entity; //導入依賴的package包/類
public void removeBlock(BlockBreakEvent e) {
for (Entity en : e.getBlock().getWorld().getEntities()) {
if (en.getCustomName() != null && en.getCustomName().equals(getName()) && en.getLocation().add(-0.5, 0, -0.5).equals(e.getBlock().getLocation())) {
en.remove();
en.getWorld().getBlockAt(en.getLocation().add(-0.5, 0, -0.5)).setType(Material.AIR);
ItemStack block = new ItemStack(Material.MONSTER_EGG, 1);
ItemMeta bmeta = block.getItemMeta();
bmeta.setDisplayName(name);
block.setItemMeta(bmeta);
if (e.getPlayer() != null && e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
e.getPlayer().getInventory().addItem(block);
} else {
e.getBlock().getWorld().dropItemNaturally(en.getLocation().add(-0.5, 0, -0.5), block);
}
}
}
//}
}
示例9: MatchEntityState
import org.bukkit.entity.Entity; //導入依賴的package包/類
protected MatchEntityState(Match match, Class<? extends Entity> entityClass, UUID uuid, EntityLocation location, @Nullable String customName) {
this.uuid = checkNotNull(uuid);
this.match = checkNotNull(match);
this.entityClass = checkNotNull(entityClass);
this.location = checkNotNull(location);
this.customName = customName;
EntityType type = null;
for(EntityType t : EntityType.values()) {
if(t.getEntityClass().isAssignableFrom(entityClass)) {
type = t;
break;
}
}
checkArgument(type != null, "Unknown entity class " + entityClass);
this.entityType = type;
}
示例10: getPlayers
import org.bukkit.entity.Entity; //導入依賴的package包/類
public List<Player> getPlayers() {
List<Player> list = new ArrayList<Player>();
for (Object o : world.loadedEntityList) {
if (o instanceof net.minecraft.entity.Entity) {
net.minecraft.entity.Entity mcEnt = (net.minecraft.entity.Entity) o;
Entity bukkitEntity = mcEnt.getBukkitEntity();
if ((bukkitEntity != null) && (bukkitEntity instanceof Player)) {
list.add((Player) bukkitEntity);
}
}
}
return list;
}
示例11: getEntity
import org.bukkit.entity.Entity; //導入依賴的package包/類
@Nullable
private static Entity getEntity(String input, @Nullable CommandSender sender) throws InputException {
Entity target;
if (sender instanceof Player) {
if (input.equalsIgnoreCase("that")) {
target = PlatformUtil.getEntityPlayerLookingAt((Player) sender, 25, 1.5D);
if (target != null) {
return target;
}
} else if (input.equalsIgnoreCase("me")) {
return ((Player) sender);
}
}
Location loc = getLocation(input, sender);
return PlatformUtil.getEntityNearestTo(loc, 25, 1.5D);
}
示例12: get
import org.bukkit.entity.Entity; //導入依賴的package包/類
/**
* Gets a {@link MetadataMap} for the given object, if one already exists and has
* been cached in this registry.
*
* A map will only be returned if the object is an instance of
* {@link Player}, {@link UUID}, {@link Entity}, {@link Block} or {@link World}.
*
* @param obj the object
* @return a metadata map
*/
@Nonnull
public static Optional<MetadataMap> get(@Nonnull Object obj) {
Preconditions.checkNotNull(obj, "obj");
if (obj instanceof Player) {
return getForPlayer(((Player) obj));
} else if (obj instanceof UUID) {
return getForPlayer(((UUID) obj));
} else if (obj instanceof Entity) {
return getForEntity(((Entity) obj));
} else if (obj instanceof Block) {
return getForBlock(((Block) obj));
} else if (obj instanceof World) {
return getForWorld(((World) obj));
} else {
throw new IllegalArgumentException("Unknown object type: " + obj.getClass());
}
}
示例13: 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);
}
}
}
示例14: onEntityDeath
import org.bukkit.entity.Entity; //導入依賴的package包/類
/**
* Utilizes a random chance to either spawn a skeleton with gold armor or resources.
*
* @param event The event
*/
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Sheep) {
double chance = Math.random();
if (0.25 > chance) {
Skeleton skeleton = entity.getWorld().spawn(entity.getLocation(), Skeleton.class);
skeleton.getEquipment().setArmorContents(
new ItemStack[]{
new ItemStack(Material.GOLD_HELMET),
new ItemStack(Material.GOLD_CHESTPLATE),
new ItemStack(Material.GOLD_LEGGINGS),
new ItemStack(Material.GOLD_BOOTS)
}
);
} else if (0.5 > chance) {
event.getDrops().add(new ItemStack(Material.IRON_INGOT));
} else if (0.75 > chance) {
event.getDrops().add(new ItemStack(Material.GOLD_INGOT));
} else {
event.getDrops().add(new ItemStack(Material.DIAMOND));
}
}
}
示例15: handleSlowdown
import org.bukkit.entity.Entity; //導入依賴的package包/類
private void handleSlowdown(Player player, Rune rune) {
new BukkitRunnable() {
int iterations = 0;
public void run() {
if(!player.isOnline() || iterations / 2 >= rune.getDuration()) {
finish(player, true);
this.cancel();
return;
}
for(Entity entity : player.getNearbyEntities(3D, 3D, 3D)) {
if(!(entity instanceof Player)) {
continue;
}
Player target = (Player) entity;
if(Utility.canAttack(player, target)) {
target.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 0));
}
}
iterations++;
}
}.runTaskTimer(plugin, 0L, 10L);
}