From deeecc7f080ef14da10d49d28a7bd021144b288a Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 1 May 2019 18:39:43 +1000 Subject: [PATCH] SPIGOT-4820: Villager Type API --- .../bukkit/craftbukkit/entity/CraftVillager.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index 8989fec812..8f674d3463 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -3,9 +3,9 @@ package org.bukkit.craftbukkit.entity; import java.util.Locale; import net.minecraft.server.EntityVillager; import net.minecraft.server.IRegistry; -import net.minecraft.server.MinecraftKey; import org.apache.commons.lang.Validate; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Villager; @@ -38,6 +38,17 @@ public class CraftVillager extends CraftAbstractVillager implements Villager { @Override public void setProfession(Profession profession) { Validate.notNull(profession); - getHandle().setVillagerData(getHandle().getVillagerData().withProfession(IRegistry.VILLAGER_PROFESSION.get(new MinecraftKey(profession.name().toLowerCase(Locale.ROOT))))); + getHandle().setVillagerData(getHandle().getVillagerData().withProfession(IRegistry.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(profession.getKey())))); + } + + @Override + public Type getVillagerType() { + return Type.valueOf(IRegistry.VILLAGER_TYPE.getKey(getHandle().getVillagerData().getType()).getKey().toUpperCase(Locale.ROOT)); + } + + @Override + public void setVillagerType(Type type) { + Validate.notNull(type); + getHandle().setVillagerData(getHandle().getVillagerData().withType(IRegistry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())))); } }