Warn on missing delay in text prompt

This commit is contained in:
fullwall 2019-12-19 16:46:26 +09:00
parent 530e26c4f8
commit 8c165b9d55

View File

@ -11,67 +11,69 @@ import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
public class TextStartPrompt extends StringPrompt { public class TextStartPrompt extends StringPrompt {
private final Text text; private final Text text;
public TextStartPrompt(Text text) { public TextStartPrompt(Text text) {
this.text = text; this.text = text;
} }
@Override @Override
public Prompt acceptInput(ConversationContext context, String original) { public Prompt acceptInput(ConversationContext context, String original) {
String[] parts = ChatColor.stripColor(original.trim()).split(" "); String[] parts = ChatColor.stripColor(original.trim()).split(" ");
String input = parts[0]; String input = parts[0];
CommandSender sender = (CommandSender) context.getForWhom(); CommandSender sender = (CommandSender) context.getForWhom();
if (input.equalsIgnoreCase("add")) if (input.equalsIgnoreCase("add"))
return new TextAddPrompt(text); return new TextAddPrompt(text);
else if (input.equalsIgnoreCase("edit")) else if (input.equalsIgnoreCase("edit"))
return new TextEditStartPrompt(text); return new TextEditStartPrompt(text);
else if (input.equalsIgnoreCase("remove")) else if (input.equalsIgnoreCase("remove"))
return new TextRemovePrompt(text); return new TextRemovePrompt(text);
else if (input.equalsIgnoreCase("delay")) { else if (input.equalsIgnoreCase("delay")) {
try { try {
int delay = Integer.parseInt(parts[1]); int delay = Integer.parseInt(parts[1]);
text.setDelay(delay); text.setDelay(delay);
Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay); Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY); Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
} } catch (ArrayIndexOutOfBoundsException e) {
} else if (input.equalsIgnoreCase("random")) Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker()); }
else if (input.equalsIgnoreCase("realistic looking")) } else if (input.equalsIgnoreCase("random"))
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking()); Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
else if (input.equalsIgnoreCase("close") || input.equalsIgnoreCase("talk-close")) else if (input.equalsIgnoreCase("realistic looking"))
Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle()); Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());
else if (input.equalsIgnoreCase("range")) { else if (input.equalsIgnoreCase("close") || input.equalsIgnoreCase("talk-close"))
try { Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle());
double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble()); else if (input.equalsIgnoreCase("range")) {
text.setRange(range); try {
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range); double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble());
} catch (NumberFormatException e) { text.setRange(range);
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE); Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range);
} catch (ArrayIndexOutOfBoundsException e) { } catch (NumberFormatException e) {
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE); Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
} } catch (ArrayIndexOutOfBoundsException e) {
} else if (input.equalsIgnoreCase("item")) { Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
if (parts.length > 1) { }
text.setItemInHandPattern(parts[1]); } else if (input.equalsIgnoreCase("item")) {
Messaging.sendTr(sender, Messages.TEXT_EDITOR_SET_ITEM, parts[1]); if (parts.length > 1) {
} text.setItemInHandPattern(parts[1]);
} else if (input.equalsIgnoreCase("help")) { Messaging.sendTr(sender, Messages.TEXT_EDITOR_SET_ITEM, parts[1]);
context.setSessionData("said-text", false); }
Messaging.send(sender, getPromptText(context)); } else if (input.equalsIgnoreCase("help")) {
} else context.setSessionData("said-text", false);
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE); Messaging.send(sender, getPromptText(context));
} else
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE);
return new TextStartPrompt(text); return new TextStartPrompt(text);
} }
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
if (context.getSessionData("said-text") == Boolean.TRUE) if (context.getSessionData("said-text") == Boolean.TRUE)
return ""; return "";
String text = Messaging.tr(Messages.TEXT_EDITOR_START_PROMPT); String text = Messaging.tr(Messages.TEXT_EDITOR_START_PROMPT);
context.setSessionData("said-text", Boolean.TRUE); context.setSessionData("said-text", Boolean.TRUE);
return text; return text;
} }
} }