Skip to content

Commit

Permalink
fix: stop syncing ambient effects, close #289
Browse files Browse the repository at this point in the history
Effects from beacons, conduits, and The Warden will no longer sync.
  • Loading branch information
WiIIiam278 committed Aug 9, 2024
1 parent fead3df commit ea06852
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
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.*;
Expand Down Expand Up @@ -236,8 +237,9 @@ public static class PotionEffects extends BukkitData implements Data.PotionEffec
private final Collection<PotionEffect> effects;

@NotNull
public static BukkitData.PotionEffects from(@NotNull Collection<PotionEffect> effects) {
return new BukkitData.PotionEffects(effects);
public static BukkitData.PotionEffects from(@NotNull Collection<PotionEffect> sei) {
return new BukkitData.PotionEffects(Lists.newArrayList(sei.stream().filter(e -> !e.isAmbient()).toList()));

}

@NotNull
Expand All @@ -261,7 +263,7 @@ public static BukkitData.PotionEffects adapt(@NotNull Collection<Effect> effects
@NotNull
@SuppressWarnings("unused")
public static BukkitData.PotionEffects empty() {
return new BukkitData.PotionEffects(List.of());
return new BukkitData.PotionEffects(Lists.newArrayList());
}

@Override
Expand All @@ -277,6 +279,7 @@ public void apply(@NotNull BukkitUser user, @NotNull BukkitHuskSync plugin) thro

@NotNull
@Override
@Unmodifiable
public List<Effect> getActiveEffects() {
return effects.stream()
.map(potionEffect -> new Effect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;
import org.jetbrains.annotations.Unmodifiable;

import java.util.*;

Expand Down Expand Up @@ -237,8 +238,8 @@ public static class PotionEffects extends FabricData implements Data.PotionEffec
private final Collection<StatusEffectInstance> effects;

@NotNull
public static FabricData.PotionEffects from(@NotNull Collection<StatusEffectInstance> effects) {
return new FabricData.PotionEffects(effects);
public static FabricData.PotionEffects from(@NotNull Collection<StatusEffectInstance> sei) {
return new FabricData.PotionEffects(Lists.newArrayList(sei.stream().filter(e -> !e.isAmbient()).toList()));
}

@NotNull
Expand All @@ -263,19 +264,21 @@ public static FabricData.PotionEffects adapt(@NotNull Collection<Effect> effects
@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<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);
getEffects().forEach(player::addStatusEffect);
}

@NotNull
@Override
@Unmodifiable
public List<Effect> getActiveEffects() {
return effects.stream()
.map(potionEffect -> {
Expand Down Expand Up @@ -368,7 +371,7 @@ private void setAdvancement(@NotNull FabricHuskSync plugin,

// 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));
}
Expand Down

0 comments on commit ea06852

Please sign in to comment.