Allow /npc remove to ignore the ownership requirement when called from console

This commit is contained in:
fullwall 2013-08-07 23:39:26 +08:00
parent 7d7f6b5415
commit 5df6499dae
3 changed files with 16 additions and 12 deletions

View File

@ -33,11 +33,12 @@ public class Settings {
public void reload() { public void reload() {
config.load(); config.load();
for (Setting setting : Setting.values()) for (Setting setting : Setting.values()) {
if (root.keyExists(setting.path)) if (root.keyExists(setting.path)) {
setting.loadFromKey(root); setting.loadFromKey(root);
}
}
updateMessagingSettings(); updateMessagingSettings();
save(); save();
} }

View File

@ -783,9 +783,9 @@ public class NPCCommands {
@Requirements(selected = true, ownership = true, types = EntityType.PLAYER) @Requirements(selected = true, ownership = true, types = EntityType.PLAYER)
public void playerlist(CommandContext args, CommandSender sender, NPC npc) { public void playerlist(CommandContext args, CommandSender sender, NPC npc) {
boolean remove = !npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean()); boolean remove = !npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
if (args.hasFlag('a')) if (args.hasFlag('a')) {
remove = false; remove = false;
else if (args.hasFlag('r')) } else if (args.hasFlag('r'))
remove = true; remove = true;
npc.data().setPersistent("removefromplayerlist", remove); npc.data().setPersistent("removefromplayerlist", remove);
if (npc.isSpawned()) if (npc.isSpawned())
@ -897,7 +897,7 @@ public class NPCCommands {
} }
if (npc == null) if (npc == null)
throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED); throw new CommandException(Messages.COMMAND_MUST_HAVE_SELECTED);
if (!npc.getTrait(Owner.class).isOwnedBy(sender)) if (!(sender instanceof ConsoleCommandSender) && !npc.getTrait(Owner.class).isOwnedBy(sender))
throw new CommandException(Messages.COMMAND_MUST_BE_OWNER); throw new CommandException(Messages.COMMAND_MUST_BE_OWNER);
if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin")) if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException(); throw new NoPermissionsException();

View File

@ -2,7 +2,6 @@ package net.citizensnpcs.trait.text;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@ -33,8 +32,10 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.google.common.collect.Maps;
public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener { public class Text extends Trait implements Runnable, Toggleable, Listener, ConversationAbandonedListener {
private final Map<String, Date> cooldowns = new HashMap<String, Date>(); private final Map<String, Date> cooldowns = Maps.newHashMap();
private int currentIndex; private int currentIndex;
private String itemInHandPattern = "default"; private String itemInHandPattern = "default";
private final Plugin plugin; private final Plugin plugin;
@ -67,7 +68,6 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
.withLocalEcho(false).withEscapeSequence("/npc text").withEscapeSequence("exit").withModality(false) .withLocalEcho(false).withEscapeSequence("/npc text").withEscapeSequence("exit").withModality(false)
.withFirstPrompt(new TextStartPrompt(this)).buildConversation(player); .withFirstPrompt(new TextStartPrompt(this)).buildConversation(player);
return new Editor() { return new Editor() {
@Override @Override
public void begin() { public void begin() {
Messaging.sendTr(player, Messages.TEXT_EDITOR_BEGIN); Messaging.sendTr(player, Messages.TEXT_EDITOR_BEGIN);
@ -90,12 +90,15 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
public void load(DataKey key) throws NPCLoadException { public void load(DataKey key) throws NPCLoadException {
text.clear(); text.clear();
// TODO: legacy, remove later // TODO: legacy, remove later
for (DataKey sub : key.getIntegerSubKeys()) for (DataKey sub : key.getIntegerSubKeys()) {
text.add(sub.getString("")); text.add(sub.getString(""));
for (DataKey sub : key.getRelative("text").getIntegerSubKeys()) }
for (DataKey sub : key.getRelative("text").getIntegerSubKeys()) {
text.add(sub.getString("")); text.add(sub.getString(""));
if (text.isEmpty()) }
if (text.isEmpty()) {
populateDefaultText(); populateDefaultText();
}
talkClose = key.getBoolean("talk-close", talkClose); talkClose = key.getBoolean("talk-close", talkClose);
realisticLooker = key.getBoolean("realistic-looking", realisticLooker); realisticLooker = key.getBoolean("realistic-looking", realisticLooker);