From 2e24b5b60f97eb86bb0c7715177cf63293e8f58e Mon Sep 17 00:00:00 2001 From: aPunch Date: Mon, 27 Feb 2012 02:32:43 -0600 Subject: [PATCH] added mob type requirement to commands --- src/main/java/net/citizensnpcs/Citizens.java | 7 +++- .../citizensnpcs/command/CommandManager.java | 7 ++++ .../citizensnpcs/command/Requirements.java | 4 ++ .../command/command/EditorCommands.java | 39 ++++++++++++++++--- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/citizensnpcs/Citizens.java b/src/main/java/net/citizensnpcs/Citizens.java index 5157feb33..2740bde76 100644 --- a/src/main/java/net/citizensnpcs/Citizens.java +++ b/src/main/java/net/citizensnpcs/Citizens.java @@ -15,6 +15,7 @@ import net.citizensnpcs.api.trait.DefaultInstanceFactory; import net.citizensnpcs.api.trait.InstanceFactory; import net.citizensnpcs.api.trait.Trait; import net.citizensnpcs.api.trait.trait.Inventory; +import net.citizensnpcs.api.trait.trait.MobType; import net.citizensnpcs.api.trait.trait.Owner; import net.citizensnpcs.api.trait.trait.SpawnLocation; import net.citizensnpcs.api.trait.trait.Spawned; @@ -25,6 +26,7 @@ import net.citizensnpcs.api.util.YamlStorage; import net.citizensnpcs.command.CommandManager; import net.citizensnpcs.command.Injector; import net.citizensnpcs.command.command.AdminCommands; +import net.citizensnpcs.command.command.EditorCommands; import net.citizensnpcs.command.command.HelpCommands; import net.citizensnpcs.command.command.NPCCommands; import net.citizensnpcs.command.exception.CommandUsageException; @@ -56,7 +58,7 @@ public class Citizens extends JavaPlugin { private volatile CitizensNPCManager npcManager; private final InstanceFactory characterManager = new DefaultInstanceFactory(); private final InstanceFactory traitManager = DefaultInstanceFactory.create(Owner.class, Spawned.class, - LookClose.class, SpawnLocation.class, Inventory.class); + LookClose.class, SpawnLocation.class, Inventory.class, MobType.class); private final CommandManager commands = new CommandManager(); private Settings config; private Storage saves; @@ -249,8 +251,9 @@ public class Citizens extends JavaPlugin { // Register command classes commands.register(AdminCommands.class); - commands.register(NPCCommands.class); + commands.register(EditorCommands.class); commands.register(HelpCommands.class); + commands.register(NPCCommands.class); } private void saveNPCs() { diff --git a/src/main/java/net/citizensnpcs/command/CommandManager.java b/src/main/java/net/citizensnpcs/command/CommandManager.java index 7bc947fd3..860934dc3 100644 --- a/src/main/java/net/citizensnpcs/command/CommandManager.java +++ b/src/main/java/net/citizensnpcs/command/CommandManager.java @@ -14,6 +14,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.citizensnpcs.api.npc.NPC; +import net.citizensnpcs.api.trait.trait.MobType; import net.citizensnpcs.api.trait.trait.Owner; import net.citizensnpcs.command.exception.CommandException; import net.citizensnpcs.command.exception.CommandUsageException; @@ -24,6 +25,7 @@ import net.citizensnpcs.command.exception.UnhandledCommandException; import net.citizensnpcs.command.exception.WrappedCommandException; import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; public class CommandManager { @@ -99,6 +101,11 @@ public class CommandManager { && !npc.getTrait(Owner.class).getOwner().equals(player.getName()) && !player.hasPermission("citizens.admin")) throw new RequirementMissingException("You must be the owner of this NPC to execute that command."); + if (cmdRequirements.type() != EntityType.UNKNOWN + && !cmdRequirements.type().name().equals(npc.getTrait(MobType.class).getType())) + throw new RequirementMissingException("The NPC must be of the type '" + + cmdRequirements.type().name().toLowerCase().replace('_', '-') + + "' in order for you to use that command."); } } diff --git a/src/main/java/net/citizensnpcs/command/Requirements.java b/src/main/java/net/citizensnpcs/command/Requirements.java index 255466b24..c817c2b3d 100644 --- a/src/main/java/net/citizensnpcs/command/Requirements.java +++ b/src/main/java/net/citizensnpcs/command/Requirements.java @@ -3,10 +3,14 @@ package net.citizensnpcs.command; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import org.bukkit.entity.EntityType; + @Retention(RetentionPolicy.RUNTIME) public @interface Requirements { boolean ownership() default false; boolean selected() default false; + + EntityType type() default EntityType.UNKNOWN; } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/command/command/EditorCommands.java b/src/main/java/net/citizensnpcs/command/command/EditorCommands.java index a6cdc6f53..e0461f2a2 100644 --- a/src/main/java/net/citizensnpcs/command/command/EditorCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/EditorCommands.java @@ -1,12 +1,15 @@ package net.citizensnpcs.command.command; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import net.citizensnpcs.Citizens; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.command.Command; import net.citizensnpcs.command.CommandContext; +import net.citizensnpcs.command.Requirements; +@Requirements(selected = true, ownership = true) public class EditorCommands { public EditorCommands(Citizens plugin) { @@ -14,11 +17,35 @@ public class EditorCommands { @Command( aliases = { "npc" }, - usage = "edit (editor)", - desc = "Toggle an NPC editor", - modifiers = { "edit" }, - min = 2, - max = 2) - public void toggleEquipEditor(CommandContext args, Player player, NPC npc) { + usage = "equip", + desc = "Toggle the equipment editor", + modifiers = { "equip" }, + min = 1, + max = 1, + permission = "npc.edit.equip") + @Requirements(selected = true, ownership = true, type = EntityType.PLAYER) + public void equip(CommandContext args, Player player, NPC npc) { + } + + @Command( + aliases = { "npc" }, + usage = "path", + desc = "Toggle the waypoint editor", + modifiers = { "path", "waypoints" }, + min = 1, + max = 1, + permission = "npc.edit.path") + public void path(CommandContext args, Player player, NPC npc) { + } + + @Command( + aliases = { "npc" }, + usage = "text", + desc = "Toggle the text editor", + modifiers = { "text" }, + min = 1, + max = 1, + permission = "npc.edit.text") + public void text(CommandContext args, Player player, NPC npc) { } } \ No newline at end of file