mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-14 22:55:54 +01:00
Accept seconds for stage delays, per #286
This commit is contained in:
parent
ee986cbf77
commit
65bc723a13
@ -744,7 +744,6 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
delay = i * 1000;
|
||||
} catch (NumberFormatException e) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.ITALIC + "" + ChatColor.RED + input + ChatColor.RESET + ChatColor.RED + " " + Lang.get("stageEditorInvalidNumber"));
|
||||
// delay = MiscUtil.getTimeFromString(input);
|
||||
return new RedoDelayPrompt();
|
||||
}
|
||||
if (delay < -1) {
|
||||
|
@ -3575,22 +3575,19 @@ public class CreateStagePrompt extends FixedSetPrompt {
|
||||
player.sendMessage(ChatColor.GREEN + Lang.get("stageEditorDelayCleared"));
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
}
|
||||
long l;
|
||||
long stageDelay;
|
||||
try {
|
||||
l = Long.parseLong(input);
|
||||
int i = Integer.parseInt(input);
|
||||
stageDelay = i * 1000;
|
||||
} catch (NumberFormatException e) {
|
||||
// returns -1 if incorrect input
|
||||
l = MiscUtil.getTimeFromString(input);
|
||||
if (l == -1) {
|
||||
player.sendMessage(ChatColor.RED + Lang.get("stageEditorNoNumber"));
|
||||
return new DelayPrompt();
|
||||
}
|
||||
player.sendMessage(ChatColor.RED + Lang.get("stageEditorNoNumber"));
|
||||
return new DelayPrompt();
|
||||
}
|
||||
if (l < 1000) {
|
||||
if (stageDelay < 1000) {
|
||||
player.sendMessage(ChatColor.RED + Lang.get("stageEditorInvalidDelay"));
|
||||
return new DelayPrompt();
|
||||
} else {
|
||||
context.setSessionData(pref + CK.S_DELAY, l);
|
||||
context.setSessionData(pref + CK.S_DELAY, stageDelay);
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
}
|
||||
}
|
||||
|
@ -30,40 +30,6 @@ public class MiscUtil {
|
||||
return s2 + s;
|
||||
}
|
||||
|
||||
// Time: 7d 24h 5m 10s 20ms
|
||||
public static long getTimeFromString(String string) {
|
||||
// if it returns -1 then the string is incorrect.
|
||||
long timeMilliSeconds = -1;
|
||||
// replace 2 or more spaces with one space.
|
||||
string = string.replaceAll("[ ]{2,}", " ");
|
||||
String[] dates = string.split(" ");
|
||||
for (String date : dates) {
|
||||
String num = date.split("[a-zA-Z]+")[0];
|
||||
String type = date.split("[0-9]+")[1];
|
||||
int t = 0;
|
||||
try {
|
||||
t = Math.abs(Integer.parseInt(num));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
if (type.equals("d")) {
|
||||
timeMilliSeconds += t * 86400000L;
|
||||
} else if (type.equals("h")) {
|
||||
timeMilliSeconds += t * 3600000;
|
||||
} else if (type.equals("m")) {
|
||||
timeMilliSeconds += t * 60000;
|
||||
} else if (type.equals("s")) {
|
||||
timeMilliSeconds += t * 1000;
|
||||
} else if (type.equals("ms")) {
|
||||
timeMilliSeconds += t;
|
||||
}
|
||||
}
|
||||
// To balance the -1 at the beginning.
|
||||
if (timeMilliSeconds > -1) {
|
||||
timeMilliSeconds++;
|
||||
}
|
||||
return timeMilliSeconds;
|
||||
}
|
||||
|
||||
public static String getProperMobName(EntityType type) {
|
||||
String name = type.name().toLowerCase();
|
||||
name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
|
||||
|
Loading…
Reference in New Issue
Block a user