All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.item.enchantment.sideeffect.SideEffectCombust Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.item.enchantment.sideeffect;

import cn.nukkit.Server;
import cn.nukkit.api.DeprecationDetails;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.entity.Entity;
import cn.nukkit.event.entity.EntityCombustByEntityEvent;
import cn.nukkit.event.entity.EntityDamageEvent;
import lombok.SneakyThrows;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

@PowerNukkitOnly
@Since("1.5.1.0-PN")
public class SideEffectCombust implements SideEffect {
    private int duration;

    @PowerNukkitOnly
    @Since("1.5.1.0-PN")
    public SideEffectCombust(int duration) {
        this.duration = duration;
    }

    @Since("1.5.1.0-PN")
    @PowerNukkitOnly
    @Override
    public void doPreHealthChange(@Nonnull Entity entity, @Nonnull EntityDamageEvent event, @Nullable Entity attacker) {
        EntityCombustByEntityEvent ev = new EntityCombustByEntityEvent(attacker, entity, duration);
        Server.getInstance().getPluginManager().callEvent(ev);

        if (!ev.isCancelled()) {
            entity.setOnFire(ev.getDuration());
        }
    }

    @Since("1.5.1.0-PN")
    @PowerNukkitOnly
    public int getDuration() {
        return duration;
    }

    @Since("1.5.1.0-PN")
    @PowerNukkitOnly
    public void setDuration(int duration) {
        this.duration = duration;
    }

    @Deprecated
    @DeprecationDetails(since = "FUTURE", reason = "clone have problems when defined in an interface", by = "PowerNukkit",
        replaceWith = "cloneSideEffect")
    @Since("1.5.1.0-PN")
    @SneakyThrows
    @Override
    @Nonnull
    public SideEffect clone() {
        return (SideEffect) super.clone();
    }

    @Since("FUTURE")
    @PowerNukkitOnly
    @SneakyThrows
    @Override
    @Nonnull
    public SideEffect cloneSideEffect() {
        return (SideEffect) super.clone();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy