下面列出了org.bukkit.entity.Entity#getFireTicks ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean effect(Event event, Player player) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
Entity entity = e.getEntity();
if(e.getDamager() == player && entity.getFireTicks() > 0) {
e.setDamage(damageMultiplier * e.getDamage());
entity.getWorld().playEffect(entity.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
EffectManager.playSound(entity.getLocation(), "BLOCK_ANVIL_LAND", 1f, 0.001f);
return true;
}
return false;
}
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
Entity projectile = event.getDamager();
if (projectile.hasMetadata("customProjectile")) {
// If the custom projectile replaced an arrow, recreate some effects specific to arrows
if (projectile.hasMetadata("damage")) {
boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
int knockback = projectile.getMetadata("knockback").get(0).asInt();
double damage = projectile.getMetadata("damage").get(0).asDouble();
double speed = projectile.getVelocity().length();
// Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
if (critical) {
finalDamage += match.getRandom().nextInt(finalDamage / 2 + 2);
}
event.setDamage(finalDamage);
// Flame arrows - target burns for 5 seconds always
if (projectile.getFireTicks() > 0) {
event.getEntity().setFireTicks(100);
}
// Reproduce the knockback calculation for punch bows
if (knockback > 0) {
Vector projectileVelocity = projectile.getVelocity();
double horizontalSpeed =
Math.sqrt(
projectileVelocity.getX() * projectileVelocity.getX()
+ projectileVelocity.getZ() * projectileVelocity.getZ());
Vector velocity = event.getEntity().getVelocity();
velocity.setX(
velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
velocity.setY(velocity.getY() + 0.1);
velocity.setZ(
velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
event.getEntity().setVelocity(velocity);
}
// If the projectile is not an arrow, play an impact sound.
if (event.getEntity() instanceof Player
&& (projectile instanceof Projectile && !(projectile instanceof Arrow))) {
Projectile customProjectile = (Projectile) projectile;
if (customProjectile.getShooter() instanceof Player) {
Player bukkitShooter = (Player) customProjectile.getShooter();
MatchPlayer shooter = match.getPlayer(bukkitShooter);
if (shooter != null && event.getEntity() != null) {
shooter.playSound(PROJECTILE_SOUND);
}
}
}
}
// Apply any potion effects attached to the projectile
if (event.getEntity() instanceof LivingEntity) {
for (PotionEffect potionEffect : this.potionEffects) {
((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
}
}
}
}
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
Entity projectile = event.getDamager();
if(projectile.hasMetadata("customProjectile")) {
// If the custom projectile replaced an arrow, recreate some effects specific to arrows
if(projectile.hasMetadata("damage")) {
boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
int knockback = projectile.getMetadata("knockback").get(0).asInt();
double damage = projectile.getMetadata("damage").get(0).asDouble();
double speed = projectile.getVelocity().length();
// Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
if(critical) {
finalDamage += random.nextInt(finalDamage / 2 + 2);
}
event.setDamage(finalDamage);
// Flame arrows - target burns for 5 seconds always
if(projectile.getFireTicks() > 0) {
event.getEntity().setFireTicks(100);
}
// Reproduce the knockback calculation for punch bows
if(knockback > 0) {
Vector projectileVelocity = projectile.getVelocity();
double horizontalSpeed = Math.sqrt(projectileVelocity.getX() * projectileVelocity.getX() +
projectileVelocity.getZ() * projectileVelocity.getZ());
Vector velocity = event.getEntity().getVelocity();
velocity.setX(velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
velocity.setY(velocity.getY() + 0.1);
velocity.setZ(velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
event.getEntity().setVelocity(velocity);
}
}
// Apply any potion effects attached to the projectile
if(event.getEntity() instanceof LivingEntity) {
for(PotionEffect potionEffect : this.potionEffects) {
((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
}
}
}
}
@Override
public boolean check(final Entity e) {
return e.getFireTicks() > 0;
}