Merge pull request #11516 from melkypie/report-24hclock
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -52,16 +53,15 @@ 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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2020, melky <https://github.com/melkypie>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user