mirror of
https://github.com/PikaMug/Quests.git
synced 2024-12-01 07:03:55 +01:00
NEW date/time Planner section, part 3, #93
This commit is contained in:
parent
7405d4b7f4
commit
e793661a3a
@ -1,8 +1,12 @@
|
|||||||
package me.blackvein.quests.prompts;
|
package me.blackvein.quests.prompts;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import me.blackvein.quests.Quests;
|
||||||
import me.blackvein.quests.util.Lang;
|
import me.blackvein.quests.util.Lang;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -13,10 +17,12 @@ import org.bukkit.conversations.StringPrompt;
|
|||||||
|
|
||||||
public class DateTimePrompt extends FixedSetPrompt {
|
public class DateTimePrompt extends FixedSetPrompt {
|
||||||
|
|
||||||
|
Quests quests;
|
||||||
final Prompt oldPrompt;
|
final Prompt oldPrompt;
|
||||||
|
|
||||||
public DateTimePrompt(Prompt old) {
|
public DateTimePrompt(Quests plugin, Prompt old) {
|
||||||
super("0", "1", "2", "3", "4", "5", "6", "7", "8");
|
super("0", "1", "2", "3", "4", "5", "6", "7", "8");
|
||||||
|
quests = plugin;
|
||||||
oldPrompt = old;
|
oldPrompt = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,33 +30,49 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
public String getPromptText(ConversationContext cc) {
|
public String getPromptText(ConversationContext cc) {
|
||||||
String menu = ChatColor.YELLOW + Lang.get("dateTimeTitle") + "\n";
|
String menu = ChatColor.YELLOW + Lang.get("dateTimeTitle") + "\n";
|
||||||
String dateData = "";
|
String dateData = "";
|
||||||
if (cc.getSessionData("tempDay") != null) {
|
Calendar cal = Calendar.getInstance();
|
||||||
dateData += (String) cc.getSessionData("tempDay") + "/";
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
|
||||||
|
if (cc.getSessionData("tempDay") == null) {
|
||||||
|
cc.setSessionData("tempDay", cal.get(Calendar.DAY_OF_MONTH));
|
||||||
}
|
}
|
||||||
if (cc.getSessionData("tempMonth") != null) {
|
if (cc.getSessionData("tempMonth") == null) {
|
||||||
dateData += (String) cc.getSessionData("tempMonth") + "/";
|
cc.setSessionData("tempMonth", cal.get(Calendar.MONTH));
|
||||||
}
|
}
|
||||||
if (cc.getSessionData("tempYear") != null) {
|
if (cc.getSessionData("tempYear") == null) {
|
||||||
dateData += (String) cc.getSessionData("tempYear") + " ";
|
cc.setSessionData("tempYear", cal.get(Calendar.YEAR));
|
||||||
}
|
}
|
||||||
if (cc.getSessionData("tempHour") != null) {
|
|
||||||
dateData += (String) cc.getSessionData("tempHour") + ":";
|
if (cc.getSessionData("tempHour") == null) {
|
||||||
|
cc.setSessionData("tempHour", cal.get(Calendar.HOUR_OF_DAY));
|
||||||
}
|
}
|
||||||
if (cc.getSessionData("tempMinute") != null) {
|
if (cc.getSessionData("tempMinute") == null) {
|
||||||
dateData += (String) cc.getSessionData("tempMinute") + ":";
|
cc.setSessionData("tempMinute", cal.get(Calendar.MINUTE));
|
||||||
}
|
}
|
||||||
if (cc.getSessionData("tempSecond") != null) {
|
if (cc.getSessionData("tempSecond") == null) {
|
||||||
dateData += (String) cc.getSessionData("tempSecond") + " ";
|
cc.setSessionData("tempSecond", cal.get(Calendar.SECOND));
|
||||||
}
|
}
|
||||||
|
cal.set((Integer) cc.getSessionData("tempYear"), (Integer) cc.getSessionData("tempMonth"), (Integer) cc.getSessionData("tempDay"),
|
||||||
|
(Integer) cc.getSessionData("tempHour"), (Integer) cc.getSessionData("tempMinute"), (Integer) cc.getSessionData("tempSecond"));
|
||||||
|
dateData += ChatColor.DARK_AQUA + dateFormat.format(cal.getTime()) + " ";
|
||||||
|
dateData += ChatColor.AQUA + timeFormat.format(cal.getTime()) + " ";
|
||||||
|
|
||||||
if (cc.getSessionData("tempZone") == null) {
|
if (cc.getSessionData("tempZone") == null) {
|
||||||
cc.setSessionData("tempZone", TimeZone.getDefault().getID());
|
cc.setSessionData("tempZone", cal.getTimeZone().getID());
|
||||||
}
|
}
|
||||||
TimeZone tz = TimeZone.getTimeZone((String) cc.getSessionData("tempZone"));
|
TimeZone tz = TimeZone.getTimeZone((String) cc.getSessionData("tempZone"));
|
||||||
//TODO - CHANGE CURRENT SYSTEM TIME TO USER-SPECIFIED DATE
|
cal.setTimeZone(tz);
|
||||||
dateData += tz.getOffset(System.currentTimeMillis() / 1000 / 60) + " (" + tz.getID() + ")" + " test - " + tz.getDisplayName(Locale.FRENCH);
|
String[] iso = quests.lang.iso.split("-");
|
||||||
|
Locale loc = new Locale(iso[0], iso[1]);
|
||||||
|
Double hour = (double) (cal.getTimeZone().getRawOffset() / 60 / 60 / 1000);
|
||||||
|
String[] sep = String.valueOf(hour).replace("-", "").split("\\.");
|
||||||
|
DecimalFormat zoneFormat = new DecimalFormat("00");
|
||||||
|
dateData += ChatColor.LIGHT_PURPLE + "UTC" + (hour < 0 ? "-":"+") + zoneFormat.format(Integer.valueOf(sep[0])) + ":" + zoneFormat.format(Integer.valueOf(sep[1]))
|
||||||
|
+ ChatColor.RED + " (" + cal.getTimeZone().getDisplayName(loc) + ")";
|
||||||
if (dateData != null) {
|
if (dateData != null) {
|
||||||
menu += dateData + "\n";
|
menu += dateData + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "1. " + ChatColor.RESET + "" + ChatColor.GOLD + Lang.get("timeDay") + "\n";
|
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "1. " + ChatColor.RESET + "" + ChatColor.GOLD + Lang.get("timeDay") + "\n";
|
||||||
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "2. " + ChatColor.RESET + "" + ChatColor.GOLD + Lang.get("timeMonth") + "\n";
|
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "2. " + ChatColor.RESET + "" + ChatColor.GOLD + Lang.get("timeMonth") + "\n";
|
||||||
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "3. " + ChatColor.RESET + "" + ChatColor.GOLD + Lang.get("timeYear") + "\n";
|
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "3. " + ChatColor.RESET + "" + ChatColor.GOLD + Lang.get("timeYear") + "\n";
|
||||||
@ -125,14 +147,14 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
return new DayPrompt();
|
return new DayPrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempDay", Integer.parseInt(input));
|
cc.setSessionData("tempDay", Integer.parseInt(input));
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new DayPrompt();
|
return new DayPrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,15 +176,15 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
.replace("<least>", "1").replace("<greatest>", "12"));
|
.replace("<least>", "1").replace("<greatest>", "12"));
|
||||||
return new MonthPrompt();
|
return new MonthPrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempMonth", Integer.parseInt(input));
|
cc.setSessionData("tempMonth", Integer.parseInt(input) - 1);
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new MonthPrompt();
|
return new MonthPrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,14 +207,14 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
return new YearPrompt();
|
return new YearPrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempYear", Integer.parseInt(input));
|
cc.setSessionData("tempYear", Integer.parseInt(input));
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new YearPrompt();
|
return new YearPrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,14 +237,14 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
return new HourPrompt();
|
return new HourPrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempHour", Integer.parseInt(input));
|
cc.setSessionData("tempHour", Integer.parseInt(input));
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new HourPrompt();
|
return new HourPrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,14 +267,14 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
return new MinutePrompt();
|
return new MinutePrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempMinute", Integer.parseInt(input));
|
cc.setSessionData("tempMinute", Integer.parseInt(input));
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new MinutePrompt();
|
return new MinutePrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,14 +297,14 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
return new SecondPrompt();
|
return new SecondPrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempSecond", Integer.parseInt(input));
|
cc.setSessionData("tempSecond", Integer.parseInt(input));
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new SecondPrompt();
|
return new SecondPrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,21 +320,31 @@ public class DateTimePrompt extends FixedSetPrompt {
|
|||||||
public Prompt acceptInput(ConversationContext cc, String input) {
|
public Prompt acceptInput(ConversationContext cc, String input) {
|
||||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||||
try {
|
try {
|
||||||
int amt = Integer.parseInt(input.replaceAll("UTC", ""));
|
double amt = Double.parseDouble(input.replaceAll("UTC", "").replace(":", "."));
|
||||||
if (amt < -12 || amt > 14) {
|
if (amt < -12.0 || amt > 14.0) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
|
||||||
.replace("<least>", "-12").replace("<greatest>", "14"));
|
.replace("<least>", "-12:00").replace("<greatest>", "14:00"));
|
||||||
return new ZonePrompt();
|
return new ZonePrompt();
|
||||||
} else {
|
} else {
|
||||||
cc.setSessionData("tempZone", Integer.parseInt(input));
|
String[] t = TimeZone.getAvailableIDs((int) Math.round(amt * 60.0 * 60.0 * 1000.0));
|
||||||
return new DateTimePrompt(oldPrompt);
|
//TODO - let user choose
|
||||||
|
for (String output : t) {
|
||||||
|
System.out.println("zone id= " + output);
|
||||||
|
}
|
||||||
|
if (t.length > 0) {
|
||||||
|
cc.setSessionData("tempZone", t[0]);
|
||||||
|
} else {
|
||||||
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
|
quests.getLogger().severe("Unable to get time zone for converted offset " + input);
|
||||||
|
}
|
||||||
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
|
||||||
return new ZonePrompt();
|
return new ZonePrompt();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new DateTimePrompt(oldPrompt);
|
return new DateTimePrompt(quests, oldPrompt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,10 @@ public class PlannerPrompt extends FixedSetPrompt {
|
|||||||
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
|
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
|
||||||
if (input.equalsIgnoreCase("1")) {
|
if (input.equalsIgnoreCase("1")) {
|
||||||
//return new StartPrompt();
|
//return new StartPrompt();
|
||||||
return new DateTimePrompt(PlannerPrompt.this);
|
return new DateTimePrompt(quests, PlannerPrompt.this);
|
||||||
} else if (input.equalsIgnoreCase("2")) {
|
} else if (input.equalsIgnoreCase("2")) {
|
||||||
//return new EndPrompt();
|
//return new EndPrompt();
|
||||||
return new DateTimePrompt(PlannerPrompt.this);
|
return new DateTimePrompt(quests, PlannerPrompt.this);
|
||||||
} else if (input.equalsIgnoreCase("3")) {
|
} else if (input.equalsIgnoreCase("3")) {
|
||||||
return new RepeatPrompt();
|
return new RepeatPrompt();
|
||||||
} else if (input.equalsIgnoreCase("4")) {
|
} else if (input.equalsIgnoreCase("4")) {
|
||||||
|
@ -580,7 +580,7 @@ dateCreateEnterYear: "Enter a year (max. 9999), <cancel>"
|
|||||||
dateCreateEnterHour: "Enter an hour (max. 23), <cancel>"
|
dateCreateEnterHour: "Enter an hour (max. 23), <cancel>"
|
||||||
dateCreateEnterMinute: "Enter a minute (max. 59), <cancel>"
|
dateCreateEnterMinute: "Enter a minute (max. 59), <cancel>"
|
||||||
dateCreateEnterSecond: "Enter a second (max. 59), <cancel>"
|
dateCreateEnterSecond: "Enter a second (max. 59), <cancel>"
|
||||||
dateCreateEnterZone: "Enter a UTC time zone (max. 14), <cancel>"
|
dateCreateEnterZone: "Enter a UTC time offset (max. 14), <cancel>"
|
||||||
dateCreateNoYearAmount: "You must set a year first!"
|
dateCreateNoYearAmount: "You must set a year first!"
|
||||||
questTitle: "-- <quest> --"
|
questTitle: "-- <quest> --"
|
||||||
questObjectivesTitle: "---(<quest>)---"
|
questObjectivesTitle: "---(<quest>)---"
|
||||||
|
Loading…
Reference in New Issue
Block a user