revert permission change

This commit is contained in:
aPunch 2012-02-21 19:56:22 -06:00
parent 67c8d61715
commit 90d5473ba2
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.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<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 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.
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;

View File

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

View File

@ -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();

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