fix: stop syncing ambient effects, close #289

Effects from beacons, conduits, and The Warden will no longer sync.
dependabot/gradle/org.junit.jupiter-junit-jupiter-engine-5.11.0
William 3 months ago
parent fead3df0d8
commit ea068529f6
No known key found for this signature in database

@ -47,6 +47,7 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range; import org.jetbrains.annotations.Range;
import org.jetbrains.annotations.Unmodifiable;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.*; import java.util.*;
@ -236,8 +237,9 @@ public abstract class BukkitData implements Data {
private final Collection<PotionEffect> effects; private final Collection<PotionEffect> effects;
@NotNull @NotNull
public static BukkitData.PotionEffects from(@NotNull Collection<PotionEffect> effects) { public static BukkitData.PotionEffects from(@NotNull Collection<PotionEffect> sei) {
return new BukkitData.PotionEffects(effects); return new BukkitData.PotionEffects(Lists.newArrayList(sei.stream().filter(e -> !e.isAmbient()).toList()));
} }
@NotNull @NotNull
@ -261,7 +263,7 @@ public abstract class BukkitData implements Data {
@NotNull @NotNull
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static BukkitData.PotionEffects empty() { public static BukkitData.PotionEffects empty() {
return new BukkitData.PotionEffects(List.of()); return new BukkitData.PotionEffects(Lists.newArrayList());
} }
@Override @Override
@ -277,6 +279,7 @@ public abstract class BukkitData implements Data {
@NotNull @NotNull
@Override @Override
@Unmodifiable
public List<Effect> getActiveEffects() { public List<Effect> getActiveEffects() {
return effects.stream() return effects.stream()
.map(potionEffect -> new Effect( .map(potionEffect -> new Effect(

@ -53,6 +53,7 @@ import net.william278.husksync.user.FabricUser;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range; import org.jetbrains.annotations.Range;
import org.jetbrains.annotations.Unmodifiable;
import java.util.*; import java.util.*;
@ -237,8 +238,8 @@ public abstract class FabricData implements Data {
private final Collection<StatusEffectInstance> effects; private final Collection<StatusEffectInstance> effects;
@NotNull @NotNull
public static FabricData.PotionEffects from(@NotNull Collection<StatusEffectInstance> effects) { public static FabricData.PotionEffects from(@NotNull Collection<StatusEffectInstance> sei) {
return new FabricData.PotionEffects(effects); return new FabricData.PotionEffects(Lists.newArrayList(sei.stream().filter(e -> !e.isAmbient()).toList()));
} }
@NotNull @NotNull
@ -263,19 +264,21 @@ public abstract class FabricData implements Data {
@NotNull @NotNull
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static FabricData.PotionEffects empty() { public static FabricData.PotionEffects empty() {
return new FabricData.PotionEffects(List.of()); return new FabricData.PotionEffects(Lists.newArrayList());
} }
@Override @Override
public void apply(@NotNull FabricUser user, @NotNull FabricHuskSync plugin) throws IllegalStateException { public void apply(@NotNull FabricUser user, @NotNull FabricHuskSync plugin) throws IllegalStateException {
final ServerPlayerEntity player = user.getPlayer(); final ServerPlayerEntity player = user.getPlayer();
List<StatusEffect> effectsToRemove = new ArrayList<>(player.getActiveStatusEffects().keySet()); final List<StatusEffect> effectsToRemove = player.getActiveStatusEffects().entrySet().stream()
.filter(e -> !e.getValue().isAmbient()).map(Map.Entry::getKey).toList();
effectsToRemove.forEach(player::removeStatusEffect); effectsToRemove.forEach(player::removeStatusEffect);
getEffects().forEach(player::addStatusEffect); getEffects().forEach(player::addStatusEffect);
} }
@NotNull @NotNull
@Override @Override
@Unmodifiable
public List<Effect> getActiveEffects() { public List<Effect> getActiveEffects() {
return effects.stream() return effects.stream()
.map(potionEffect -> { .map(potionEffect -> {
@ -368,7 +371,7 @@ public abstract class FabricData implements Data {
// Restore player exp level & progress // Restore player exp level & progress
if (!toAward.isEmpty() if (!toAward.isEmpty()
&& (player.experienceLevel != expLevel || player.experienceProgress != expProgress)) { && (player.experienceLevel != expLevel || player.experienceProgress != expProgress)) {
player.setExperienceLevel(expLevel); player.setExperienceLevel(expLevel);
player.setExperiencePoints((int) (player.getNextLevelExperience() * expProgress)); player.setExperiencePoints((int) (player.getNextLevelExperience() * expProgress));
} }

Loading…
Cancel
Save