From 65bc723a137c84c0ee0489767d97c252d583020f Mon Sep 17 00:00:00 2001 From: HappyPikachu Date: Mon, 12 Feb 2018 01:25:39 -0500 Subject: [PATCH] Accept seconds for stage delays, per #286 --- .../me/blackvein/quests/QuestFactory.java | 1 - .../quests/prompts/CreateStagePrompt.java | 17 ++++------ .../me/blackvein/quests/util/MiscUtil.java | 34 ------------------- 3 files changed, 7 insertions(+), 45 deletions(-) diff --git a/src/main/java/me/blackvein/quests/QuestFactory.java b/src/main/java/me/blackvein/quests/QuestFactory.java index e6717e260..ab522cb82 100644 --- a/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/src/main/java/me/blackvein/quests/QuestFactory.java @@ -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) { diff --git a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java index 69f61064a..ac226b9b0 100644 --- a/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java @@ -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); } } diff --git a/src/main/java/me/blackvein/quests/util/MiscUtil.java b/src/main/java/me/blackvein/quests/util/MiscUtil.java index 2bb13b2b4..196cad018 100644 --- a/src/main/java/me/blackvein/quests/util/MiscUtil.java +++ b/src/main/java/me/blackvein/quests/util/MiscUtil.java @@ -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);