From 8c65adeea27945745675d0fb900b6965385f1533 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 1 Oct 2022 18:21:08 +0200 Subject: [PATCH] Add generics to SpellContainer.stream --- .../unicopia/ability/magic/SpellContainer.java | 9 ++++++++- .../unicopia/network/datasync/EffectSync.java | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java index 703965ac..bbe1ad70 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellContainer.java @@ -62,9 +62,16 @@ public interface SpellContainer { */ boolean forEach(Function action, boolean update); + + /** + * Gets all active effects for this caster updating it if needed. + */ Stream stream(boolean update); - Stream stream(@Nullable SpellPredicate type, boolean update); + /** + * Gets all active effects for this caster that match the given type updating it if needed. + */ + Stream stream(@Nullable SpellPredicate type, boolean update); /** * Removes all effects currently active in this slot. diff --git a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java index 8fdec87b..33b71d91 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java +++ b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java @@ -51,9 +51,8 @@ public class EffectSync implements SpellContainer { } @Override - @SuppressWarnings("unchecked") public Optional get(@Nullable SpellPredicate type, boolean update) { - return (Optional)(read(type, update, true).findFirst()); + return read(type, update, true).findFirst(); } @Override @@ -95,7 +94,7 @@ public class EffectSync implements SpellContainer { } @Override - public Stream stream(@Nullable SpellPredicate type, boolean update) { + public Stream stream(@Nullable SpellPredicate type, boolean update) { return read(type, update, true); } @@ -111,15 +110,16 @@ public class EffectSync implements SpellContainer { return false; } - private Stream read(@Nullable SpellPredicate type, boolean synchronize, boolean sendUpdate) { + @SuppressWarnings("unchecked") + private Stream read(@Nullable SpellPredicate type, boolean synchronize, boolean sendUpdate) { if (synchronize && spells.fromNbt(owner.getEntity().getDataTracker().get(param)) && sendUpdate) { owner.getEntity().getDataTracker().set(param, spells.toNbt()); } if (type == null) { - return spells.getReferences(); + return (Stream)spells.getReferences(); } - return spells.getReferences().flatMap(s -> s.findMatches(type)); + return (Stream)spells.getReferences().flatMap(s -> s.findMatches(type)); } public boolean reduce(Alteration alteration) {