#1029: Trial changing a small number of inner enums to classes/interfaces to better support custom values
This PR is a subset of the enum PR #660 and is designed as a low impact trial run of the design and backwards compatibility to inform subsequent development. Additional plugin compatibility features may be available by setting `settings.compatibility.enum-compatibility-mode` to `true` in `bukkit.yml`. By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package org.bukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Locale;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.util.OldEnum;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -44,30 +48,51 @@ public interface Frog extends Animals {
|
||||
/**
|
||||
* Represents the variant of a frog - ie its color.
|
||||
*/
|
||||
public enum Variant implements Keyed {
|
||||
interface Variant extends OldEnum<Variant>, Keyed {
|
||||
|
||||
/**
|
||||
* Temperate (brown-orange) frog.
|
||||
*/
|
||||
TEMPERATE,
|
||||
Variant TEMPERATE = getVariant("temperate");
|
||||
/**
|
||||
* Warm (gray) frog.
|
||||
*/
|
||||
WARM,
|
||||
Variant WARM = getVariant("warm");
|
||||
/**
|
||||
* Cold (green) frog.
|
||||
*/
|
||||
COLD;
|
||||
private final NamespacedKey key;
|
||||
|
||||
private Variant() {
|
||||
this.key = NamespacedKey.minecraft(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
Variant COLD = getVariant("cold");
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
private static Variant getVariant(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Variant variant = Registry.FROG_VARIANT.get(namespacedKey);
|
||||
|
||||
Preconditions.checkNotNull(variant, "No frog variant found for %s. This is a bug.", namespacedKey);
|
||||
return variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name of the frog variant.
|
||||
* @return the frog variant with the given name.
|
||||
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated(since = "1.21")
|
||||
static Variant valueOf(@NotNull String name) {
|
||||
Variant variant = Registry.FROG_VARIANT.get(NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
|
||||
Preconditions.checkArgument(variant != null, "No frog variant found with the name %s", name);
|
||||
return variant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of all known frog variants.
|
||||
* @deprecated use {@link Registry#iterator()}.
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated(since = "1.21")
|
||||
static Variant[] values() {
|
||||
return Lists.newArrayList(Registry.FROG_VARIANT).toArray(new Variant[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user