From 3fbe1915e3370fbf5e5c26b317f7895a4c3a0e9d Mon Sep 17 00:00:00 2001 From: Cyborger1 <45152844+Cyborger1@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:00:15 -0500 Subject: [PATCH] Add config to set panel nav button priority --- README.md | 1 + .../com/botdetector/BotDetectorConfig.java | 15 +++++++++++ .../com/botdetector/BotDetectorPlugin.java | 25 ++++++++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8a02b827..4620981f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Identifies bots by sending nearby players' information to a third-party machine | Panel Settings | Show Feedback Textbox | Adds a textbox to the prediction feedback panel, so you can explain your choice in up to 250 characters. Make sure you type your feedback *before* you make your choice! | | Panel Settings | Panel Default Stats Tab | Sets panel default stats tab when the Plugin turns on. | | Panel Settings | Panel Font Size | Sets the font size of most of the Plugin's Panel elements. | +| Panel Settings | Panel Button Priority | Sets the priority level of the panel navigation button, changing its placement in the sidebar. Higher means further down the list. | | 'Predict' Settings | Right-click 'Predict' Players | Allows you to right-click predict players, instead of having to type their name in the Plugin's panel manually. | | 'Predict' Settings | 'Predict' on Right-click 'Report' | If you right-click Report someone via Jagex's official in-game report system, the player will be automatically predicted in the Plugin's Panel. | | 'Predict' Settings | 'Predict' Copy Name to Clipboard | Copies the predicted player's name to your clipboard when right-click predicting. | diff --git a/src/main/java/com/botdetector/BotDetectorConfig.java b/src/main/java/com/botdetector/BotDetectorConfig.java index 96f5368b..daae9006 100644 --- a/src/main/java/com/botdetector/BotDetectorConfig.java +++ b/src/main/java/com/botdetector/BotDetectorConfig.java @@ -49,6 +49,7 @@ public interface BotDetectorConfig extends Config String SHOW_FEEDBACK_TEXTBOX = "showFeedbackTextbox"; String SHOW_DISCORD_VERIFICATION_ERRORS = "showDiscordVerificationErrors"; String ANONYMOUS_UUID_KEY = "anonymousUUID"; + String PANEL_NAVIGATION_BUTTON_PRIORITY_KEY = "panelNavigationButtonPriority"; int AUTO_SEND_MINIMUM_MINUTES = 5; int AUTO_SEND_MAXIMUM_MINUTES = 360; @@ -195,6 +196,20 @@ default PanelFontType panelFontType() return PanelFontType.NORMAL; } + @ConfigItem( + position = 6, + keyName = PANEL_NAVIGATION_BUTTON_PRIORITY_KEY, + name = "Panel Button Priority", + description = "Sets the priority level of the panel navigation button, changing its placement in the sidebar." + + "
A higher number means the button will appear further down the list.", + section = panelSection + ) + @Range(max = 10000) + default int panelNavigationButtonPriority() + { + return 90; + } + @ConfigItem( position = 1, keyName = ADD_PREDICT_OPTION_KEY, diff --git a/src/main/java/com/botdetector/BotDetectorPlugin.java b/src/main/java/com/botdetector/BotDetectorPlugin.java index fc59b5fd..a9a01bd7 100644 --- a/src/main/java/com/botdetector/BotDetectorPlugin.java +++ b/src/main/java/com/botdetector/BotDetectorPlugin.java @@ -67,6 +67,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.regex.Pattern; import javax.swing.JEditorPane; import javax.swing.JOptionPane; @@ -300,6 +301,15 @@ BotDetectorConfig provideConfig(ConfigManager configManager) @Getter private final Map flaggedPlayers = new ConcurrentHashMap<>(); + private final BufferedImage navButtonIcon = ImageUtil.loadImageResource(getClass(), "bot-icon.png"); + private final Supplier navButtonSupplier = () -> + NavigationButton.builder() + .panel(panel) + .tooltip("Bot Detector") + .icon(navButtonIcon) + .priority(config.panelNavigationButtonPriority()) + .build(); + @Override protected void startUp() { @@ -342,15 +352,7 @@ protected void startUp() processCurrentWorld(); - final BufferedImage icon = ImageUtil.loadImageResource(getClass(), "bot-icon.png"); - - navButton = NavigationButton.builder() - .panel(panel) - .tooltip("Bot Detector") - .icon(icon) - .priority(90) - .build(); - + navButton = navButtonSupplier.get(); clientToolbar.addNavigation(navButton); if (config.addPredictOption() && client != null) @@ -627,6 +629,11 @@ private void onConfigChanged(ConfigChanged event) case BotDetectorConfig.ONLY_SEND_AT_LOGOUT_KEY: updateTimeToAutoSend(); break; + case BotDetectorConfig.PANEL_NAVIGATION_BUTTON_PRIORITY_KEY: + clientToolbar.removeNavigation(navButton); + navButton = navButtonSupplier.get(); + clientToolbar.addNavigation(navButton); + break; } }