From 33feac8e3b13cc539c7661d89c8258023d839f00 Mon Sep 17 00:00:00 2001 From: Malfuryent Date: Sun, 11 Nov 2018 19:04:25 +0100 Subject: [PATCH 1/2] report button: add ability to switch between 24h and 12h clock Co-authored-by: melkypie <5113962+melkypie@users.noreply.github.com> --- .../reportbutton/ReportButtonConfig.java | 10 +++++ .../reportbutton/ReportButtonPlugin.java | 38 ++++++++++++---- .../plugins/reportbutton/TimeFormat.java | 43 +++++++++++++++++++ 3 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeFormat.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonConfig.java index 7848b20a7d..e8d90f2abd 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonConfig.java @@ -40,4 +40,14 @@ public interface ReportButtonConfig extends Config { return TimeStyle.LOGIN_TIME; } + + @ConfigItem( + keyName = "switchTimeFormat", + name = "Time Format", + description = "Configures time between 12 or 24 hour time format" + ) + default TimeFormat switchTimeFormat() + { + return TimeFormat.TIME_12H; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java index d1ec6d6828..4859c877cc 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java @@ -45,6 +45,7 @@ import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.callback.ClientThread; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.ConfigChanged; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.task.Schedule; @@ -58,10 +59,9 @@ public class ReportButtonPlugin extends Plugin { private static final ZoneId UTC = ZoneId.of("UTC"); private static final ZoneId JAGEX = ZoneId.of("Europe/London"); - - private static final DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM); private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MMM. dd, yyyy"); + private DateTimeFormatter timeFormat; private Instant loginTime; private int ticksSinceLogin; private boolean ready; @@ -85,6 +85,7 @@ public class ReportButtonPlugin extends Plugin public void startUp() { clientThread.invoke(this::updateReportButtonTime); + updateTimeFormat(); } @Override @@ -134,6 +135,15 @@ public class ReportButtonPlugin extends Plugin } } + @Subscribe + public void onConfigChanged(ConfigChanged event) + { + if (event.getGroup().equals("reportButton") && event.getKey().equals("switchTimeFormat")) + { + updateTimeFormat(); + } + } + @Schedule( period = 500, unit = ChronoUnit.MILLIS @@ -199,25 +209,37 @@ public class ReportButtonPlugin extends Plugin return Integer.toString(ticksSinceLogin); } - private static String getLocalTime() + private String getLocalTime() { - return LocalTime.now().format(DATE_TIME_FORMAT); + return LocalTime.now().format(timeFormat); } - private static String getUTCTime() + private String getUTCTime() { LocalTime time = LocalTime.now(UTC); - return time.format(DATE_TIME_FORMAT); + return time.format(timeFormat); } - private static String getJagexTime() + private String getJagexTime() { LocalTime time = LocalTime.now(JAGEX); - return time.format(DATE_TIME_FORMAT); + return time.format(timeFormat); } private static String getDate() { return DATE_FORMAT.format(new Date()); } + + private void updateTimeFormat() + { + if (config.switchTimeFormat() == TimeFormat.TIME_24H) + { + timeFormat = DateTimeFormatter.ofPattern("HH:mm:ss"); + } + else + { + timeFormat = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM); + } + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeFormat.java b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeFormat.java new file mode 100644 index 0000000000..ac7ccaad91 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeFormat.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020, melky + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.reportbutton; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum TimeFormat +{ + TIME_12H("12-hour"), + TIME_24H("24-hour"); + + private final String name; + + @Override + public String toString() + { + return this.name; + } +} + From 582798148aa6864c9230ce5d19e90f343c9933b5 Mon Sep 17 00:00:00 2001 From: melkypie <5113962+melkypie@users.noreply.github.com> Date: Sat, 9 May 2020 14:00:23 +0300 Subject: [PATCH 2/2] report button: add clock tag Co-authored-by: Malfuryent --- .../client/plugins/reportbutton/ReportButtonPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java index 4859c877cc..8ad7c9d8ec 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java @@ -53,7 +53,7 @@ import net.runelite.client.task.Schedule; @PluginDescriptor( name = "Report Button", description = "Replace the text on the Report button with the current time", - tags = {"time", "utc"} + tags = {"time", "utc", "clock"} ) public class ReportButtonPlugin extends Plugin {