From 713ac360bff35d5343ab7ff38e4f2fb720d1e6d6 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Wed, 1 May 2019 18:39:34 +1000 Subject: [PATCH] SPIGOT-4820: Villager Type API By: md_5 --- .../src/main/java/org/bukkit/Registry.java | 13 +++++ .../main/java/org/bukkit/entity/Villager.java | 57 ++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/paper-api/src/main/java/org/bukkit/Registry.java b/paper-api/src/main/java/org/bukkit/Registry.java index 433bf79d82..a36b890bd1 100644 --- a/paper-api/src/main/java/org/bukkit/Registry.java +++ b/paper-api/src/main/java/org/bukkit/Registry.java @@ -9,6 +9,7 @@ import org.bukkit.block.Biome; import org.bukkit.boss.KeyedBossBar; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Villager; import org.bukkit.loot.LootTables; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -116,6 +117,18 @@ public interface Registry extends Iterable { * @see Statistic */ Registry STATISTIC = new SimpleRegistry<>(Statistic.class); + /** + * Villager profession. + * + * @see Villager.Profession + */ + Registry VILLAGER_PROFESSION = new SimpleRegistry<>(Villager.Profession.class); + /** + * Villager type. + * + * @see Villager.Type + */ + Registry VILLAGER_TYPE = new SimpleRegistry<>(Villager.Type.class); /** * Get the object by its key. diff --git a/paper-api/src/main/java/org/bukkit/entity/Villager.java b/paper-api/src/main/java/org/bukkit/entity/Villager.java index 05fd0786a2..d7626a6d90 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Villager.java +++ b/paper-api/src/main/java/org/bukkit/entity/Villager.java @@ -1,5 +1,8 @@ package org.bukkit.entity; +import java.util.Locale; +import org.bukkit.Keyed; +import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; /** @@ -22,11 +25,52 @@ public interface Villager extends AbstractVillager { */ public void setProfession(@NotNull Profession profession); + /** + * Gets the current type of this villager. + * + * @return Current type. + */ + @NotNull + public Type getVillagerType(); + + /** + * Sets the new type of this villager. + * + * @param type New type. + */ + public void setVillagerType(@NotNull Type type); + + /** + * Represents Villager type, usually corresponding to what biome they spawn + * in. + */ + public enum Type implements Keyed { + + DESERT, + JUNGLE, + PLAINS, + SAVANNA, + SNOWY, + SWAMP, + TAIGA; + private final NamespacedKey key; + + private Type() { + this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT)); + } + + @NotNull + @Override + public NamespacedKey getKey() { + return key; + } + } + /** * Represents the various different Villager professions there may be. * Villagers have different trading options depending on their profession, */ - public enum Profession { + public enum Profession implements Keyed { NONE, /** * Armorer profession. Wears a black apron. @@ -103,5 +147,16 @@ public interface Villager extends AbstractVillager { * enchanted. */ WEAPONSMITH; + private final NamespacedKey key; + + private Profession() { + this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT)); + } + + @NotNull + @Override + public NamespacedKey getKey() { + return key; + } } }