Java Code Examples for cn.nukkit.entity.Entity#hasEffect()

The following examples show how to use cn.nukkit.entity.Entity#hasEffect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockLava.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    entity.highestPosition -= (entity.highestPosition - entity.y) * 0.5;

    // Always setting the duration to 15 seconds? TODO
    EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15);
    Server.getInstance().getPluginManager().callEvent(ev);
    if (!ev.isCancelled()
            // Making sure the entity is actually alive and not invulnerable.
            && entity.isAlive()
            && entity.noDamageTicks == 0) {
        entity.setOnFire(ev.getDuration());
    }

    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.LAVA, 4));
    }

    super.onEntityCollide(entity);
}
 
Example 2
Source File: BlockLava.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    entity.highestPosition -= (entity.highestPosition - entity.y) * 0.5;
    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.LAVA, 4));
    }

    // Always setting the duration to 15 seconds? TODO
    EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15);
    Server.getInstance().getPluginManager().callEvent(ev);
    if (!ev.isCancelled()
            // Making sure the entity is acutally alive and not invulnerable.
            && entity.isAlive()
            && entity.noDamageTicks == 0) {
        entity.setOnFire(ev.getDuration());
    }

    super.onEntityCollide(entity);
}
 
Example 3
Source File: BlockLava.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    entity.highestPosition -= (entity.highestPosition - entity.y) * 0.5;
    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.LAVA, 4));
    }

    EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 15);
    Server.getInstance().getPluginManager().callEvent(ev);
    if (!ev.isCancelled()) {
        entity.setOnFire(ev.getDuration());
    }

    super.onEntityCollide(entity);
}
 
Example 4
Source File: BlockFire.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1));
    }

    EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8);
    if (entity instanceof EntityArrow) {
        ev.setCancelled();
    }
    Server.getInstance().getPluginManager().callEvent(ev);
    if (!ev.isCancelled() && entity instanceof Player && !((Player) entity).isCreative()) {
        entity.setOnFire(ev.getDuration());
    }
}
 
Example 5
Source File: EntityDamageEvent.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public EntityDamageEvent(Entity entity, DamageCause cause, Map<DamageModifier, Float> modifiers) {
    this.entity = entity;
    this.cause = cause;
    this.modifiers = modifiers;

    this.originals = this.modifiers;

    if (!this.modifiers.containsKey(DamageModifier.BASE)) {
        throw new EventException("BASE Damage modifier missing");
    }

    if (entity.hasEffect(Effect.DAMAGE_RESISTANCE)) {
        this.setDamage((float) -(this.getDamage(DamageModifier.BASE) * 0.20 * (entity.getEffect(Effect.DAMAGE_RESISTANCE).getAmplifier() + 1)), DamageModifier.RESISTANCE);
    }
}
 
Example 6
Source File: EntityDamageByEntityEvent.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
protected void addAttackerModifiers(Entity damager) {
    if (damager.hasEffect(Effect.STRENGTH)) {
        this.setDamage((float) (this.getDamage(DamageModifier.BASE) * 0.3 * (damager.getEffect(Effect.STRENGTH).getAmplifier() + 1)), DamageModifier.STRENGTH);
    }

    if (damager.hasEffect(Effect.WEAKNESS)) {
        this.setDamage(-(float) (this.getDamage(DamageModifier.BASE) * 0.2 * (damager.getEffect(Effect.WEAKNESS).getAmplifier() + 1)), DamageModifier.WEAKNESS);
    }
}
 
Example 7
Source File: BlockMagma.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        if (entity instanceof Player) {
            Player p = (Player) entity;
            if (!p.isCreative() && !p.isSpectator() && !p.isSneaking()) {
                entity.attack(new EntityDamageByBlockEvent(this, entity, EntityDamageEvent.DamageCause.LAVA, 1));
            }
        } else {
            entity.attack(new EntityDamageByBlockEvent(this, entity, EntityDamageEvent.DamageCause.LAVA, 1));
        }
    }
}
 
Example 8
Source File: BlockFire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1));
    }

    EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8);
    if (entity instanceof EntityArrow) {
        ev.setCancelled();
    }
    Server.getInstance().getPluginManager().callEvent(ev);
    if (!ev.isCancelled() && entity.isAlive() && entity.noDamageTicks == 0) {
        entity.setOnFire(ev.getDuration());
    }
}
 
Example 9
Source File: EntityDamageEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public EntityDamageEvent(Entity entity, DamageCause cause, Map<DamageModifier, Float> modifiers) {
    this.entity = entity;
    this.cause = cause;
    this.modifiers = new EnumMap<>(modifiers);

    this.originals = ImmutableMap.copyOf(this.modifiers);

    if (!this.modifiers.containsKey(DamageModifier.BASE)) {
        throw new EventException("BASE Damage modifier missing");
    }

    if (entity.hasEffect(Effect.DAMAGE_RESISTANCE)) {
        this.setDamage((float) -(this.getDamage(DamageModifier.BASE) * 0.20 * (entity.getEffect(Effect.DAMAGE_RESISTANCE).getAmplifier() + 1)), DamageModifier.RESISTANCE);
    }
}
 
Example 10
Source File: EntityDamageByEntityEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void addAttackerModifiers(Entity damager) {
    if (damager.hasEffect(Effect.STRENGTH)) {
        this.setDamage((float) (this.getDamage(DamageModifier.BASE) * 0.3 * (damager.getEffect(Effect.STRENGTH).getAmplifier() + 1)), DamageModifier.STRENGTH);
    }

    if (damager.hasEffect(Effect.WEAKNESS)) {
        this.setDamage(-(float) (this.getDamage(DamageModifier.BASE) * 0.2 * (damager.getEffect(Effect.WEAKNESS).getAmplifier() + 1)), DamageModifier.WEAKNESS);
    }
}
 
Example 11
Source File: BlockFire.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onEntityCollide(Entity entity) {
    if (!entity.hasEffect(Effect.FIRE_RESISTANCE)) {
        entity.attack(new EntityDamageByBlockEvent(this, entity, DamageCause.FIRE, 1));
    }

    EntityCombustByBlockEvent ev = new EntityCombustByBlockEvent(this, entity, 8);
    if (entity instanceof EntityArrow) {
        ev.setCancelled();
    }
    Server.getInstance().getPluginManager().callEvent(ev);
    if (!ev.isCancelled() && entity instanceof Player && !((Player) entity).isCreative()) {
        entity.setOnFire(ev.getDuration());
    }
}
 
Example 12
Source File: EntityDamageEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public EntityDamageEvent(Entity entity, DamageCause cause, Map<DamageModifier, Float> modifiers) {
    this.entity = entity;
    this.cause = cause;
    this.modifiers = modifiers;

    this.originals = this.modifiers;

    if (!this.modifiers.containsKey(DamageModifier.BASE)) {
        throw new EventException("BASE Damage modifier missing");
    }

    if (entity.hasEffect(Effect.DAMAGE_RESISTANCE)) {
        this.setDamage((float) -(this.getDamage(DamageModifier.BASE) * 0.20 * (entity.getEffect(Effect.DAMAGE_RESISTANCE).getAmplifier() + 1)), DamageModifier.RESISTANCE);
    }
}
 
Example 13
Source File: EntityDamageByEntityEvent.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void addAttackerModifiers(Entity damager) {
    if (damager.hasEffect(Effect.STRENGTH)) {
        this.setDamage((float) (this.getDamage(DamageModifier.BASE) * 0.3 * (damager.getEffect(Effect.STRENGTH).getAmplifier() + 1)), DamageModifier.STRENGTH);
    }

    if (damager.hasEffect(Effect.WEAKNESS)) {
        this.setDamage(-(float) (this.getDamage(DamageModifier.BASE) * 0.2 * (damager.getEffect(Effect.WEAKNESS).getAmplifier() + 1)), DamageModifier.WEAKNESS);
    }
}