From 5469138a69a99da70aaf9c46a405eacb93b56042 Mon Sep 17 00:00:00 2001 From: aPunch Date: Tue, 21 Feb 2012 19:56:22 -0600 Subject: [PATCH] revert permission change --- src/net/citizensnpcs/Citizens.java | 3 +- .../citizensnpcs/command/CommandManager.java | 6 +- .../command/command/EditorCommands.java | 49 ++++++++------- .../command/command/NPCCommands.java | 40 +++++------- src/net/citizensnpcs/trait/Sneak.java | 63 ------------------- 5 files changed, 48 insertions(+), 113 deletions(-) delete mode 100644 src/net/citizensnpcs/trait/Sneak.java diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index e8387a492..9eb859ba3 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -35,7 +35,6 @@ import net.citizensnpcs.command.exception.UnhandledCommandException; import net.citizensnpcs.command.exception.WrappedCommandException; import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.trait.LookClose; -import net.citizensnpcs.trait.Sneak; import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Metrics; import net.citizensnpcs.util.StringHelper; @@ -57,7 +56,7 @@ public class Citizens extends JavaPlugin { @SuppressWarnings("unchecked") private static final List> defaultTraits = Lists.newArrayList(Owner.class, Spawned.class, - LookClose.class, SpawnLocation.class, Inventory.class, Sneak.class); + LookClose.class, SpawnLocation.class, Inventory.class); private volatile CitizensNPCManager npcManager; private final DefaultInstanceFactory characterManager = new DefaultInstanceFactory(); diff --git a/src/net/citizensnpcs/command/CommandManager.java b/src/net/citizensnpcs/command/CommandManager.java index 0bbe4ede8..1f5a0e36c 100644 --- a/src/net/citizensnpcs/command/CommandManager.java +++ b/src/net/citizensnpcs/command/CommandManager.java @@ -204,10 +204,8 @@ public class CommandManager { // Returns whether a player has access to a command. private boolean hasPermission(Method method, Player player) { Command cmd = method.getAnnotation(Command.class); - if (cmd.permission().isEmpty()) - return true; - - if (hasPermission(player, cmd.permission())) + if (cmd.permission().isEmpty() || hasPermission(player, cmd.permission()) + || hasPermission(player, "citizens.admin")) return true; return false; diff --git a/src/net/citizensnpcs/command/command/EditorCommands.java b/src/net/citizensnpcs/command/command/EditorCommands.java index 082063917..63e7b33ca 100644 --- a/src/net/citizensnpcs/command/command/EditorCommands.java +++ b/src/net/citizensnpcs/command/command/EditorCommands.java @@ -6,6 +6,7 @@ import net.citizensnpcs.Citizens; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.command.CommandContext; import net.citizensnpcs.command.annotation.Command; +import net.citizensnpcs.util.Messaging; public class EditorCommands { @@ -18,30 +19,36 @@ public class EditorCommands { desc = "Toggle equipment editor", modifiers = { "equip" }, min = 1, - max = 1) + max = 1, + permission = "npc.equip") public void toggleEquipEditor(CommandContext args, Player player, NPC npc) { + if (!(npc instanceof Player)) { + Messaging.sendError(player, "The NPC must be a human to equip armor and items."); + return; + } + } + + @Command( + aliases = { "npc" }, + usage = "path", + desc = "Toggle path editor", + modifiers = { "path" }, + min = 1, + max = 1, + permission = "npc.path") + public void togglePathEditor(CommandContext args, Player player, NPC npc) { // TODO } - + @Command( - aliases = { "npc" }, - usage = "path", - desc = "Toggle path editor", - modifiers = { "path" }, - min = 1, - max = 1) - public void togglePathEditor(CommandContext args, Player player, NPC npc) { - // TODO - } - - @Command( - aliases = { "npc" }, - usage = "text", - desc = "Toggle text editor", - modifiers = { "text" }, - min = 1, - max = 1) - public void toggleTextEditor(CommandContext args, Player player, NPC npc) { + aliases = { "npc" }, + usage = "text", + desc = "Toggle text editor", + modifiers = { "text" }, + min = 1, + max = 1, + permission = "npc.text") + public void toggleTextEditor(CommandContext args, Player player, NPC npc) { // TODO - } + } } \ No newline at end of file diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index 684bd7cec..69d38688b 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -15,7 +15,6 @@ import net.citizensnpcs.command.annotation.Command; import net.citizensnpcs.command.annotation.Requirements; import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.trait.LookClose; -import net.citizensnpcs.trait.Sneak; import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.StringHelper; @@ -99,7 +98,8 @@ public class NPCCommands { desc = "Despawn an NPC", modifiers = { "despawn" }, min = 1, - max = 1) + max = 1, + permission = "npc.despawn") public void despawnNPC(CommandContext args, Player player, NPC npc) { npc.getTrait(Spawned.class).setSpawned(false); npc.despawn(); @@ -118,7 +118,8 @@ public class NPCCommands { desc = "Rename an NPC", modifiers = { "rename" }, min = 2, - max = 2) + max = 2, + permission = "npc.rename") public void renameNPC(CommandContext args, Player player, NPC npc) { String oldName = npc.getName(); String newName = args.getString(1); @@ -137,7 +138,8 @@ public class NPCCommands { desc = "Selects an NPC with the given ID", modifiers = { "select" }, min = 2, - max = 2) + max = 2, + permission = "npc.select") @Requirements(ownership = true) public void selectNPC(CommandContext args, Player player, NPC npc) { NPC toSelect = npcManager.getNPC(args.getInteger(1)); @@ -172,33 +174,23 @@ public class NPCCommands { Messaging.sendError(player, "The NPC already has the character '" + args.getString(1) + "'."); return; } + if (!player.hasPermission("citizens.npc.character." + character.getName())) { + Messaging.sendError(player, "You don't have permission to execute that command."); + return; + } Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '" + StringHelper.wrap(args.getString(1)) + "'."); npc.setCharacter(character); } - @Command( - aliases = { "npc" }, - usage = "sneak", - desc = "Toggle whether an NPC should sneak", - modifiers = { "sneak" }, - min = 1, - max = 1) - public void toggleSneak(CommandContext args, Player player, NPC npc) { - Sneak trait = npc.getTrait(Sneak.class); - trait.toggle(); - String msg = StringHelper.wrap(npc.getName()) + " will " - + (trait.isSneaking() ? "now sneak" : "no longer sneak"); - Messaging.send(player, msg += "."); - } - @Command( aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" }, min = 2, - max = 2) + max = 2, + permission = "npc.spawn") @Requirements public void spawnNPC(CommandContext args, Player player, NPC npc) { NPC respawn = npcManager.getNPC(args.getInteger(1)); @@ -228,7 +220,8 @@ public class NPCCommands { desc = "Teleport an NPC to your location", modifiers = { "tphere" }, min = 1, - max = 1) + max = 1, + permission = "npc.tphere") public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) { // Spawn the NPC if it isn't spawned to prevent NPEs if (!npc.isSpawned()) @@ -244,7 +237,8 @@ public class NPCCommands { desc = "Teleport to an NPC", modifiers = { "tp", "teleport" }, min = 1, - max = 1) + max = 1, + permission = "npc.tp") public void teleportToNPC(CommandContext args, Player player, NPC npc) { // Spawn the NPC if it isn't spawned to prevent NPEs if (!npc.isSpawned()) @@ -254,7 +248,7 @@ public class NPCCommands { } @Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = { - "lookclose", "look", "rotate" }, min = 1, max = 1) + "lookclose", "look", "rotate" }, min = 1, max = 1, permission = "npc.look-close") public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) { LookClose trait = npc.getTrait(LookClose.class); trait.toggle(); diff --git a/src/net/citizensnpcs/trait/Sneak.java b/src/net/citizensnpcs/trait/Sneak.java deleted file mode 100644 index 2c6735e7b..000000000 --- a/src/net/citizensnpcs/trait/Sneak.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.citizensnpcs.trait; - -import net.citizensnpcs.api.exception.NPCLoadException; -import net.citizensnpcs.api.npc.NPC; -import net.citizensnpcs.api.npc.trait.SaveId; -import net.citizensnpcs.api.npc.trait.Trait; -import net.citizensnpcs.api.util.DataKey; -import net.citizensnpcs.npc.entity.CitizensHumanNPC; - -import net.minecraft.server.EntityPlayer; -import net.minecraft.server.Packet40EntityMetadata; - -import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.entity.Player; - -@SaveId("sneak") -public class Sneak extends Trait implements Runnable { - private final NPC npc; - private boolean sneak; - - public Sneak(NPC npc) { - this.npc = npc; - } - - @Override - public void load(DataKey key) throws NPCLoadException { - sneak = key.getBoolean(""); - } - - @Override - public void save(DataKey key) { - key.setBoolean("", sneak); - } - - @Override - public void run() { - if (npc instanceof CitizensHumanNPC) { - EntityPlayer handle = ((CitizensHumanNPC) npc).getHandle(); - handle.setSneak(sneak); - for (Player player : Bukkit.getOnlinePlayers()) - ((CraftPlayer) player).getHandle().netServerHandler.sendPacket(new Packet40EntityMetadata(handle.id, - handle.getDataWatcher())); - } - } - - public void setSneaking(boolean sneak) { - this.sneak = sneak; - } - - public boolean isSneaking() { - return sneak; - } - - public void toggle() { - sneak = !sneak; - } - - @Override - public String toString() { - return "Sneak{" + sneak + "}"; - } -} \ No newline at end of file