From ea068529f6f1ed5594591b620dc188950d069a08 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 9 Aug 2024 14:39:56 +0100 Subject: [PATCH] fix: stop syncing ambient effects, close #289 Effects from beacons, conduits, and The Warden will no longer sync. --- .../net/william278/husksync/data/BukkitData.java | 9 ++++++--- .../net/william278/husksync/data/FabricData.java | 13 ++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java b/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java index 695c70c5..539597ce 100644 --- a/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java +++ b/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java @@ -47,6 +47,7 @@ import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Range; +import org.jetbrains.annotations.Unmodifiable; import java.lang.reflect.Constructor; import java.util.*; @@ -236,8 +237,9 @@ public abstract class BukkitData implements Data { private final Collection effects; @NotNull - public static BukkitData.PotionEffects from(@NotNull Collection effects) { - return new BukkitData.PotionEffects(effects); + public static BukkitData.PotionEffects from(@NotNull Collection sei) { + return new BukkitData.PotionEffects(Lists.newArrayList(sei.stream().filter(e -> !e.isAmbient()).toList())); + } @NotNull @@ -261,7 +263,7 @@ public abstract class BukkitData implements Data { @NotNull @SuppressWarnings("unused") public static BukkitData.PotionEffects empty() { - return new BukkitData.PotionEffects(List.of()); + return new BukkitData.PotionEffects(Lists.newArrayList()); } @Override @@ -277,6 +279,7 @@ public abstract class BukkitData implements Data { @NotNull @Override + @Unmodifiable public List getActiveEffects() { return effects.stream() .map(potionEffect -> new Effect( diff --git a/fabric/src/main/java/net/william278/husksync/data/FabricData.java b/fabric/src/main/java/net/william278/husksync/data/FabricData.java index 5a126f3c..d59323d6 100644 --- a/fabric/src/main/java/net/william278/husksync/data/FabricData.java +++ b/fabric/src/main/java/net/william278/husksync/data/FabricData.java @@ -53,6 +53,7 @@ import net.william278.husksync.user.FabricUser; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Range; +import org.jetbrains.annotations.Unmodifiable; import java.util.*; @@ -237,8 +238,8 @@ public abstract class FabricData implements Data { private final Collection effects; @NotNull - public static FabricData.PotionEffects from(@NotNull Collection effects) { - return new FabricData.PotionEffects(effects); + public static FabricData.PotionEffects from(@NotNull Collection sei) { + return new FabricData.PotionEffects(Lists.newArrayList(sei.stream().filter(e -> !e.isAmbient()).toList())); } @NotNull @@ -263,19 +264,21 @@ public abstract class FabricData implements Data { @NotNull @SuppressWarnings("unused") public static FabricData.PotionEffects empty() { - return new FabricData.PotionEffects(List.of()); + return new FabricData.PotionEffects(Lists.newArrayList()); } @Override public void apply(@NotNull FabricUser user, @NotNull FabricHuskSync plugin) throws IllegalStateException { final ServerPlayerEntity player = user.getPlayer(); - List effectsToRemove = new ArrayList<>(player.getActiveStatusEffects().keySet()); + final List effectsToRemove = player.getActiveStatusEffects().entrySet().stream() + .filter(e -> !e.getValue().isAmbient()).map(Map.Entry::getKey).toList(); effectsToRemove.forEach(player::removeStatusEffect); getEffects().forEach(player::addStatusEffect); } @NotNull @Override + @Unmodifiable public List getActiveEffects() { return effects.stream() .map(potionEffect -> { @@ -368,7 +371,7 @@ public abstract class FabricData implements Data { // Restore player exp level & progress if (!toAward.isEmpty() - && (player.experienceLevel != expLevel || player.experienceProgress != expProgress)) { + && (player.experienceLevel != expLevel || player.experienceProgress != expProgress)) { player.setExperienceLevel(expLevel); player.setExperiencePoints((int) (player.getNextLevelExperience() * expProgress)); }