Ricerca…


introduzione

Tutti gli eventi entità estende EntityEvent, la superclasse di EntityEvents.

Tutti gli EntityEvents noti sono disponibili di seguito e saranno trattati in questa documentazione.

Evento EntityDamage

L'evento EntityDamage viene generato quando un'entità è danneggiata.

EntityDamageEvent

@EventHandler
public void onEntityDamage(EntityDamageEvent e) {
    DamageCause cause = e.getCause();    //Get the event DamageCause
    double rawDamage = e.getDamage();    //Returns the damage before any calculation
    double damageModified = e.getDamage(DamageModifier.X);     //Returns the damage that would be caused with the specified modifier
    double finalDamage = e.getFinalDamage();    //Gets the final damage of this event, with all the calculations included

    e.setCancelled(boolean x);    //If for any reasons you want the event to not happen, you can cancel it
    e.setDamage(double damage);    //You can change the full damage the event will cause
    e.setDamage(DamageModifier modifier, double damage);    //Changes the damage considering any possible modifier
}

La maggior parte delle volte, EntityDamageEvent non verrà utilizzato. Verrà utilizzata una sottoclasse, ad esempio EntityDamageByEntityEvent o EntityDamageByBlockEvent . Entrambi possono essere visti sotto.


EntityDamageByEntityEvent

@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
    //Retrieving the Entity that dealt damage
    Entity damageDealer = e.getDamager();

    //Retrieving the Entity that took damage
    Entity damageTaker = e.getEntity();

    //Retrieving the cause of the damage
    DamageCause cause = e.getDamageCause();

    //damage is the double value of the damage before all the resistances and modifiers have been applied
    double damage = e.getDamage();

    //FinalDamage is the double value of the damage after all the resistances and modifiers have been applied
    double finalDamage = e.getFinalDamage();

   //You can also set the raw damage (before modifiers) for the event to a different value
   e.setDamage(20.0);
}

EntityDamageByBlockEvent

Una semplice estensione a EntityDamageEvent, ma con un metodo diverso:

Block b = event.getDamager();    //Returns the block that dealt damage to the entity

EntityEvent (Superclasse)

Le sottoclasse conosciute per Eventi entità sono:

Sotto-Classi Sotto-Classi Sotto-Classi
CreatureSpawnEvent CreeperPowerEvent EntityChangeBlockEvent
EntityCombustEvent EntityCreatePortalEvent EntityDamageEvent
EntityDeathEvent EntityExplodeEvent EntityInteractEvent
EntityPortalEnterEvent EntityRegainHealthEvent EntityShootBowEvent
EntityTameEvent EntityTargetEvent EntityTeleportEvent
EntityUnleashEvent ExplosionPrimeEvent FoodLevelChangeEvent
HorseJumpEvent ItemDespawnEvent ItemSpawnEvent
PigZapEvent ProjectileHitEvent ProjectileLaunchEvent
SheepDyeWoolEvent SheepRegrowWoolEvent SlimeSplitEvent


Oltre a questo, tutte le sottoclassi ereditano i seguenti metodi:

Entity getEntity();            //Entity who is involved in this event
EntityType getEntityType();    //EntityType of the Entity involved in this event


Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow