Simplify multi-way selection prompt

This commit is contained in:
fullwall 2012-10-26 12:11:30 +08:00
parent addf9c4a2b
commit 8abfa3b96e
3 changed files with 14 additions and 16 deletions

View File

@ -28,19 +28,19 @@ public class SelectionPrompt extends NumericPrompt {
@Override
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
Object num = context.getSessionData(input);
if (num == null) {
for (NPC npc : choices) {
if (input.intValue() == npc.getId()) {
num = input.intValue();
break;
}
boolean found = false;
for (NPC npc : choices) {
if (input.intValue() == npc.getId()) {
found = true;
break;
}
if (num == null)
return this;
}
NPC toSelect = CitizensAPI.getNPCRegistry().getById((Integer) num);
CommandSender sender = (CommandSender) context.getForWhom();
if (!found) {
Messaging.sendErrorTr(sender, Messages.SELECTION_PROMPT_INVALID_CHOICE, input);
return this;
}
NPC toSelect = CitizensAPI.getNPCRegistry().getById(input.intValue());
selector.select(sender, toSelect);
Messaging.sendWithNPC(sender, Setting.SELECTION_MESSAGE.asString(), toSelect);
return null;
@ -49,12 +49,8 @@ public class SelectionPrompt extends NumericPrompt {
@Override
public String getPromptText(ConversationContext context) {
String text = Messaging.tr(Messages.SELECTION_PROMPT);
int num = 1;
for (NPC npc : choices) {
text += "<br> - " + npc.getId() + "(" + num + ")";
context.setSessionData(npc.getId(), num);
num++;
}
for (NPC npc : choices)
text += "\n - " + npc.getId();
return text;
}

View File

@ -182,4 +182,5 @@ public class Messages {
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default";
public static final String ADDED_TO_PLAYERLIST = "citizens.commands.npc.playerlist.added";
public static final String REMOVED_FROM_PLAYERLIST = "citizens.commands.npc.playerlist.removed";
public static final String SELECTION_PROMPT_INVALID_CHOICE = "citizens.conversations.selection.invalid-choice";
}

View File

@ -4,6 +4,7 @@ citizens.commands.console-error=Please report this error: [See console]
citizens.commands.npc.playerlist.added=Added [[{0}]] to the player list.
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
citizens.commands.help.command-missing=Command /{0} not found.
citizens.conversations.selection.invalid-choice=[[{0}]] is not a valid option.
citizens.commands.help.header=Help
citizens.commands.id-not-found=Couldn't find any NPC with ID {0}.
citizens.commands.invalid-mobtype={0} is not a valid mobtype.