Refactor PluginSorter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<PluginListItem> removedPlugins = new ArrayList<>();
|
||||
|
||||
//Cache the hidden plugins
|
||||
public static List<PluginListItem> 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<PluginListItem> iter = ConfigPanel.pluginList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
PluginListItem pli = iter.next();
|
||||
if (pli.getPlugin() != null) {
|
||||
private void hidePlugins()
|
||||
{
|
||||
Iterator<PluginListItem> 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<PluginListItem> tempList = new ArrayList<>();
|
||||
private void showPlugins()
|
||||
{
|
||||
List<PluginListItem> tempList = new ArrayList<>();
|
||||
tempList.addAll(removedPlugins);
|
||||
tempList.addAll(ConfigPanel.pluginList);
|
||||
ConfigPanel.pluginList = tempList;
|
||||
}
|
||||
ConfigPanel.pluginList = tempList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user