Skip to content

Commit

Permalink
Allow /npc remove to ignore the ownership requirement when called fro…
Browse files Browse the repository at this point in the history
…m console
  • Loading branch information
fullwall committed Aug 7, 2013
1 parent 8906ca3 commit a69476a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/main/java/net/citizensnpcs/Settings.java
Expand Up @@ -33,11 +33,12 @@ public Settings(File folder) {

public void reload() {
config.load();
for (Setting setting : Setting.values())
if (root.keyExists(setting.path))
for (Setting setting : Setting.values()) {
if (root.keyExists(setting.path)) {
setting.loadFromKey(root);
}
}
updateMessagingSettings();

save();
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/citizensnpcs/commands/NPCCommands.java
Expand Up @@ -783,9 +783,9 @@ public void pathfindingRange(CommandContext args, CommandSender sender, NPC npc)
@Requirements(selected = true, ownership = true, types = EntityType.PLAYER)
public void playerlist(CommandContext args, CommandSender sender, NPC npc) {
boolean remove = !npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
if (args.hasFlag('a'))
if (args.hasFlag('a')) {
remove = false;
else if (args.hasFlag('r'))
} else if (args.hasFlag('r'))
remove = true;
npc.data().setPersistent("removefromplayerlist", remove);
if (npc.isSpawned())
Expand Down Expand Up @@ -897,7 +897,7 @@ public void remove(CommandContext args, CommandSender sender, NPC npc) throws Co
}
if (npc == null)
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);
if (!sender.hasPermission("citizens.npc.remove") && !sender.hasPermission("citizens.admin"))
throw new NoPermissionsException();
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/net/citizensnpcs/trait/text/Text.java
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand Down Expand Up @@ -33,8 +32,10 @@
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;

import com.google.common.collect.Maps;

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 String itemInHandPattern = "default";
private final Plugin plugin;
Expand Down Expand Up @@ -67,7 +68,6 @@ public Editor getEditor(final Player player) {
.withLocalEcho(false).withEscapeSequence("/npc text").withEscapeSequence("exit").withModality(false)
.withFirstPrompt(new TextStartPrompt(this)).buildConversation(player);
return new Editor() {

@Override
public void begin() {
Messaging.sendTr(player, Messages.TEXT_EDITOR_BEGIN);
Expand All @@ -90,12 +90,15 @@ boolean hasIndex(int index) {
public void load(DataKey key) throws NPCLoadException {
text.clear();
// TODO: legacy, remove later
for (DataKey sub : key.getIntegerSubKeys())
for (DataKey sub : key.getIntegerSubKeys()) {
text.add(sub.getString(""));
for (DataKey sub : key.getRelative("text").getIntegerSubKeys())
}
for (DataKey sub : key.getRelative("text").getIntegerSubKeys()) {
text.add(sub.getString(""));
if (text.isEmpty())
}
if (text.isEmpty()) {
populateDefaultText();
}

talkClose = key.getBoolean("talk-close", talkClose);
realisticLooker = key.getBoolean("realistic-looking", realisticLooker);
Expand Down

0 comments on commit a69476a

Please sign in to comment.