use of org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutRemovePotionEffect in project LanternServer by LanternPowered.
the class LivingEntityProtocol method update.
@Override
protected void update(EntityProtocolUpdateContext context) {
super.update(context);
final List<PotionEffect> potionEffects = this.entity.get(Keys.POTION_EFFECTS).orElse(Collections.emptyList());
final Map<PotionEffectType, PotionEffect> potionEffectMap = new HashMap<>();
for (PotionEffect potionEffect : potionEffects) {
if (potionEffect.getDuration() > 0) {
potionEffectMap.put(potionEffect.getType(), potionEffect);
}
}
final long time = LanternGame.currentTimeTicks();
if (this.lastPotionSendTime == -1L) {
potionEffects.forEach(potionEffect -> context.sendToAll(() -> createAddMessage(potionEffect)));
} else {
final int delay = (int) (time - this.lastPotionSendTime);
for (PotionEffect potionEffect : potionEffectMap.values()) {
// noinspection ConstantConditions
final PotionEffect oldEntry = this.lastPotionEffects.remove(potionEffect.getType());
if (oldEntry == null || oldEntry.getDuration() - delay != potionEffect.getDuration() || oldEntry.getAmplifier() != potionEffect.getAmplifier() || oldEntry.isAmbient() != potionEffect.isAmbient() || oldEntry.getShowParticles() != potionEffect.getShowParticles()) {
context.sendToAll(() -> createAddMessage(potionEffect));
}
}
this.lastPotionEffects.values().forEach(potionEffect -> context.sendToAll(() -> new MessagePlayOutRemovePotionEffect(getRootEntityId(), potionEffect.getType())));
}
this.lastPotionSendTime = time;
this.lastPotionEffects = potionEffectMap;
}
Aggregations