mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-08-05 16:49:39 +00:00
Some more cleanup
This commit is contained in:
parent
807e4bc249
commit
bef033b58d
6 changed files with 58 additions and 24 deletions
|
@ -106,7 +106,20 @@ public abstract class Art extends OldEnum<Art> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,15 +88,19 @@ public abstract class PatternType extends OldEnum<PatternType> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -337,6 +337,14 @@ public abstract class EntityType<E extends Entity> extends OldEnum<EntityType<E>
|
|||
@Nullable
|
||||
public abstract Class<E> 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<E extends Entity> extends OldEnum<EntityType<E>
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<PotionType> implements Keyed {
|
||||
|
|
Loading…
Add table
Reference in a new issue