From 495e8ad286356aa7faf421a89bbcfe9d966316c2 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 20 Jul 2016 00:49:00 +0800 Subject: [PATCH] Add new zombiemodifier for professions --- .../citizensnpcs/commands/NPCCommands.java | 11 +++++++++- .../citizensnpcs/trait/ZombieModifier.java | 20 ++++++++++++++++--- .../java/net/citizensnpcs/util/Messages.java | 1 + src/main/resources/messages_en.properties | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 15826ec4e..4c311586d 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -1969,7 +1969,7 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "zombiemod (-b(aby), -v(illager))", + usage = "zombiemod (-b(aby), -v(illager) --p(rofession) [profession])", desc = "Sets a zombie NPC to be a baby or villager", modifiers = { "zombie", "zombiemod" }, flags = "bv", @@ -1988,5 +1988,14 @@ public class NPCCommands { Messaging.sendTr(sender, isVillager ? Messages.ZOMBIE_VILLAGER_SET : Messages.ZOMBIE_VILLAGER_UNSET, npc.getName()); } + if (args.hasValueFlag("profession") || args.hasValueFlag("p")) { + Profession profession = Util.matchEnum(Profession.values(), args.getFlag("profession", args.getFlag("p"))); + if (profession == null) { + throw new CommandException(); + } + trait.setProfession(profession); + Messaging.sendTr(sender, Messages.ZOMBIE_VILLAGER_PROFESSION_SET, npc.getName(), + Util.prettyEnum(profession)); + } } } diff --git a/src/main/java/net/citizensnpcs/trait/ZombieModifier.java b/src/main/java/net/citizensnpcs/trait/ZombieModifier.java index 6ea53ebfc..d1f9735ca 100644 --- a/src/main/java/net/citizensnpcs/trait/ZombieModifier.java +++ b/src/main/java/net/citizensnpcs/trait/ZombieModifier.java @@ -1,5 +1,6 @@ package net.citizensnpcs.trait; +import org.bukkit.entity.Villager.Profession; import org.bukkit.entity.Zombie; import net.citizensnpcs.api.persistence.Persist; @@ -11,6 +12,8 @@ public class ZombieModifier extends Trait { @Persist private boolean baby; @Persist + private Profession profession; + @Persist private boolean villager; private boolean zombie; @@ -23,22 +26,33 @@ public class ZombieModifier extends Trait { if (npc.getEntity() instanceof Zombie) { ((Zombie) npc.getEntity()).setVillager(villager); ((Zombie) npc.getEntity()).setBaby(baby); + ((Zombie) npc.getEntity()).setVillagerProfession(profession); zombie = true; - } else + } else { zombie = false; + } + } + + public void setProfession(Profession profession) { + this.profession = profession; + if (zombie) { + ((Zombie) npc.getEntity()).setVillagerProfession(profession); + } } public boolean toggleBaby() { baby = !baby; - if (zombie) + if (zombie) { ((Zombie) npc.getEntity()).setBaby(baby); + } return baby; } public boolean toggleVillager() { villager = !villager; - if (zombie) + if (zombie) { ((Zombie) npc.getEntity()).setVillager(villager); + } return villager; } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index cfe2d6742..5dbbeb582 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -281,6 +281,7 @@ public class Messages { public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default"; public static final String ZOMBIE_BABY_SET = "citizens.commands.npc.zombiemod.baby-set"; public static final String ZOMBIE_BABY_UNSET = "citizens.commands.npc.zombiemod.baby-unset"; + public static final String ZOMBIE_VILLAGER_PROFESSION_SET = "citizens.commands.npc.zombiemod.villager-profession-set"; public static final String ZOMBIE_VILLAGER_SET = "citizens.commands.npc.zombiemod.villager-set"; public static final String ZOMBIE_VILLAGER_UNSET = "citizens.commands.npc.zombiemod.villager-unset"; } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index fafdb9cbc..cd3889f32 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -142,6 +142,7 @@ citizens.commands.npc.zombiemod.villager-set=[[{0}]] is now a villager. citizens.commands.npc.zombiemod.villager-unset=[[{0}]] is no longer a villager. citizens.commands.npc.zombiemod.baby-set=[[{0}]] is now a baby. citizens.commands.npc.zombiemod.baby-unset=[[{0}]] is no longer a baby. +citizens.commands.npc.zombiemod.villager-profession-set=[[{0}]]''s profession set to [[{1}]]. citizens.commands.page-missing=The page [[{0}]] does not exist. citizens.commands.requirements.disallowed-mobtype=The NPC cannot be the mob type [[{0}]] for that command. citizens.commands.requirements.living-entity=The NPC must be a living entity.