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 07f05bb6..568a30e6 100644 --- a/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java +++ b/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java @@ -237,21 +237,20 @@ public abstract class BukkitData implements Data { @NotNull public static BukkitData.PotionEffects adapt(@NotNull Collection effects) { - return from( - effects.stream() - .map(effect -> new PotionEffect( - Objects.requireNonNull( - PotionEffectType.getByName(effect.type()), - "Invalid potion effect type" - ), - effect.duration(), - effect.amplifier(), - effect.isAmbient(), - effect.showParticles(), - effect.hasIcon() - )) - .toList() - ); + return from(effects.stream() + .map(effect -> { + final PotionEffectType type = matchEffectType(effect.type()); + return type != null ? new PotionEffect( + type, + effect.duration(), + effect.amplifier(), + effect.isAmbient(), + effect.showParticles(), + effect.hasIcon() + ) : null; + }) + .filter(Objects::nonNull) + .toList()); } @NotNull diff --git a/bukkit/src/main/java/net/william278/husksync/util/BukkitKeyedAdapter.java b/bukkit/src/main/java/net/william278/husksync/util/BukkitKeyedAdapter.java index c427bf49..94bdfcce 100644 --- a/bukkit/src/main/java/net/william278/husksync/util/BukkitKeyedAdapter.java +++ b/bukkit/src/main/java/net/william278/husksync/util/BukkitKeyedAdapter.java @@ -22,6 +22,7 @@ package net.william278.husksync.util; import org.bukkit.*; import org.bukkit.attribute.Attribute; import org.bukkit.entity.EntityType; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -48,6 +49,11 @@ public final class BukkitKeyedAdapter { return getRegistryValue(Registry.ATTRIBUTE, key); } + @Nullable + public static PotionEffectType matchEffectType(@NotNull String key) { + return PotionEffectType.getByName(key); // No registry for this in 1.17 API + } + private static T getRegistryValue(@NotNull Registry registry, @NotNull String keyString) { final NamespacedKey key = NamespacedKey.fromString(keyString); return key != null ? registry.get(key) : null;