From c441dba815351c36ffbfa3f37d64ef0291a2a777 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 5 May 2019 12:03:20 +1000 Subject: [PATCH] SPIGOT-4834: API for Villager levels and experience --- .../craftbukkit/entity/CraftVillager.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index 8f674d3463..8cb4967e0f 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Preconditions; import java.util.Locale; import net.minecraft.server.EntityVillager; import net.minecraft.server.IRegistry; @@ -51,4 +52,28 @@ public class CraftVillager extends CraftAbstractVillager implements Villager { Validate.notNull(type); getHandle().setVillagerData(getHandle().getVillagerData().withType(IRegistry.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())))); } + + @Override + public int getVillagerLevel() { + return getHandle().getVillagerData().getLevel(); + } + + @Override + public void setVillagerLevel(int level) { + Preconditions.checkArgument(0 <= level && level <= 5, "level must be between [0, 5]"); + + getHandle().setVillagerData(getHandle().getVillagerData().withLevel(level)); + } + + @Override + public int getVillagerExperience() { + return getHandle().dV(); + } + + @Override + public void setVillagerExperience(int experience) { + Preconditions.checkArgument(experience >= 0, "Experience must be positive"); + + getHandle().t(experience); + } }