Skip to content

Commit

Permalink
Allow --id in non-selected requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Aug 11, 2013
1 parent 2c7393f commit 598fa65
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,23 @@ public void process(CommandSender sender, CommandContext context, Annotation ins
Requirements requirements = (Requirements) instance;
NPC npc = (methodArgs.length >= 3 && methodArgs[2] instanceof NPC) ? (NPC) methodArgs[2] : null;

// Requirements
if (requirements.selected()) {
boolean canRedefineSelected = context.hasValueFlag("id") && sender.hasPermission("npc.select");
String error = Messaging.tr(CommandMessages.MUST_HAVE_SELECTED);
if (canRedefineSelected) {
npc = CitizensAPI.getNPCRegistry().getById(context.getFlagInteger("id"));
if (methodArgs.length >= 3)
methodArgs[2] = npc;
if (npc == null)
error += ' ' + Messaging.tr(CommandMessages.ID_NOT_FOUND, context.getFlagInteger("id"));
}
boolean canRedefineSelected = context.hasValueFlag("id") && sender.hasPermission("npc.select");
String error = Messaging.tr(CommandMessages.MUST_HAVE_SELECTED);
if (canRedefineSelected) {
npc = CitizensAPI.getNPCRegistry().getById(context.getFlagInteger("id"));
if (methodArgs.length >= 3)
methodArgs[2] = npc;
if (npc == null)
throw new RequirementMissingException(error);
error += ' ' + Messaging.tr(CommandMessages.ID_NOT_FOUND, context.getFlagInteger("id"));
}
if (requirements.selected() && npc == null) {
throw new RequirementMissingException(error);
}

if (requirements.ownership() && npc != null && !sender.hasPermission("citizens.admin")
&& !npc.getTrait(Owner.class).isOwnedBy(sender))
&& !npc.getTrait(Owner.class).isOwnedBy(sender)) {
throw new RequirementMissingException(Messaging.tr(CommandMessages.MUST_BE_OWNER));
}

if (npc == null)
return;
Expand Down

0 comments on commit 598fa65

Please sign in to comment.