added mob type requirement to commands

This commit is contained in:
aPunch 2012-02-27 02:32:43 -06:00
parent e5994c562c
commit 2e24b5b60f
4 changed files with 49 additions and 8 deletions

View File

@ -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<Character> characterManager = new DefaultInstanceFactory<Character>();
private final InstanceFactory<Trait> 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() {

View File

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

View File

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

View File

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