diff --git a/src/main/java/org/bukkit/Art.java b/src/main/java/org/bukkit/Art.java index 6888c84a..802bf931 100644 --- a/src/main/java/org/bukkit/Art.java +++ b/src/main/java/org/bukkit/Art.java @@ -106,7 +106,20 @@ public abstract class Art extends OldEnum implements Keyed { @Deprecated @Nullable public static Art getById(int id) { - return BY_ID.get(id); + Art art = BY_ID.get(id); + + if (art != null) { + return art; + } + + for (Art other : Registry.ART) { + if (other.getId() == id) { + BY_ID.put(id, other); + return other; + } + } + + return null; } /** diff --git a/src/main/java/org/bukkit/block/banner/PatternType.java b/src/main/java/org/bukkit/block/banner/PatternType.java index e9ceb99b..ff93d013 100644 --- a/src/main/java/org/bukkit/block/banner/PatternType.java +++ b/src/main/java/org/bukkit/block/banner/PatternType.java @@ -88,15 +88,19 @@ public abstract class PatternType extends OldEnum implements Keyed return null; } - return byString.computeIfAbsent(identifier, id -> { - for (PatternType patternType : Registry.BANNER_PATTERN) { - if (identifier.equals(patternType.getIdentifier())) { - return patternType; - } - } + PatternType patternType = byString.get(identifier); + if (patternType != null) { + return patternType; + } - return null; - }); + for (PatternType type : Registry.BANNER_PATTERN) { + if (identifier.equals(type.getIdentifier())) { + byString.put(identifier, type); + return type; + } + } + + return null; } /** diff --git a/src/main/java/org/bukkit/entity/EntityType.java b/src/main/java/org/bukkit/entity/EntityType.java index 9bb9b2d1..855b4022 100644 --- a/src/main/java/org/bukkit/entity/EntityType.java +++ b/src/main/java/org/bukkit/entity/EntityType.java @@ -337,6 +337,14 @@ public abstract class EntityType extends OldEnum @Nullable public abstract Class getEntityClass(); + /** + * Gets if this EntityType is enabled by feature in a world. + * + * @param world the world to check + * @return true if this EntityType can be used to spawn an Entity for this World. + */ + public abstract boolean isEnabledByFeature(@NotNull World world); + /** * Gets the entity type name. * @@ -478,14 +486,4 @@ public abstract class EntityType extends OldEnum return from; } - - /** - * Gets if this EntityType is enabled by feature in a world. - * - * @param world the world to check - * @return true if this EntityType can be used to spawn an Entity for this World. - */ - public boolean isEnabledByFeature(@NotNull World world) { - return Bukkit.getDataPackManager().isEnabledByFeature(this, world); - } } diff --git a/src/main/java/org/bukkit/potion/PotionEffectType.java b/src/main/java/org/bukkit/potion/PotionEffectType.java index 686e1cfe..26bd4303 100644 --- a/src/main/java/org/bukkit/potion/PotionEffectType.java +++ b/src/main/java/org/bukkit/potion/PotionEffectType.java @@ -208,9 +208,7 @@ public abstract class PotionEffectType implements Keyed { * @see PotionBrewer#createEffect(PotionEffectType, int, int) */ @NotNull - public PotionEffect createEffect(int duration, int amplifier) { - return new PotionEffect(this, isInstant() ? 1 : (int) (duration * getDurationModifier()), amplifier); - } + public abstract PotionEffect createEffect(int duration, int amplifier); /** * Returns whether the effect of this type happens once, immediately. @@ -260,9 +258,11 @@ public abstract class PotionEffectType implements Keyed { * * @param key key to fetch * @return Resulting PotionEffectType, or null if not found + * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead. */ @Contract("null -> null") @Nullable + @Deprecated public static PotionEffectType getByKey(@Nullable NamespacedKey key) { return Registry.POTION_EFFECT_TYPE.get(key); } @@ -277,7 +277,20 @@ public abstract class PotionEffectType implements Keyed { @Deprecated @Nullable public static PotionEffectType getById(int id) { - return ID_MAP.get(id); + PotionEffectType type = ID_MAP.get(id); + + if (type != null) { + return type; + } + + for (PotionEffectType other : Registry.POTION_EFFECT_TYPE) { + if (other.getId() == id) { + ID_MAP.put(id, other); + return other; + } + } + + return null; } /** diff --git a/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java b/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java index 835752c9..0a2df03c 100644 --- a/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java +++ b/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java @@ -37,6 +37,12 @@ public class PotionEffectTypeWrapper extends PotionEffectType { return PotionEffectType.getByKey(getKey()); } + @NotNull + @Override + public PotionEffect createEffect(int duration, int amplifier) { + return getType().createEffect(duration, amplifier); + } + @Override public boolean isInstant() { return getType().isInstant(); diff --git a/src/main/java/org/bukkit/potion/PotionType.java b/src/main/java/org/bukkit/potion/PotionType.java index f0f4849b..d25875ae 100644 --- a/src/main/java/org/bukkit/potion/PotionType.java +++ b/src/main/java/org/bukkit/potion/PotionType.java @@ -11,7 +11,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** - * This enum reflects and matches each potion state that can be obtained from + * This class reflects and matches each potion state that can be obtained from * the Creative mode inventory */ public abstract class PotionType extends OldEnum implements Keyed {