diff --git a/runelite-api/src/main/java/net/runelite/api/GameState.java b/runelite-api/src/main/java/net/runelite/api/GameState.java index cb7e70fbde..f43a707f82 100644 --- a/runelite-api/src/main/java/net/runelite/api/GameState.java +++ b/runelite-api/src/main/java/net/runelite/api/GameState.java @@ -32,6 +32,7 @@ public enum GameState LOGGING_IN(20), LOADING(25), LOGGED_IN(30), + CONNECTION_LOST(40), HOPPING(45); private final int state; diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java index 24593e652e..58020c626a 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetID.java @@ -157,6 +157,7 @@ class WidgetID static class Chatbox { static final int CHATBOX_MESSAGES = 29; + static final int CHATBOX_REPORT_TEXT = 28; static final int CHATBOX_BUTTONS = 1; } diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java index bfbed77142..53f52ed810 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetInfo.java @@ -127,8 +127,8 @@ public enum WidgetInfo CHATBOX(WidgetID.CHATBOX_GROUP_ID, 0), CHATBOX_MESSAGES(WidgetID.CHATBOX_GROUP_ID, WidgetID.Chatbox.CHATBOX_MESSAGES), - CHATBOX_BUTTONS(WidgetID.CHATBOX_GROUP_ID, WidgetID.Chatbox.CHATBOX_BUTTONS); - + CHATBOX_BUTTONS(WidgetID.CHATBOX_GROUP_ID, WidgetID.Chatbox.CHATBOX_BUTTONS), + CHATBOX_REPORT_TEXT(WidgetID.CHATBOX_GROUP_ID, WidgetID.Chatbox.CHATBOX_REPORT_TEXT); private final int groupId; private final int childId; 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 new file mode 100644 index 0000000000..5a62357aa0 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonConfig.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018, Cameron + * 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 net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup( + keyName = "reportButton", + name = "Report Button Utils", + description = "Configuration for report button" +) +public interface ReportButtonConfig extends Config +{ + @ConfigItem( + keyName = "time", + name = "Display Options", + description = "Configures what text the report button shows." + ) + default TimeStyle time() + { + return TimeStyle.LOGIN_TIME; + } +} 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 new file mode 100644 index 0000000000..2b00345015 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/ReportButtonPlugin.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2018, Cameron + * 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 com.google.common.eventbus.Subscribe; +import com.google.inject.Provides; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.time.temporal.ChronoUnit; +import javax.inject.Inject; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Client; +import net.runelite.api.GameState; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.events.GameStateChanged; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.task.Schedule; + +@PluginDescriptor( + name = "Report Button Utilities" +) +@Slf4j +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 Instant loginTime; + private boolean ready; + + @Inject + Client client; + + @Inject + ReportButtonConfig config; + + @Provides + ReportButtonConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(ReportButtonConfig.class); + } + + @Subscribe + public void onGameStateChange(GameStateChanged event) + { + GameState state = event.getGameState(); + + switch (state) + { + case LOGGING_IN: + case HOPPING: + case CONNECTION_LOST: + ready = true; + break; + case LOGGED_IN: + if (ready) + { + loginTime = Instant.now(); + ready = false; + } + break; + } + } + + @Schedule( + period = 1, + unit = ChronoUnit.SECONDS + ) + public void updateReportButtonTime() + { + if (client.getGameState() != GameState.LOGGED_IN) + { + return; + } + + Widget reportButton = client.getWidget(WidgetInfo.CHATBOX_REPORT_TEXT); + if (reportButton == null) + { + return; + } + + switch (config.time()) + { + case UTC: + reportButton.setText(getUTCTime()); + break; + case JAGEX: + reportButton.setText(getJagexTime()); + break; + case LOCAL_TIME: + reportButton.setText(getLocalTime()); + break; + case LOGIN_TIME: + reportButton.setText(getLoginTime()); + break; + case OFF: + reportButton.setText("Report"); + break; + } + } + + public String getLocalTime() + { + return LocalTime.now().format(DATE_TIME_FORMAT); + } + + public String getLoginTime() + { + if (loginTime == null) + { + return "Report"; + } + + Duration duration = Duration.between(loginTime, Instant.now()); + LocalTime time = LocalTime.ofSecondOfDay(duration.getSeconds()); + return time.format(DateTimeFormatter.ofPattern("HH:mm:ss")); + } + + public String getUTCTime() + { + LocalTime time = LocalTime.now(UTC); + return time.format(DATE_TIME_FORMAT); + } + + public String getJagexTime() + { + LocalTime time = LocalTime.now(JAGEX); + return time.format(DATE_TIME_FORMAT); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeStyle.java b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeStyle.java new file mode 100644 index 0000000000..97aa419247 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/reportbutton/TimeStyle.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Cameron + * 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; + +public enum TimeStyle +{ + OFF("Off"), + LOGIN_TIME("Login Timer"), + UTC("UTC Time"), + JAGEX("Jagex HQ Time"), + LOCAL_TIME("Local Time"); + + private final String name; + + TimeStyle(String name) + { + this.name = name; + } + + @Override + public String toString() + { + return name; + } + +}