Minestom/src/main/java/net/minestom/server/potion/Potion.java

59 lines
2.0 KiB
Java
Raw Normal View History

2020-12-31 00:12:03 +01:00
package net.minestom.server.potion;
import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.play.EntityEffectPacket;
import net.minestom.server.network.packet.server.play.RemoveEntityEffectPacket;
import org.jetbrains.annotations.NotNull;
public class Potion {
public PotionEffect effect;
public byte amplifier;
public int duration;
public boolean ambient;
public boolean particles;
public boolean icon;
public Potion(PotionEffect effect, byte amplifier, int duration) {
this(effect, amplifier, duration, true, true, false);
}
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles) {
this(effect, amplifier, duration, particles, true, false);
}
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles, boolean icon) {
this(effect, amplifier, duration, particles, icon, false);
}
public Potion(PotionEffect effect, byte amplifier, int duration, boolean particles, boolean icon, boolean ambient) {
this.effect = effect;
this.amplifier = amplifier;
this.duration = duration;
this.particles = particles;
this.icon = icon;
this.ambient = ambient;
}
public byte getFlags() {
byte computed = 0x00;
if (ambient) computed = (byte)(computed | 0x01);
if (particles) computed = (byte)(computed | 0x02);
if (icon) computed = (byte)(computed | 0x04);
return computed;
}
public void sendAddPacket(@NotNull Player player) {
EntityEffectPacket eep = new EntityEffectPacket();
eep.entityId = player.getEntityId();
eep.potion = this;
player.sendPacketToViewersAndSelf(eep);
}
public void sendRemovePacket(@NotNull Player player) {
RemoveEntityEffectPacket reep = new RemoveEntityEffectPacket();
reep.entityId = player.getEntityId();
reep.effect = effect;
player.sendPacketToViewersAndSelf(reep);
}
}