mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-26 01:01:42 +01:00
Simplify multi-way selection prompt
This commit is contained in:
parent
addf9c4a2b
commit
8abfa3b96e
@ -28,19 +28,19 @@ public class SelectionPrompt extends NumericPrompt {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||||
Object num = context.getSessionData(input);
|
boolean found = false;
|
||||||
if (num == null) {
|
|
||||||
for (NPC npc : choices) {
|
for (NPC npc : choices) {
|
||||||
if (input.intValue() == npc.getId()) {
|
if (input.intValue() == npc.getId()) {
|
||||||
num = input.intValue();
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (num == null)
|
CommandSender sender = (CommandSender) context.getForWhom();
|
||||||
|
if (!found) {
|
||||||
|
Messaging.sendErrorTr(sender, Messages.SELECTION_PROMPT_INVALID_CHOICE, input);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
NPC toSelect = CitizensAPI.getNPCRegistry().getById((Integer) num);
|
NPC toSelect = CitizensAPI.getNPCRegistry().getById(input.intValue());
|
||||||
CommandSender sender = (CommandSender) context.getForWhom();
|
|
||||||
selector.select(sender, toSelect);
|
selector.select(sender, toSelect);
|
||||||
Messaging.sendWithNPC(sender, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
Messaging.sendWithNPC(sender, Setting.SELECTION_MESSAGE.asString(), toSelect);
|
||||||
return null;
|
return null;
|
||||||
@ -49,12 +49,8 @@ public class SelectionPrompt extends NumericPrompt {
|
|||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
String text = Messaging.tr(Messages.SELECTION_PROMPT);
|
String text = Messaging.tr(Messages.SELECTION_PROMPT);
|
||||||
int num = 1;
|
for (NPC npc : choices)
|
||||||
for (NPC npc : choices) {
|
text += "\n - " + npc.getId();
|
||||||
text += "<br> - " + npc.getId() + "(" + num + ")";
|
|
||||||
context.setSessionData(npc.getId(), num);
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,4 +182,5 @@ public class Messages {
|
|||||||
public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default";
|
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 ADDED_TO_PLAYERLIST = "citizens.commands.npc.playerlist.added";
|
||||||
public static final String REMOVED_FROM_PLAYERLIST = "citizens.commands.npc.playerlist.removed";
|
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";
|
||||||
}
|
}
|
||||||
|
@ -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.added=Added [[{0}]] to the player list.
|
||||||
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
|
citizens.commands.npc.playerlist.removed=Removed [[{0}]] from the player list.
|
||||||
citizens.commands.help.command-missing=Command /{0} not found.
|
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.help.header=Help
|
||||||
citizens.commands.id-not-found=Couldn't find any NPC with ID {0}.
|
citizens.commands.id-not-found=Couldn't find any NPC with ID {0}.
|
||||||
citizens.commands.invalid-mobtype={0} is not a valid mobtype.
|
citizens.commands.invalid-mobtype={0} is not a valid mobtype.
|
||||||
|
Loading…
Reference in New Issue
Block a user