Accept seconds for stage delays, per #286

This commit is contained in:
HappyPikachu 2018-02-12 01:25:39 -05:00
parent ee986cbf77
commit 65bc723a13
3 changed files with 7 additions and 45 deletions

View File

@ -744,7 +744,6 @@ public class QuestFactory implements ConversationAbandonedListener {
delay = i * 1000; delay = i * 1000;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.ITALIC + "" + ChatColor.RED + input + ChatColor.RESET + ChatColor.RED + " " + Lang.get("stageEditorInvalidNumber")); context.getForWhom().sendRawMessage(ChatColor.ITALIC + "" + ChatColor.RED + input + ChatColor.RESET + ChatColor.RED + " " + Lang.get("stageEditorInvalidNumber"));
// delay = MiscUtil.getTimeFromString(input);
return new RedoDelayPrompt(); return new RedoDelayPrompt();
} }
if (delay < -1) { if (delay < -1) {

View File

@ -3575,22 +3575,19 @@ public class CreateStagePrompt extends FixedSetPrompt {
player.sendMessage(ChatColor.GREEN + Lang.get("stageEditorDelayCleared")); player.sendMessage(ChatColor.GREEN + Lang.get("stageEditorDelayCleared"));
return new CreateStagePrompt(stageNum, questFactory, citizens); return new CreateStagePrompt(stageNum, questFactory, citizens);
} }
long l; long stageDelay;
try { try {
l = Long.parseLong(input); int i = Integer.parseInt(input);
stageDelay = i * 1000;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// returns -1 if incorrect input player.sendMessage(ChatColor.RED + Lang.get("stageEditorNoNumber"));
l = MiscUtil.getTimeFromString(input); return new DelayPrompt();
if (l == -1) {
player.sendMessage(ChatColor.RED + Lang.get("stageEditorNoNumber"));
return new DelayPrompt();
}
} }
if (l < 1000) { if (stageDelay < 1000) {
player.sendMessage(ChatColor.RED + Lang.get("stageEditorInvalidDelay")); player.sendMessage(ChatColor.RED + Lang.get("stageEditorInvalidDelay"));
return new DelayPrompt(); return new DelayPrompt();
} else { } else {
context.setSessionData(pref + CK.S_DELAY, l); context.setSessionData(pref + CK.S_DELAY, stageDelay);
return new CreateStagePrompt(stageNum, questFactory, citizens); return new CreateStagePrompt(stageNum, questFactory, citizens);
} }
} }

View File

@ -30,40 +30,6 @@ public class MiscUtil {
return s2 + s; 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) { public static String getProperMobName(EntityType type) {
String name = type.name().toLowerCase(); String name = type.name().toLowerCase();
name = Character.toUpperCase(name.charAt(0)) + name.substring(1); name = Character.toUpperCase(name.charAt(0)) + name.substring(1);