use of org.spongepowered.api.effect.potion.PotionEffect in project LanternServer by LanternPowered.
the class PotionEffectHelper method merge.
public static List<PotionEffect> merge(Collection<PotionEffect> effectsA, Collection<PotionEffect> effectsB) {
final Map<PotionEffectType, PotionEffect> effectsByType = new HashMap<>();
for (PotionEffect effect : effectsA) {
effectsByType.put(effect.getType(), effect);
}
final List<PotionEffect> result = new ArrayList<>();
for (PotionEffect effect : effectsB) {
final PotionEffect potionEffect = effectsByType.remove(effect.getType());
if (potionEffect != null) {
result.add(merge(effect, potionEffect));
} else {
result.add(effect);
}
}
result.addAll(effectsByType.values());
return result;
}
use of org.spongepowered.api.effect.potion.PotionEffect 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