Convert Cat type

This commit is contained in:
DerFrZocker 2023-05-24 18:20:06 +02:00
parent af6c2987e9
commit c6b51f7c66
No known key found for this signature in database
GPG key ID: 713F71FFFE1DDF91
2 changed files with 56 additions and 12 deletions

View file

@ -13,6 +13,7 @@ import org.bukkit.block.Biome;
import org.bukkit.block.BlockType;
import org.bukkit.boss.KeyedBossBar;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Cat;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Frog;
import org.bukkit.entity.Villager;
@ -100,6 +101,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
return Bukkit.getBossBars();
}
};
/**
* Server cat types.
*
* @see Cat.Type
*/
Registry<Cat.Type> CAT_TYPE = Objects.requireNonNull(Bukkit.getRegistry(Cat.Type.class), "No registry present for Cat Type. This is a bug.");
/**
* Server enchantments.
*

View file

@ -1,6 +1,12 @@
package org.bukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.bukkit.DyeColor;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;
/**
@ -41,17 +47,48 @@ public interface Cat extends Tameable, Sittable {
/**
* Represents the various different cat types there are.
*/
public enum Type {
TABBY,
BLACK,
RED,
SIAMESE,
BRITISH_SHORTHAIR,
CALICO,
PERSIAN,
RAGDOLL,
WHITE,
JELLIE,
ALL_BLACK;
abstract class Type extends OldEnum<Type> implements Keyed {
public static final Type TABBY = getType("tabby");
public static final Type BLACK = getType("black");
public static final Type RED = getType("red");
public static final Type SIAMESE = getType("siamese");
public static final Type BRITISH_SHORTHAIR = getType("british_shorthair");
public static final Type CALICO = getType("calico");
public static final Type PERSIAN = getType("persian");
public static final Type RAGDOLL = getType("ragdoll");
public static final Type WHITE = getType("white");
public static final Type JELLIE = getType("jellie");
public static final Type ALL_BLACK = getType("all_black");
@NotNull
private static Type getType(@NotNull String key) {
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
Type type = Registry.CAT_TYPE.get(namespacedKey);
Preconditions.checkNotNull(type, "No cat type found for %s. This is a bug.", namespacedKey);
return type;
}
/**
* @param name of the cat type.
* @return the cat type with the given name.
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
*/
@NotNull
@Deprecated
public static Type valueOf(@NotNull String name) {
Type type = Registry.CAT_TYPE.get(NamespacedKey.fromString(name.toLowerCase()));
Preconditions.checkArgument(type != null, "No cat type found with the name %s", name);
return type;
}
/**
* @return an array of all known cat types.
* @deprecated use {@link Registry#iterator()}.
*/
@NotNull
@Deprecated
public static Type[] values() {
return Lists.newArrayList(Registry.CAT_TYPE).toArray(new Type[0]);
}
}
}