From 09a09eeede81d5f828b7e18d2f86a69be8408e67 Mon Sep 17 00:00:00 2001 From: aPunch Date: Thu, 15 Mar 2012 06:02:53 -0500 Subject: [PATCH] Added ability to change a villager NPC profession. This addresses CITIZENS-14. --- lib/CitizensAPI.jar | Bin 48106 -> 48015 bytes .../command/command/NPCCommands.java | 22 ++++++++ .../npc/CitizensTraitManager.java | 2 + .../citizensnpcs/trait/CurrentLocation.java | 2 +- .../trait/VillagerProfession.java | 47 ++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/citizensnpcs/trait/VillagerProfession.java diff --git a/lib/CitizensAPI.jar b/lib/CitizensAPI.jar index 08c4ca5585668db00278b4c61b3bc30dcb34aa76..3261736366192bd71b5e19e3c22c4720378cd2eb 100644 GIT binary patch delta 5108 zcmZWt2{=@57axPM?}Qo4jD06s#!i+7*|+RV$et~0OvF$zmfIppw(KPPp6nGNifpAt zL{bSQ`K~*C{-6Ih&vWOT`#Zn)yyrdddG3AB{j>>B-Gnok7?4xY!uEaxGUw76#K`+W zfxQBWUVcb?l-d)(Au>5g>X9jsgIoYlb_}|2B2$9o53(bWl!B{45>F-qIGZB=XNEm5 zMQ|0!`T>4)PuB91Uxc%QipJ*IHbYu67_1z;&@dpcTmXMQ?V(Y(9CIRG=3XA9J{_H_ zHvLkZ@Jl0(U3T#}vYwI8Z*Aw1PfJ;kv#KD;nL4#FJPI5ZOn=;7hlQ!(qwyEuO}_N3gv)bc z%R`>kkG&wrAI(l2Im!*BOHjDA)vw}r8VxFEb#IPgrOWL-mh+uO$IKG8-)yvRpR%mF z)7eWXsywqPV(ve=&^Rx5r&0Wjj+NKEWA!+|1!gdBe=uZ&6eQ{Quo2YS>=Z zb`h;)Q2N@bnMleo%|keZq|XaNo6u}3a~glH%bN#jS4$WcHh3PoCy!lFt?GV!bFk;pz8{3Ipi1eRnP&=R4B zDh7wP@O?`GgAu{{m4g8;^@4!lDOS8Sn>G6%BY$$2&NSLX_Z$ldus%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|yFN)N^7xE=Sz?00oQ3~;*6YIlHJAxtsAq-p6{yF+KjVL!y74T4 zM?HCyf@UEQS&fFRVsUH-OX8Qlu CWoUo^ diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index 2558c27b1..ae3ee24c2 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -22,6 +22,7 @@ import net.citizensnpcs.npc.CitizensTraitManager; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.Powered; +import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.text.Text; import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Paginator; @@ -30,6 +31,7 @@ import net.citizensnpcs.util.StringHelper; import org.bukkit.ChatColor; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.Villager.Profession; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @Requirements(selected = true, ownership = true) @@ -391,4 +393,24 @@ public class NPCCommands { + (npc.getTrait(Powered.class).toggle() ? "now" : "no longer"); Messaging.send(player, msg += " be powered."); } + + @Command( + aliases = { "npc" }, + usage = "profession [profession]", + desc = "Set a NPC's profession", + modifiers = { "profession" }, + min = 2, + max = 2, + permission = "npc.profession") + @Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER }) + public void profession(CommandContext args, Player player, NPC npc) throws CommandException { + String profession = args.getString(1); + try { + npc.getTrait(VillagerProfession.class).setProfession(Profession.valueOf(profession.toUpperCase())); + Messaging.send(player, StringHelper.wrap(npc.getName()) + " is now the profession " + + StringHelper.wrap(profession.toUpperCase()) + "."); + } catch (IllegalArgumentException ex) { + throw new CommandException("'" + profession + "' is not a valid profession."); + } + } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java b/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java index 685f7eea0..cf31f0a45 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java @@ -17,6 +17,7 @@ import net.citizensnpcs.api.trait.trait.Spawned; import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.Powered; +import net.citizensnpcs.trait.VillagerProfession; import net.citizensnpcs.trait.text.Text; import net.citizensnpcs.trait.waypoint.Waypoints; @@ -35,6 +36,7 @@ public class CitizensTraitManager implements TraitManager { registerTrait(new TraitFactory(Spawned.class).withName("spawned")); registerTrait(new TraitFactory(CurrentLocation.class).withName("location")); registerTrait(new TraitFactory(Text.class).withName("text")); + registerTrait(new TraitFactory(VillagerProfession.class).withName("profession")); registerTrait(new TraitFactory(Waypoints.class).withName("waypoints")); } diff --git a/src/main/java/net/citizensnpcs/trait/CurrentLocation.java b/src/main/java/net/citizensnpcs/trait/CurrentLocation.java index 57a12be26..211544282 100644 --- a/src/main/java/net/citizensnpcs/trait/CurrentLocation.java +++ b/src/main/java/net/citizensnpcs/trait/CurrentLocation.java @@ -53,6 +53,6 @@ public class CurrentLocation extends Trait implements Runnable { @Override public String toString() { - return "SpawnLocation{" + loc + "}"; + return "CurrentLocation{" + loc + "}"; } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/trait/VillagerProfession.java b/src/main/java/net/citizensnpcs/trait/VillagerProfession.java new file mode 100644 index 000000000..6375f8ea8 --- /dev/null +++ b/src/main/java/net/citizensnpcs/trait/VillagerProfession.java @@ -0,0 +1,47 @@ +package net.citizensnpcs.trait; + +import net.citizensnpcs.api.exception.NPCLoadException; +import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.trait.Trait; +import net.citizensnpcs.api.util.DataKey; + +import org.bukkit.entity.Villager; +import org.bukkit.entity.Villager.Profession; + +public class VillagerProfession extends Trait { + private Profession profession = Profession.FARMER; + private final NPC npc; + + public VillagerProfession(NPC npc) { + this.npc = npc; + } + + @Override + public void load(DataKey key) throws NPCLoadException { + try { + profession = Profession.valueOf(key.getString("")); + } catch (IllegalArgumentException ex) { + throw new NPCLoadException("Invalid profession."); + } + } + + @Override + public void save(DataKey key) { + key.setString("", profession.name()); + } + + @Override + public void onNPCSpawn() { + if (npc.getBukkitEntity() instanceof Villager) + ((Villager) npc.getBukkitEntity()).setProfession(profession); + } + + public void setProfession(Profession profession) { + this.profession = profession; + } + + @Override + public String toString() { + return "Profession{" + profession + "}"; + } +} \ No newline at end of file