mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-21 15:01:19 +01:00
+ Added new way of entering time (delays).
* Changed colors of a few messages.
This commit is contained in:
parent
1935030a83
commit
aad9022ad9
@ -2,7 +2,9 @@ package me.blackvein.quests;
|
||||
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
|
||||
import me.blackvein.quests.util.ColorUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@ -11,13 +13,16 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import me.blackvein.quests.prompts.RequirementsPrompt;
|
||||
import me.blackvein.quests.prompts.RewardsPrompt;
|
||||
import me.blackvein.quests.prompts.StagesPrompt;
|
||||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
@ -839,7 +844,7 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private class RedoDelayPrompt extends NumericPrompt {
|
||||
private class RedoDelayPrompt extends StringPrompt {
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
@ -849,19 +854,31 @@ public class QuestFactory implements ConversationAbandonedListener, ColorUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||
|
||||
if (input.longValue() < -1) {
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
|
||||
return new CreateMenuPrompt();
|
||||
}
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(CK.Q_REDO_DELAY, null);
|
||||
}
|
||||
long delay = -1;
|
||||
try {
|
||||
delay = Long.parseLong(input);
|
||||
} catch (NumberFormatException e) {
|
||||
delay = MiscUtil.getTimeFromString(input);
|
||||
}
|
||||
|
||||
if (delay < -1) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questEditorPositiveAmount"));
|
||||
} else if (input.longValue() == 0) {
|
||||
} else if (delay == 0) {
|
||||
context.setSessionData(CK.Q_REDO_DELAY, null);
|
||||
} else if (input.longValue() != -1) {
|
||||
context.setSessionData(CK.Q_REDO_DELAY, input.longValue());
|
||||
}
|
||||
} else if (delay != -1) {
|
||||
context.setSessionData(CK.Q_REDO_DELAY, delay);
|
||||
}
|
||||
|
||||
return new CreateMenuPrompt();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SavePrompt extends StringPrompt {
|
||||
|
@ -3,6 +3,7 @@ package me.blackvein.quests.prompts;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import me.ThaH3lper.com.Mobs.EpicMobs;
|
||||
import me.blackvein.quests.util.ColorUtil;
|
||||
import me.blackvein.quests.Event;
|
||||
@ -12,8 +13,10 @@ import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
import net.aufdemrand.denizen.scripts.ScriptRegistry;
|
||||
import net.citizensnpcs.api.CitizensPlugin;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -3807,35 +3810,39 @@ public class CreateStagePrompt extends FixedSetPrompt implements ColorUtil {
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
|
||||
Player player = (Player) context.getForWhom();
|
||||
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
|
||||
|
||||
long l;
|
||||
|
||||
try {
|
||||
|
||||
l = Long.parseLong(input);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
player.sendMessage(YELLOW + Lang.get("stageEditorNoNumber"));
|
||||
return new DelayPrompt();
|
||||
}
|
||||
|
||||
|
||||
if (l < 1000) {
|
||||
player.sendMessage(YELLOW + Lang.get("stageEditorInvalidDelay"));
|
||||
return new DelayPrompt();
|
||||
} else {
|
||||
context.setSessionData(pref + CK.S_DELAY, l);
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
}
|
||||
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(pref + CK.S_DELAY, null);
|
||||
player.sendMessage(YELLOW + "Delay cleared.");
|
||||
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
}
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(pref + CK.S_DELAY, null);
|
||||
player.sendMessage(GREEN + "Delay cleared.");
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
}
|
||||
|
||||
|
||||
long l;
|
||||
|
||||
try {
|
||||
|
||||
l = Long.parseLong(input);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
//returns -1 if incorrect input
|
||||
l = MiscUtil.getTimeFromString(input);
|
||||
|
||||
if (l == -1) {
|
||||
player.sendMessage(RED + Lang.get("stageEditorNoNumber"));
|
||||
return new DelayPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
if (l < 1000) {
|
||||
player.sendMessage(RED + Lang.get("stageEditorInvalidDelay"));
|
||||
return new DelayPrompt();
|
||||
} else {
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
context.setSessionData(pref + CK.S_DELAY, l);
|
||||
return new CreateStagePrompt(stageNum, questFactory, citizens);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,4 +17,42 @@ public class MiscUtil {
|
||||
|
||||
}
|
||||
|
||||
//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 * 86400000;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user