mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-23 17:47:35 +01:00
Warn on missing delay in text prompt
This commit is contained in:
parent
530e26c4f8
commit
8c165b9d55
@ -11,67 +11,69 @@ import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
|
||||
public class TextStartPrompt extends StringPrompt {
|
||||
private final Text text;
|
||||
private final Text text;
|
||||
|
||||
public TextStartPrompt(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
public TextStartPrompt(Text text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String original) {
|
||||
String[] parts = ChatColor.stripColor(original.trim()).split(" ");
|
||||
String input = parts[0];
|
||||
CommandSender sender = (CommandSender) context.getForWhom();
|
||||
if (input.equalsIgnoreCase("add"))
|
||||
return new TextAddPrompt(text);
|
||||
else if (input.equalsIgnoreCase("edit"))
|
||||
return new TextEditStartPrompt(text);
|
||||
else if (input.equalsIgnoreCase("remove"))
|
||||
return new TextRemovePrompt(text);
|
||||
else if (input.equalsIgnoreCase("delay")) {
|
||||
try {
|
||||
int delay = Integer.parseInt(parts[1]);
|
||||
text.setDelay(delay);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("random"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
|
||||
else if (input.equalsIgnoreCase("realistic looking"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());
|
||||
else if (input.equalsIgnoreCase("close") || input.equalsIgnoreCase("talk-close"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle());
|
||||
else if (input.equalsIgnoreCase("range")) {
|
||||
try {
|
||||
double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble());
|
||||
text.setRange(range);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("item")) {
|
||||
if (parts.length > 1) {
|
||||
text.setItemInHandPattern(parts[1]);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_SET_ITEM, parts[1]);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("help")) {
|
||||
context.setSessionData("said-text", false);
|
||||
Messaging.send(sender, getPromptText(context));
|
||||
} else
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE);
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String original) {
|
||||
String[] parts = ChatColor.stripColor(original.trim()).split(" ");
|
||||
String input = parts[0];
|
||||
CommandSender sender = (CommandSender) context.getForWhom();
|
||||
if (input.equalsIgnoreCase("add"))
|
||||
return new TextAddPrompt(text);
|
||||
else if (input.equalsIgnoreCase("edit"))
|
||||
return new TextEditStartPrompt(text);
|
||||
else if (input.equalsIgnoreCase("remove"))
|
||||
return new TextRemovePrompt(text);
|
||||
else if (input.equalsIgnoreCase("delay")) {
|
||||
try {
|
||||
int delay = Integer.parseInt(parts[1]);
|
||||
text.setDelay(delay);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_DELAY_SET, delay);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_DELAY);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("random"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANDOM_TALKER_SET, text.toggleRandomTalker());
|
||||
else if (input.equalsIgnoreCase("realistic looking"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_REALISTIC_LOOKING_SET, text.toggleRealisticLooking());
|
||||
else if (input.equalsIgnoreCase("close") || input.equalsIgnoreCase("talk-close"))
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_CLOSE_TALKER_SET, text.toggle());
|
||||
else if (input.equalsIgnoreCase("range")) {
|
||||
try {
|
||||
double range = Math.min(Math.max(0, Double.parseDouble(parts[1])), Setting.MAX_TEXT_RANGE.asDouble());
|
||||
text.setRange(range);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_RANGE_SET, range);
|
||||
} catch (NumberFormatException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_RANGE);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("item")) {
|
||||
if (parts.length > 1) {
|
||||
text.setItemInHandPattern(parts[1]);
|
||||
Messaging.sendTr(sender, Messages.TEXT_EDITOR_SET_ITEM, parts[1]);
|
||||
}
|
||||
} else if (input.equalsIgnoreCase("help")) {
|
||||
context.setSessionData("said-text", false);
|
||||
Messaging.send(sender, getPromptText(context));
|
||||
} else
|
||||
Messaging.sendErrorTr(sender, Messages.TEXT_EDITOR_INVALID_EDIT_TYPE);
|
||||
|
||||
return new TextStartPrompt(text);
|
||||
}
|
||||
return new TextStartPrompt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
if (context.getSessionData("said-text") == Boolean.TRUE)
|
||||
return "";
|
||||
String text = Messaging.tr(Messages.TEXT_EDITOR_START_PROMPT);
|
||||
context.setSessionData("said-text", Boolean.TRUE);
|
||||
return text;
|
||||
}
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
if (context.getSessionData("said-text") == Boolean.TRUE)
|
||||
return "";
|
||||
String text = Messaging.tr(Messages.TEXT_EDITOR_START_PROMPT);
|
||||
context.setSessionData("said-text", Boolean.TRUE);
|
||||
return text;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user