From 3a8c1e7df0d658eb389c07bdfe5c941f52c5a8f0 Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 3 Mar 2021 21:33:23 -0800 Subject: [PATCH] Add support for villager stats to blueprints. https://github.com/BentoBoxWorld/BentoBox/issues/1695 --- .../blueprints/BlueprintClipboard.java | 17 ++++ .../dataobjects/BlueprintEntity.java | 91 +++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java index be5f3199e..f02173dd5 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/BlueprintClipboard.java @@ -26,6 +26,7 @@ import org.bukkit.entity.Horse; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; +import org.bukkit.entity.Villager; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Attachable; @@ -194,6 +195,9 @@ public class BlueprintClipboard { BlueprintEntity bpe = new BlueprintEntity(); bpe.setType(entity.getType()); bpe.setCustomName(entity.getCustomName()); + if (entity instanceof Villager) { + setVillager(entity, bpe); + } if (entity instanceof Colorable) { Colorable c = (Colorable)entity; if (c.getColor() != null) { @@ -301,6 +305,19 @@ public class BlueprintClipboard { return true; } + /** + * Set the villager stats + * @param entity - villager + * @param bpe - Blueprint Entity + */ + private void setVillager(LivingEntity entity, BlueprintEntity bpe) { + Villager v = (Villager)entity; + bpe.setExperience(v.getVillagerExperience()); + bpe.setLevel(v.getVillagerLevel()); + bpe.setProfession(v.getProfession()); + bpe.setVillagerType(v.getVillagerType()); + } + /** * @return the origin */ diff --git a/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java b/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java index 0f5dbf2fa..a99e972d9 100644 --- a/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java +++ b/src/main/java/world/bentobox/bentobox/blueprints/dataobjects/BlueprintEntity.java @@ -11,6 +11,8 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; import org.bukkit.entity.Horse.Style; import org.bukkit.entity.Tameable; +import org.bukkit.entity.Villager; +import org.bukkit.entity.Villager.Profession; import org.bukkit.inventory.ItemStack; import org.bukkit.material.Colorable; @@ -40,11 +42,23 @@ public class BlueprintEntity { private Map inventory; @Expose private Style style; + @Expose + private Integer level; + @Expose + private Profession profession; + @Expose + private Integer experience; + @Expose + private Villager.Type villagerType; + /** * @since 1.8.0 */ public void configureEntity(Entity e) { + if (e instanceof Villager) { + setVillager(e); + } if (e instanceof Colorable) { ((Colorable) e).setColor(color); } @@ -73,6 +87,19 @@ public class BlueprintEntity { } } + + /** + * @param e - villager + * @since 1.16.0 + */ + private void setVillager(Entity e) { + Villager v = (Villager)e; + v.setProfession(profession == null ? Profession.NONE : profession); + v.setVillagerExperience(experience == null ? 0 : experience); + v.setVillagerLevel(level == null ? 0 : level); + v.setVillagerType(villagerType == null ? Villager.Type.PLAINS : villagerType); + } + /** * @return the color */ @@ -181,4 +208,68 @@ public class BlueprintEntity { public void setStyle(Style style) { this.style = style; } + + /** + * @return the level + */ + public Integer getLevel() { + return level; + } + + /** + * @param level the level to set + */ + public void setLevel(Integer level) { + this.level = level; + } + + /** + * @return the profession + */ + public Profession getProfession() { + return profession; + } + + /** + * @param profession the profession to set + */ + public void setProfession(Profession profession) { + this.profession = profession; + } + + /** + * @return the experience + */ + public Integer getExperience() { + return experience; + } + + /** + * @param experience the experience to set + */ + public void setExperience(Integer experience) { + this.experience = experience; + } + + /** + * @return the villagerType + */ + public Villager.Type getVillagerType() { + return villagerType; + } + + /** + * @param villagerType the villagerType to set + */ + public void setVillagerType(Villager.Type villagerType) { + this.villagerType = villagerType; + } + + /** + * @param domestication the domestication to set + */ + public void setDomestication(Integer domestication) { + this.domestication = domestication; + } + }