mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-08-21 05:44:17 +00:00
Make missing Frog variant abstract
This commit is contained in:
parent
a67a5f5c44
commit
af6c2987e9
2 changed files with 37 additions and 14 deletions
|
@ -215,7 +215,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
||||||
*
|
*
|
||||||
* @see Frog.Variant
|
* @see Frog.Variant
|
||||||
*/
|
*/
|
||||||
Registry<Frog.Variant> FROG_VARIANT = new SimpleRegistry<>(Frog.Variant.class);
|
Registry<Frog.Variant> FROG_VARIANT = Objects.requireNonNull(Bukkit.getRegistry(Frog.Variant.class), "No registry present for Frog Variant. This is a bug.");
|
||||||
/**
|
/**
|
||||||
* Game events.
|
* Game events.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package org.bukkit.entity;
|
package org.bukkit.entity;
|
||||||
|
|
||||||
import java.util.Locale;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.bukkit.Keyed;
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
import org.bukkit.Registry;
|
||||||
|
import org.bukkit.util.OldEnum;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -44,30 +47,50 @@ public interface Frog extends Animals {
|
||||||
/**
|
/**
|
||||||
* Represents the variant of a frog - ie its color.
|
* Represents the variant of a frog - ie its color.
|
||||||
*/
|
*/
|
||||||
public enum Variant implements Keyed {
|
abstract class Variant extends OldEnum<Variant> implements Keyed {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temperate (brown-orange) frog.
|
* Temperate (brown-orange) frog.
|
||||||
*/
|
*/
|
||||||
TEMPERATE,
|
public static final Variant TEMPERATE = getVariant("temperate");
|
||||||
/**
|
/**
|
||||||
* Warm (gray) frog.
|
* Warm (gray) frog.
|
||||||
*/
|
*/
|
||||||
WARM,
|
public static final Variant WARM = getVariant("warm");
|
||||||
/**
|
/**
|
||||||
* Cold (green) frog.
|
* Cold (green) frog.
|
||||||
*/
|
*/
|
||||||
COLD;
|
public static final Variant COLD = getVariant("cold");
|
||||||
private final NamespacedKey key;
|
|
||||||
|
|
||||||
private Variant() {
|
|
||||||
this.key = NamespacedKey.minecraft(name().toLowerCase(Locale.ROOT));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
private static Variant getVariant(@NotNull String key) {
|
||||||
public NamespacedKey getKey() {
|
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||||
return 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
|
||||||
|
public static Variant valueOf(@NotNull String name) {
|
||||||
|
Variant variant = Registry.FROG_VARIANT.get(NamespacedKey.fromString(name.toLowerCase()));
|
||||||
|
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
|
||||||
|
public static Variant[] values() {
|
||||||
|
return Lists.newArrayList(Registry.FROG_VARIANT).toArray(new Variant[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue