From 2b61a17447f8e3bec0ea86dd8674f9bcc032a1f8 Mon Sep 17 00:00:00 2001 From: Scott Burns Date: Thu, 16 May 2019 01:01:29 +0200 Subject: [PATCH] Refactor PluginSorter --- .../pluginsorter/PluginSorterConfig.java | 111 ++++++------- .../pluginsorter/PluginSorterPlugin.java | 154 ++++++++++-------- 2 files changed, 138 insertions(+), 127 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterConfig.java index cb06dee1c2..45d15be0cc 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterConfig.java @@ -24,72 +24,69 @@ */ package net.runelite.client.plugins.pluginsorter; +import java.awt.Color; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; -import java.awt.*; - @ConfigGroup("pluginsorter") -public interface PluginSorterConfig extends Config { +public interface PluginSorterConfig extends Config +{ + boolean pluginsHidden = false; - Color rlDefault = new Color(250, 155, 23); + @ConfigItem( + position = 0, + keyName = "hidePlugins", + name = "Hide Plugins", + description = "Hides all 3rd party plugins if checked" + ) + default boolean hidePlugins() + { + return pluginsHidden; + } - boolean pluginsHidden = false; + @ConfigItem( + position = 1, + keyName = "externalColor", + name = "External color", + description = "Configure the color of external plugins" + ) + default Color externalColor() + { + return Color.MAGENTA; + } - @ConfigItem( - position = 0, - keyName = "hidePlugins", - name = "Hide Plugins", - description = "Hides all 3rd party plugins if checked" - ) - default boolean hidePlugins() - { - return pluginsHidden; - } + @ConfigItem( + position = 2, + keyName = "pvmColor", + name = "PVM color", + description = "Configure the color of PVM related plugins" + ) + default Color pvmColor() + { + return Color.GREEN; + } - @ConfigItem( - position = 1, - keyName = "externalColor", - name = "External color", - description = "Configure the color of external plugins" - ) - default Color externalColor() - { - return Color.MAGENTA; - } + @ConfigItem( + position = 3, + keyName = "pvpColor", + name = "PVP color", + description = "Configure the color of PVP related plugins" + ) + default Color pvpColor() + { + return Color.RED; + } - @ConfigItem( - position = 2, - keyName = "pvmColor", - name = "PVM color", - description = "Configure the color of PVM related plugins" - ) - default Color pvmColor() - { - return Color.GREEN; - } - - @ConfigItem( - position = 3, - keyName = "pvpColor", - name = "PVP color", - description = "Configure the color of PVP related plugins" - ) - default Color pvpColor() - { - return Color.RED; - } - - @ConfigItem( - position = 4, - keyName = "utilityColor", - name = "Utility color", - description = "Configure the color of utility related plugins" - ) - default Color utilityColor() - { - return Color.CYAN; - } + @ConfigItem( + position = 4, + keyName = "utilityColor", + name = "Utility color", + description = "Configure the color of utility related plugins" + ) + default Color utilityColor() + { + return Color.CYAN; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterPlugin.java index 6c2aa3e864..2dd3156965 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pluginsorter/PluginSorterPlugin.java @@ -25,10 +25,14 @@ package net.runelite.client.plugins.pluginsorter; import com.google.inject.Provides; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import javax.inject.Inject; import net.runelite.api.GameState; import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.GameStateChanged; -import net.runelite.client.config.ConfigItemDescriptor; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; @@ -37,70 +41,76 @@ import net.runelite.client.plugins.PluginType; import net.runelite.client.plugins.config.ConfigPanel; import net.runelite.client.plugins.config.PluginListItem; -import javax.inject.Inject; -import java.awt.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - @PluginDescriptor( - name = "Plugin Organizer", - description = "Hides and colors 3rd party plugins for better control", - tags = {"plugins","organizer"}, - type = PluginType.PLUGIN_ORGANIZER + name = "Plugin Organizer", + description = "Hides and colors 3rd party plugins for better control", + tags = {"plugins", "organizer"}, + type = PluginType.PLUGIN_ORGANIZER ) -public class PluginSorterPlugin extends Plugin { +public class PluginSorterPlugin extends Plugin +{ + //Cache the hidden plugins + private static List removedPlugins = new ArrayList<>(); - //Cache the hidden plugins - public static List removedPlugins = new ArrayList<>(); + @Inject + private PluginSorterConfig config; - @Inject - private PluginSorterConfig config; + @Provides + PluginSorterConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(PluginSorterConfig.class); + } - @Provides - PluginSorterConfig provideConfig(ConfigManager configManager) - { - return configManager.getConfig(PluginSorterConfig.class); - } + @Override + protected void startUp() throws Exception + { + updateColors(); + } - @Override - protected void startUp() throws Exception - { - updateColors(); - } + @Override + protected void shutDown() throws Exception + { - @Override - protected void shutDown() throws Exception - { + } - } + @Subscribe + public void onGameStateChanged(GameStateChanged gameStateChanged) + { + if (gameStateChanged.getGameState() == GameState.LOGIN_SCREEN) + { + if (config.hidePlugins()) + { + hidePlugins(); + } + updateColors(); + } + } - @Subscribe - public void onGameStateChanged (GameStateChanged gameStateChanged) - { - if (gameStateChanged.getGameState()== GameState.LOGIN_SCREEN) { - if (config.hidePlugins()) - hidePlugins(); - updateColors(); - } - } + @Subscribe + public void onConfigChanged(ConfigChanged configChanged) + { + if (configChanged.getKey().equals("hidePlugins")) + { + if (config.hidePlugins()) + { + hidePlugins(); + } + else + { + showPlugins(); + } + } + updateColors(); + } - @Subscribe - public void onConfigChanged(ConfigChanged configChanged) { - if (configChanged.getKey().equals("hidePlugins")) { - if (config.hidePlugins()) { - hidePlugins(); - } else { - showPlugins(); - } - } - updateColors(); - } - - public void updateColors() { - for (PluginListItem pli : ConfigPanel.pluginList) { - if (pli.getPlugin()!=null) { - switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type()) { + private void updateColors() + { + for (PluginListItem pli : ConfigPanel.pluginList) + { + if (pli.getPlugin() != null) + { + switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type()) + { case EXTERNAL: pli.nameLabel.setForeground(config.externalColor()); break; @@ -117,15 +127,18 @@ public class PluginSorterPlugin extends Plugin { pli.nameLabel.setForeground(Color.WHITE); break; } - } - } - } + } + } + } - public void hidePlugins() { - Iterator iter = ConfigPanel.pluginList.iterator(); - while (iter.hasNext()) { - PluginListItem pli = iter.next(); - if (pli.getPlugin() != null) { + private void hidePlugins() + { + Iterator iter = ConfigPanel.pluginList.iterator(); + while (iter.hasNext()) + { + PluginListItem pli = iter.next(); + if (pli.getPlugin() != null) + { switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type()) { case PVM: @@ -139,14 +152,15 @@ public class PluginSorterPlugin extends Plugin { default: break; } - } - } - } + } + } + } - public void showPlugins() { - List tempList = new ArrayList<>(); + private void showPlugins() + { + List tempList = new ArrayList<>(); tempList.addAll(removedPlugins); tempList.addAll(ConfigPanel.pluginList); - ConfigPanel.pluginList = tempList; - } + ConfigPanel.pluginList = tempList; + } }