|
|
@ -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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|