revert permission change

This commit is contained in:
aPunch 2012-02-21 19:56:22 -06:00
parent 7acd56710c
commit 5469138a69
5 changed files with 48 additions and 113 deletions

View File

@ -35,7 +35,6 @@ import net.citizensnpcs.command.exception.UnhandledCommandException;
import net.citizensnpcs.command.exception.WrappedCommandException; import net.citizensnpcs.command.exception.WrappedCommandException;
import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Sneak;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.Metrics; import net.citizensnpcs.util.Metrics;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
@ -57,7 +56,7 @@ public class Citizens extends JavaPlugin {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static final List<Class<? extends Trait>> defaultTraits = Lists.newArrayList(Owner.class, Spawned.class, private static final List<Class<? extends Trait>> 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 volatile CitizensNPCManager npcManager;
private final DefaultInstanceFactory<Character> characterManager = new DefaultInstanceFactory<Character>(); private final DefaultInstanceFactory<Character> characterManager = new DefaultInstanceFactory<Character>();

View File

@ -204,10 +204,8 @@ public class CommandManager {
// Returns whether a player has access to a command. // Returns whether a player has access to a command.
private boolean hasPermission(Method method, Player player) { private boolean hasPermission(Method method, Player player) {
Command cmd = method.getAnnotation(Command.class); Command cmd = method.getAnnotation(Command.class);
if (cmd.permission().isEmpty()) if (cmd.permission().isEmpty() || hasPermission(player, cmd.permission())
return true; || hasPermission(player, "citizens.admin"))
if (hasPermission(player, cmd.permission()))
return true; return true;
return false; return false;

View File

@ -6,6 +6,7 @@ import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.command.CommandContext; import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.annotation.Command; import net.citizensnpcs.command.annotation.Command;
import net.citizensnpcs.util.Messaging;
public class EditorCommands { public class EditorCommands {
@ -18,9 +19,13 @@ public class EditorCommands {
desc = "Toggle equipment editor", desc = "Toggle equipment editor",
modifiers = { "equip" }, modifiers = { "equip" },
min = 1, min = 1,
max = 1) max = 1,
permission = "npc.equip")
public void toggleEquipEditor(CommandContext args, Player player, NPC npc) { public void toggleEquipEditor(CommandContext args, Player player, NPC npc) {
// TODO if (!(npc instanceof Player)) {
Messaging.sendError(player, "The NPC must be a human to equip armor and items.");
return;
}
} }
@Command( @Command(
@ -29,7 +34,8 @@ public class EditorCommands {
desc = "Toggle path editor", desc = "Toggle path editor",
modifiers = { "path" }, modifiers = { "path" },
min = 1, min = 1,
max = 1) max = 1,
permission = "npc.path")
public void togglePathEditor(CommandContext args, Player player, NPC npc) { public void togglePathEditor(CommandContext args, Player player, NPC npc) {
// TODO // TODO
} }
@ -40,7 +46,8 @@ public class EditorCommands {
desc = "Toggle text editor", desc = "Toggle text editor",
modifiers = { "text" }, modifiers = { "text" },
min = 1, min = 1,
max = 1) max = 1,
permission = "npc.text")
public void toggleTextEditor(CommandContext args, Player player, NPC npc) { public void toggleTextEditor(CommandContext args, Player player, NPC npc) {
// TODO // TODO
} }

View File

@ -15,7 +15,6 @@ import net.citizensnpcs.command.annotation.Command;
import net.citizensnpcs.command.annotation.Requirements; import net.citizensnpcs.command.annotation.Requirements;
import net.citizensnpcs.npc.CitizensNPCManager; import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.trait.LookClose; import net.citizensnpcs.trait.LookClose;
import net.citizensnpcs.trait.Sneak;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.StringHelper;
@ -99,7 +98,8 @@ public class NPCCommands {
desc = "Despawn an NPC", desc = "Despawn an NPC",
modifiers = { "despawn" }, modifiers = { "despawn" },
min = 1, min = 1,
max = 1) max = 1,
permission = "npc.despawn")
public void despawnNPC(CommandContext args, Player player, NPC npc) { public void despawnNPC(CommandContext args, Player player, NPC npc) {
npc.getTrait(Spawned.class).setSpawned(false); npc.getTrait(Spawned.class).setSpawned(false);
npc.despawn(); npc.despawn();
@ -118,7 +118,8 @@ public class NPCCommands {
desc = "Rename an NPC", desc = "Rename an NPC",
modifiers = { "rename" }, modifiers = { "rename" },
min = 2, min = 2,
max = 2) max = 2,
permission = "npc.rename")
public void renameNPC(CommandContext args, Player player, NPC npc) { public void renameNPC(CommandContext args, Player player, NPC npc) {
String oldName = npc.getName(); String oldName = npc.getName();
String newName = args.getString(1); String newName = args.getString(1);
@ -137,7 +138,8 @@ public class NPCCommands {
desc = "Selects an NPC with the given ID", desc = "Selects an NPC with the given ID",
modifiers = { "select" }, modifiers = { "select" },
min = 2, min = 2,
max = 2) max = 2,
permission = "npc.select")
@Requirements(ownership = true) @Requirements(ownership = true)
public void selectNPC(CommandContext args, Player player, NPC npc) { public void selectNPC(CommandContext args, Player player, NPC npc) {
NPC toSelect = npcManager.getNPC(args.getInteger(1)); 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) + "'."); Messaging.sendError(player, "The NPC already has the character '" + args.getString(1) + "'.");
return; 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 '" Messaging.send(player, StringHelper.wrap(npc.getName() + "'s") + " character is now '"
+ StringHelper.wrap(args.getString(1)) + "'."); + StringHelper.wrap(args.getString(1)) + "'.");
npc.setCharacter(character); 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( @Command(
aliases = { "npc" }, aliases = { "npc" },
usage = "spawn [id]", usage = "spawn [id]",
desc = "Spawn an existing NPC", desc = "Spawn an existing NPC",
modifiers = { "spawn" }, modifiers = { "spawn" },
min = 2, min = 2,
max = 2) max = 2,
permission = "npc.spawn")
@Requirements @Requirements
public void spawnNPC(CommandContext args, Player player, NPC npc) { public void spawnNPC(CommandContext args, Player player, NPC npc) {
NPC respawn = npcManager.getNPC(args.getInteger(1)); NPC respawn = npcManager.getNPC(args.getInteger(1));
@ -228,7 +220,8 @@ public class NPCCommands {
desc = "Teleport an NPC to your location", desc = "Teleport an NPC to your location",
modifiers = { "tphere" }, modifiers = { "tphere" },
min = 1, min = 1,
max = 1) max = 1,
permission = "npc.tphere")
public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) { public void teleportNPCToPlayer(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs // Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) if (!npc.isSpawned())
@ -244,7 +237,8 @@ public class NPCCommands {
desc = "Teleport to an NPC", desc = "Teleport to an NPC",
modifiers = { "tp", "teleport" }, modifiers = { "tp", "teleport" },
min = 1, min = 1,
max = 1) max = 1,
permission = "npc.tp")
public void teleportToNPC(CommandContext args, Player player, NPC npc) { public void teleportToNPC(CommandContext args, Player player, NPC npc) {
// Spawn the NPC if it isn't spawned to prevent NPEs // Spawn the NPC if it isn't spawned to prevent NPEs
if (!npc.isSpawned()) if (!npc.isSpawned())
@ -254,7 +248,7 @@ public class NPCCommands {
} }
@Command(aliases = { "npc" }, usage = "lookclose", desc = "Toggle an NPC's look-close state", modifiers = { @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) { public void toggleNPCLookClose(CommandContext args, Player player, NPC npc) {
LookClose trait = npc.getTrait(LookClose.class); LookClose trait = npc.getTrait(LookClose.class);
trait.toggle(); trait.toggle();

View File

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