From d140c0080af217766cc91e3ae9b2339dfd119beb Mon Sep 17 00:00:00 2001 From: Cyborger1 <45152844+Cyborger1@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:20:01 -0500 Subject: [PATCH 1/4] Work in progress, but unlikely to pursue --- .../com/botdetector/BotDetectorConfig.java | 16 +++++++ .../com/botdetector/BotDetectorPlugin.java | 45 ++++++++++++++++--- .../events/BotDetectorPanelDeactivated.java | 33 ++++++++++++++ .../com/botdetector/ui/BotDetectorPanel.java | 7 +++ 4 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/botdetector/events/BotDetectorPanelDeactivated.java diff --git a/src/main/java/com/botdetector/BotDetectorConfig.java b/src/main/java/com/botdetector/BotDetectorConfig.java index cb06b1ac..8b72667a 100644 --- a/src/main/java/com/botdetector/BotDetectorConfig.java +++ b/src/main/java/com/botdetector/BotDetectorConfig.java @@ -52,6 +52,8 @@ public interface BotDetectorConfig extends Config String ANONYMOUS_UUID_KEY = "anonymousUUID"; String ACKNOWLEDGED_HARASSMENT_WARNING_KEY = "acknowledgedHarassmentWarning"; + String HIDE_PANEL_NAVIGATION_BUTTON_KEY = "hidePanelNavigationButton"; + int AUTO_SEND_MINIMUM_MINUTES = 5; int AUTO_SEND_MAXIMUM_MINUTES = 360; @@ -222,6 +224,20 @@ default PanelFontType panelFontType() return PanelFontType.NORMAL; } + @ConfigItem( + position = 6, + keyName = HIDE_PANEL_NAVIGATION_BUTTON_KEY, + name = "Hide Panel Navigation Button", + description = "Hides the panel navigation button on the Runelite sidebar when not in use.", + warning = "If the panel navigation button is hidden, the only way to use the plugin side panel is to use some" + + "
variation of right-click 'Predict' option or to input the ::BDOpenSidePanel command in chat.", + section = panelSection + ) + default boolean hidePanelNavigationButton() + { + return false; + } + @ConfigItem( position = 1, keyName = ADD_PREDICT_PLAYER_OPTION_KEY, diff --git a/src/main/java/com/botdetector/BotDetectorPlugin.java b/src/main/java/com/botdetector/BotDetectorPlugin.java index af3726ab..f189bc04 100644 --- a/src/main/java/com/botdetector/BotDetectorPlugin.java +++ b/src/main/java/com/botdetector/BotDetectorPlugin.java @@ -25,6 +25,7 @@ */ package com.botdetector; +import com.botdetector.events.BotDetectorPanelDeactivated; import com.botdetector.http.BotDetectorClient; import com.botdetector.http.UnauthorizedTokenException; import com.botdetector.http.ValidationException; @@ -350,7 +351,10 @@ protected void startUp() .priority(90) .build(); - clientToolbar.addNavigation(navButton); + if (!config.hidePanelNavigationButton()) + { + clientToolbar.addNavigation(navButton); + } if (config.addPredictPlayerOption() && client != null) { @@ -587,6 +591,15 @@ private void onBotDetectorPanelActivated(BotDetectorPanelActivated event) } } + @Subscribe + private void onBotDetectorPanelDeactivated(BotDetectorPanelDeactivated event) + { + if (config.hidePanelNavigationButton()) + { + clientToolbar.removeNavigation(navButton); + } + } + @Subscribe private void onConfigChanged(ConfigChanged event) { @@ -632,6 +645,16 @@ private void onConfigChanged(ConfigChanged event) case BotDetectorConfig.ONLY_SEND_AT_LOGOUT_KEY: updateTimeToAutoSend(); break; + case BotDetectorConfig.HIDE_PANEL_NAVIGATION_BUTTON_KEY: + if (config.hidePanelNavigationButton()) + { + clientToolbar.removeNavigation(navButton); + } + else + { + clientToolbar.addNavigation(navButton); + } + break; } } @@ -1088,11 +1111,8 @@ private void onWorldChanged(WorldChanged event) */ public void predictPlayer(String playerName) { - SwingUtilities.invokeLater(() -> - { - clientToolbar.openPanel(navButton); - panel.predictPlayer(playerName); - }); + openSidePanel(); + SwingUtilities.invokeLater(() -> panel.predictPlayer(playerName)); } /** @@ -1393,6 +1413,19 @@ private void toggleShowDiscordVerificationErrors() } } + /** + * Forces the side panel to open + */ + private void openSidePanel() + { + if (config.hidePanelNavigationButton()) + { + clientToolbar.addNavigation(navButton); + } + + SwingUtilities.invokeLater(() -> clientToolbar.openPanel(navButton)); + } + //endregion diff --git a/src/main/java/com/botdetector/events/BotDetectorPanelDeactivated.java b/src/main/java/com/botdetector/events/BotDetectorPanelDeactivated.java new file mode 100644 index 00000000..6d6776d9 --- /dev/null +++ b/src/main/java/com/botdetector/events/BotDetectorPanelDeactivated.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021, Ferrariic, Seltzer Bro, Cyborger1 + * 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 HOLDER 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 com.botdetector.events; + +/**s + * Event for when the {@link com.botdetector.ui.BotDetectorPanel} is deactivated. + */ +public class BotDetectorPanelDeactivated +{ +} diff --git a/src/main/java/com/botdetector/ui/BotDetectorPanel.java b/src/main/java/com/botdetector/ui/BotDetectorPanel.java index 846dec80..5662574a 100644 --- a/src/main/java/com/botdetector/ui/BotDetectorPanel.java +++ b/src/main/java/com/botdetector/ui/BotDetectorPanel.java @@ -29,6 +29,7 @@ import com.botdetector.BotDetectorPlugin; import static com.botdetector.BotDetectorPlugin.normalizeAndWrapPlayerName; import com.botdetector.events.BotDetectorPanelActivated; +import com.botdetector.events.BotDetectorPanelDeactivated; import com.botdetector.http.BotDetectorClient; import com.botdetector.model.CaseInsensitiveString; import com.botdetector.model.FeedbackValue; @@ -307,6 +308,12 @@ public void onDeactivate() isActive = false; } + @Override + public void onDeactivate() + { + eventBus.post(new BotDetectorPanelDeactivated()); + } + /** * Puts the panel in a box layout panel with a vertical pad above ({@link #SUB_PANEL_SEPARATION_HEIGHT}). * @param panel The panel. From f6a41b92a5c04d3ff3e65744811058fec18e9551 Mon Sep 17 00:00:00 2001 From: Cyborger1 <45152844+Cyborger1@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:44:46 -0500 Subject: [PATCH 2/4] Fixes and commands --- src/main/java/com/botdetector/BotDetectorConfig.java | 4 ++-- src/main/java/com/botdetector/BotDetectorPlugin.java | 4 ++++ src/main/java/com/botdetector/ui/BotDetectorPanel.java | 7 +------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/botdetector/BotDetectorConfig.java b/src/main/java/com/botdetector/BotDetectorConfig.java index 8b72667a..92499f4b 100644 --- a/src/main/java/com/botdetector/BotDetectorConfig.java +++ b/src/main/java/com/botdetector/BotDetectorConfig.java @@ -229,8 +229,8 @@ default PanelFontType panelFontType() keyName = HIDE_PANEL_NAVIGATION_BUTTON_KEY, name = "Hide Panel Navigation Button", description = "Hides the panel navigation button on the Runelite sidebar when not in use.", - warning = "If the panel navigation button is hidden, the only way to use the plugin side panel is to use some" + - "
variation of right-click 'Predict' option or to input the ::BDOpenSidePanel command in chat.", + warning = "If the panel navigation button is hidden, the only way to use the plugin side panel is to use some variation" + + "
of the right-click 'Predict' option or to input the ::BDOpenPanel or ::BDOpen command in chat.", section = panelSection ) default boolean hidePanelNavigationButton() diff --git a/src/main/java/com/botdetector/BotDetectorPlugin.java b/src/main/java/com/botdetector/BotDetectorPlugin.java index f189bc04..5852bee0 100644 --- a/src/main/java/com/botdetector/BotDetectorPlugin.java +++ b/src/main/java/com/botdetector/BotDetectorPlugin.java @@ -168,6 +168,8 @@ public class BotDetectorPlugin extends Plugin private static final String CLEAR_AUTH_TOKEN_COMMAND = COMMAND_PREFIX + "ClearToken"; private static final String TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND = COMMAND_PREFIX + "ToggleShowDiscordVerificationErrors"; private static final String TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND_ALIAS = COMMAND_PREFIX + "ToggleDVE"; + private static final String OPEN_PANEL_COMMAND = COMMAND_PREFIX + "OpenPanel"; + private static final String OPEN_PANEL_COMMAND_ALIAS = COMMAND_PREFIX + "Open"; /** Command to method map to be used in {@link #onCommandExecuted(CommandExecuted)}. **/ private final ImmutableMap> commandConsumerMap = @@ -181,6 +183,8 @@ public class BotDetectorPlugin extends Plugin .put(wrap(CLEAR_AUTH_TOKEN_COMMAND), s -> clearAuthTokenCommand()) .put(wrap(TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND), s -> toggleShowDiscordVerificationErrors()) .put(wrap(TOGGLE_SHOW_DISCORD_VERIFICATION_ERRORS_COMMAND_ALIAS), s -> toggleShowDiscordVerificationErrors()) + .put(wrap(OPEN_PANEL_COMMAND), s -> openSidePanel()) + .put(wrap(OPEN_PANEL_COMMAND_ALIAS), s -> openSidePanel()) .build(); private static final int MANUAL_FLUSH_COOLDOWN_SECONDS = 60; diff --git a/src/main/java/com/botdetector/ui/BotDetectorPanel.java b/src/main/java/com/botdetector/ui/BotDetectorPanel.java index 5662574a..cf681b7d 100644 --- a/src/main/java/com/botdetector/ui/BotDetectorPanel.java +++ b/src/main/java/com/botdetector/ui/BotDetectorPanel.java @@ -298,19 +298,14 @@ public void shutdown() @Override public void onActivate() { - eventBus.post(new BotDetectorPanelActivated()); isActive = true; + eventBus.post(new BotDetectorPanelActivated()); } @Override public void onDeactivate() { isActive = false; - } - - @Override - public void onDeactivate() - { eventBus.post(new BotDetectorPanelDeactivated()); } From 711007eeb1c183a8367798df01600f36e799dd11 Mon Sep 17 00:00:00 2001 From: Cyborger1 <45152844+Cyborger1@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:09:24 -0500 Subject: [PATCH 3/4] Don't try to add/open if panel already active --- src/main/java/com/botdetector/BotDetectorPlugin.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/botdetector/BotDetectorPlugin.java b/src/main/java/com/botdetector/BotDetectorPlugin.java index 5852bee0..4a3073ef 100644 --- a/src/main/java/com/botdetector/BotDetectorPlugin.java +++ b/src/main/java/com/botdetector/BotDetectorPlugin.java @@ -1418,10 +1418,15 @@ private void toggleShowDiscordVerificationErrors() } /** - * Forces the side panel to open + * Opens the side panel if it's not already open */ private void openSidePanel() { + if (panel.isActive()) + { + return; + } + if (config.hidePanelNavigationButton()) { clientToolbar.addNavigation(navButton); From 3f94ab82f4265ef06912afcfcf378e1e47a9b7f8 Mon Sep 17 00:00:00 2001 From: Cyborger1 <45152844+Cyborger1@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:20:05 -0500 Subject: [PATCH 4/4] Add warning about experimental feature for the self hiding button --- src/main/java/com/botdetector/BotDetectorConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/botdetector/BotDetectorConfig.java b/src/main/java/com/botdetector/BotDetectorConfig.java index 92499f4b..44fa0950 100644 --- a/src/main/java/com/botdetector/BotDetectorConfig.java +++ b/src/main/java/com/botdetector/BotDetectorConfig.java @@ -229,7 +229,8 @@ default PanelFontType panelFontType() keyName = HIDE_PANEL_NAVIGATION_BUTTON_KEY, name = "Hide Panel Navigation Button", description = "Hides the panel navigation button on the Runelite sidebar when not in use.", - warning = "If the panel navigation button is hidden, the only way to use the plugin side panel is to use some variation" + + warning = "WARNING: This feature is experimental, please report any issues on our github!" + + "

If the panel navigation button is hidden, the only way to use the plugin side panel is to use some variation" + "
of the right-click 'Predict' option or to input the ::BDOpenPanel or ::BDOpen command in chat.", section = panelSection )