SPIGOT-4834: API for Villager levels and experience

This commit is contained in:
md_5 2019-05-05 12:03:20 +10:00
parent 78616513e8
commit c441dba815

View File

@ -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);
}
}