Java源码示例:org.bukkit.entity.Creature
示例1
private void hidePlayer(Player p) {
activePlayers.add(p);
//Clear all mob targets
Collection<Entity> nearbyEntities = p.getWorld().getNearbyEntities(p.getLocation(), 64, 64, 64);
for (Entity ent : nearbyEntities) {
if (ent instanceof Creature) {
if (p.equals(((Creature) ent).getTarget())) {
((Creature) ent).setTarget(null);
}
}
}
//Hide from all players
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
if (!p.equals(player)) {
if (!player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) player.hidePlayer(MineTinker.getPlugin(), p);
}
}
}
示例2
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
final LivingEntity target = delta == null ? null : (LivingEntity) delta[0];
for (final LivingEntity entity : getExpr().getArray(e)) {
if (getTime() >= 0 && e instanceof EntityTargetEvent && entity.equals(((EntityTargetEvent) e).getEntity()) && !Delay.isDelayed(e)) {
((EntityTargetEvent) e).setTarget(target);
} else {
if (entity instanceof Creature)
((Creature) entity).setTarget(target);
}
}
} else {
super.change(e, delta, mode);
}
}
示例3
/**
* Gets an entity's target.
*
* @param entity The entity to get the target of
* @param type Can be null for any entity
* @return The entity's target
*/
@SuppressWarnings("unchecked")
@Nullable
public static <T extends Entity> T getTarget(final LivingEntity entity, @Nullable final EntityData<T> type) {
if (entity instanceof Creature) {
return ((Creature) entity).getTarget() == null || type != null && !type.isInstance(((Creature) entity).getTarget()) ? null : (T) ((Creature) entity).getTarget();
}
T target = null;
double targetDistanceSquared = 0;
final double radiusSquared = 1;
final Vector l = entity.getEyeLocation().toVector(), n = entity.getLocation().getDirection().normalize();
final double cos45 = Math.cos(Math.PI / 4);
for (final T other : type == null ? (List<T>) entity.getWorld().getEntities() : entity.getWorld().getEntitiesByClass(type.getType())) {
if (other == null || other == entity || type != null && !type.isInstance(other))
continue;
if (target == null || targetDistanceSquared > other.getLocation().distanceSquared(entity.getLocation())) {
final Vector t = other.getLocation().add(0, 1, 0).toVector().subtract(l);
if (n.clone().crossProduct(t).lengthSquared() < radiusSquared && t.normalize().dot(n) >= cos45) {
target = other;
targetDistanceSquared = target.getLocation().distanceSquared(entity.getLocation());
}
}
}
return target;
}
示例4
/**
* Set a target for the {@link com.dsh105.echopet.api.pet.Pet} to attack
*
* @param pet the attacker
* @param target the {@link org.bukkit.entity.LivingEntity} for the {@link com.dsh105.echopet.api.pet.Pet} to
* attack
*/
public void setAttackTarget(IPet pet, LivingEntity target) {
Preconditions.checkNotNull(pet, "Null pet");
Preconditions.checkNotNull(target, "Null target");
Preconditions.checkArgument(pet.getCraftPet() instanceof Creature, "Pet is a %s, not a Creature", pet.getPetType());
if (pet.getEntityPet().getPetGoalSelector().getGoal("Attack") != null) {
((Creature) pet.getCraftPet()).setTarget(target);
}
}
示例5
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);
Set<?> goals = (Set<?>) b.get(this.goalSelector);
goals.clear(); // Clears the goals
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.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, 1D, false)); // Add bedwars player
// goal
try {
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
TargetReason.TARGET_ATTACKED_ENTITY, false);
} catch (Exception ex) {
// newer spigot builds
if (ex instanceof NoSuchMethodException) {
BedwarsRel.getInstance().getBugsnag().notify(ex);
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
}
}
((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
示例6
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);
Set<?> goals = (Set<?>) b.get(this.goalSelector);
goals.clear(); // Clears the goals
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.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, 1D, false)); // Add bedwars player
// goal
try {
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
TargetReason.TARGET_ATTACKED_ENTITY, false);
} catch (Exception ex) {
// newer spigot builds
if (ex instanceof NoSuchMethodException) {
BedwarsRel.getInstance().getBugsnag().notify(ex);
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
}
}
((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
示例7
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);
}
示例8
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);
Set<?> goals = (Set<?>) b.get(this.goalSelector);
goals.clear(); // Clears the goals
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.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, 1D, false)); // Add bedwars player
// goal
try {
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
TargetReason.TARGET_ATTACKED_ENTITY, false);
} catch (Exception ex) {
// newer spigot builds
if (ex instanceof NoSuchMethodException) {
BedwarsRel.getInstance().getBugsnag().notify(ex);
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
}
}
((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
示例9
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);
Set<?> goals = (Set<?>) b.get(this.goalSelector);
goals.clear(); // Clears the goals
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.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, 1D, false)); // Add bedwars player
// goal
try {
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
TargetReason.TARGET_ATTACKED_ENTITY, false);
} catch (Exception ex) {
// newer spigot builds
if (ex instanceof NoSuchMethodException) {
BedwarsRel.getInstance().getBugsnag().notify(ex);
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
}
}
((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
示例10
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.FOLLOW_RANGE).setValue(128D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.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);
}
示例11
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);
}
示例12
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);
Set<?> goals = (Set<?>) b.get(this.goalSelector);
goals.clear(); // Clears the goals
this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
.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, 1D, false)); // Add bedwars player
// goal
try {
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
TargetReason.TARGET_ATTACKED_ENTITY, false);
} catch (Exception ex) {
// newer spigot builds
if (ex instanceof NoSuchMethodException) {
BedwarsRel.getInstance().getBugsnag().notify(ex);
this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
}
}
((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
示例13
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
if ((!killAnimalsEnabled && !killMonstersEnabled)
|| !plugin.getWorldManager().isSkyAssociatedWorld(event.getDamager().getWorld())) {
return;
}
if (!(event.getEntity() instanceof Creature)) {
return;
}
if (event.getDamager() instanceof Player
&& !plugin.playerIsOnIsland((Player)event.getDamager())) {
if (event.getDamager().hasPermission("usb.mod.bypassprotection")) {
return;
}
cancelMobDamage(event);
} else if (event.getDamager() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
if (!(shooter instanceof Player)) {
return;
}
Player player = (Player) shooter;
if (player.hasPermission("usb.mod.bypassprotection") || plugin.playerIsOnIsland(player)) {
return;
}
cancelMobDamage(event);
}
}
示例14
private Boolean evaluate(Event event) {
if (!(event instanceof EntityDamageEvent)) {
switch (cause) {
case WORLD:
return event instanceof WorldEvent;
case LIVING:
return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof LivingEntity;
case MOB:
return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof Creature;
case PLAYER:
return event instanceof PlayerEvent || event instanceof BlockPlaceEvent || event instanceof BlockBreakEvent;
case PUNCH:
return event instanceof PlayerInteractEvent
&& ((PlayerInteractEvent) event).getAction().equals(Action.LEFT_CLICK_BLOCK);
case TRAMPLE:
return event instanceof PlayerMoveEvent;
case MINE:
return event instanceof BlockBreakEvent;
case EXPLOSION:
return event instanceof EntityExplodeEvent;
}
} else {
EntityDamageEvent.DamageCause damageCause = ((EntityDamageEvent) event).getCause();
switch (cause) {
case MELEE:
return damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK);
case PROJECTILE:
return damageCause.equals(EntityDamageEvent.DamageCause.PROJECTILE);
case POTION:
return damageCause.equals(EntityDamageEvent.DamageCause.MAGIC)
|| damageCause.equals(EntityDamageEvent.DamageCause.POISON)
|| damageCause.equals(EntityDamageEvent.DamageCause.WITHER)
|| damageCause.equals(EntityDamageEvent.DamageCause.DRAGON_BREATH);
case EXPLOSION:
return damageCause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
|| damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
case COMBUSTION:
return damageCause.equals(EntityDamageEvent.DamageCause.FIRE)
|| damageCause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)
|| damageCause.equals(EntityDamageEvent.DamageCause.MELTING)
|| damageCause.equals(EntityDamageEvent.DamageCause.LAVA)
|| damageCause.equals(EntityDamageEvent.DamageCause.HOT_FLOOR);
case FALL:
return damageCause.equals(EntityDamageEvent.DamageCause.FALL);
case GRAVITY:
return damageCause.equals(EntityDamageEvent.DamageCause.FALL)
|| damageCause.equals(EntityDamageEvent.DamageCause.VOID);
case VOID:
return damageCause.equals(EntityDamageEvent.DamageCause.VOID);
case SQUASH:
return damageCause.equals(EntityDamageEvent.DamageCause.FALLING_BLOCK);
case SUFFOCATION:
return damageCause.equals(EntityDamageEvent.DamageCause.SUFFOCATION);
case DROWNING:
return damageCause.equals(EntityDamageEvent.DamageCause.DROWNING);
case STARVATION:
return damageCause.equals(EntityDamageEvent.DamageCause.STARVATION);
case LIGHTNING:
return damageCause.equals(EntityDamageEvent.DamageCause.LIGHTNING);
case CACTUS:
return damageCause.equals(EntityDamageEvent.DamageCause.CONTACT);
case THORNS:
return damageCause.equals(EntityDamageEvent.DamageCause.THORNS);
}
}
return null;
}
示例15
@Override
public Creature getCraftPet() {
return this.getEntityPet().getBukkitEntity();
}
示例16
/**
* Get the {@link org.bukkit.entity.LivingEntity} that a {@link com.dsh105.echopet.api.pet.Pet} is targeting
*
* @param pet the attacker
* @return {@link org.bukkit.entity.LivingEntity} being attacked, null if none
*/
public LivingEntity getAttackTarget(IPet pet) {
Preconditions.checkNotNull(pet, "Null pet");
Preconditions.checkArgument(pet.getCraftPet() instanceof Creature, "Pet is a %s, not a Creature", pet.getPetType());
return ((Creature) pet.getCraftPet()).getTarget();
}
示例17
public Creature getBukkitEntity();
示例18
public Creature getCraftPet();