Refactor PluginSorter
This commit is contained in:
@@ -24,72 +24,69 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.pluginsorter;
|
package net.runelite.client.plugins.pluginsorter;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import net.runelite.client.config.Config;
|
import net.runelite.client.config.Config;
|
||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigItem;
|
import net.runelite.client.config.ConfigItem;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
@ConfigGroup("pluginsorter")
|
@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(
|
@ConfigItem(
|
||||||
position = 0,
|
position = 2,
|
||||||
keyName = "hidePlugins",
|
keyName = "pvmColor",
|
||||||
name = "Hide Plugins",
|
name = "PVM color",
|
||||||
description = "Hides all 3rd party plugins if checked"
|
description = "Configure the color of PVM related plugins"
|
||||||
)
|
)
|
||||||
default boolean hidePlugins()
|
default Color pvmColor()
|
||||||
{
|
{
|
||||||
return pluginsHidden;
|
return Color.GREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 1,
|
position = 3,
|
||||||
keyName = "externalColor",
|
keyName = "pvpColor",
|
||||||
name = "External color",
|
name = "PVP color",
|
||||||
description = "Configure the color of external plugins"
|
description = "Configure the color of PVP related plugins"
|
||||||
)
|
)
|
||||||
default Color externalColor()
|
default Color pvpColor()
|
||||||
{
|
{
|
||||||
return Color.MAGENTA;
|
return Color.RED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
position = 2,
|
position = 4,
|
||||||
keyName = "pvmColor",
|
keyName = "utilityColor",
|
||||||
name = "PVM color",
|
name = "Utility color",
|
||||||
description = "Configure the color of PVM related plugins"
|
description = "Configure the color of utility related plugins"
|
||||||
)
|
)
|
||||||
default Color pvmColor()
|
default Color utilityColor()
|
||||||
{
|
{
|
||||||
return Color.GREEN;
|
return Color.CYAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,14 @@
|
|||||||
package net.runelite.client.plugins.pluginsorter;
|
package net.runelite.client.plugins.pluginsorter;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
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.GameState;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.client.config.ConfigItemDescriptor;
|
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.Subscribe;
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
import net.runelite.client.plugins.Plugin;
|
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.ConfigPanel;
|
||||||
import net.runelite.client.plugins.config.PluginListItem;
|
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(
|
@PluginDescriptor(
|
||||||
name = "Plugin Organizer",
|
name = "Plugin Organizer",
|
||||||
description = "Hides and colors 3rd party plugins for better control",
|
description = "Hides and colors 3rd party plugins for better control",
|
||||||
tags = {"plugins","organizer"},
|
tags = {"plugins", "organizer"},
|
||||||
type = PluginType.PLUGIN_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
|
@Inject
|
||||||
public static List<PluginListItem> removedPlugins = new ArrayList<>();
|
private PluginSorterConfig config;
|
||||||
|
|
||||||
@Inject
|
@Provides
|
||||||
private PluginSorterConfig config;
|
PluginSorterConfig provideConfig(ConfigManager configManager)
|
||||||
|
{
|
||||||
|
return configManager.getConfig(PluginSorterConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Override
|
||||||
PluginSorterConfig provideConfig(ConfigManager configManager)
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
return configManager.getConfig(PluginSorterConfig.class);
|
updateColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
updateColors();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
}
|
||||||
protected void shutDown() throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
@Subscribe
|
||||||
|
public void onGameStateChanged(GameStateChanged gameStateChanged)
|
||||||
|
{
|
||||||
|
if (gameStateChanged.getGameState() == GameState.LOGIN_SCREEN)
|
||||||
|
{
|
||||||
|
if (config.hidePlugins())
|
||||||
|
{
|
||||||
|
hidePlugins();
|
||||||
|
}
|
||||||
|
updateColors();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameStateChanged (GameStateChanged gameStateChanged)
|
public void onConfigChanged(ConfigChanged configChanged)
|
||||||
{
|
{
|
||||||
if (gameStateChanged.getGameState()== GameState.LOGIN_SCREEN) {
|
if (configChanged.getKey().equals("hidePlugins"))
|
||||||
if (config.hidePlugins())
|
{
|
||||||
hidePlugins();
|
if (config.hidePlugins())
|
||||||
updateColors();
|
{
|
||||||
}
|
hidePlugins();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
showPlugins();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateColors();
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
private void updateColors()
|
||||||
public void onConfigChanged(ConfigChanged configChanged) {
|
{
|
||||||
if (configChanged.getKey().equals("hidePlugins")) {
|
for (PluginListItem pli : ConfigPanel.pluginList)
|
||||||
if (config.hidePlugins()) {
|
{
|
||||||
hidePlugins();
|
if (pli.getPlugin() != null)
|
||||||
} else {
|
{
|
||||||
showPlugins();
|
switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type())
|
||||||
}
|
{
|
||||||
}
|
|
||||||
updateColors();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateColors() {
|
|
||||||
for (PluginListItem pli : ConfigPanel.pluginList) {
|
|
||||||
if (pli.getPlugin()!=null) {
|
|
||||||
switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type()) {
|
|
||||||
case EXTERNAL:
|
case EXTERNAL:
|
||||||
pli.nameLabel.setForeground(config.externalColor());
|
pli.nameLabel.setForeground(config.externalColor());
|
||||||
break;
|
break;
|
||||||
@@ -117,15 +127,18 @@ public class PluginSorterPlugin extends Plugin {
|
|||||||
pli.nameLabel.setForeground(Color.WHITE);
|
pli.nameLabel.setForeground(Color.WHITE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hidePlugins() {
|
private void hidePlugins()
|
||||||
Iterator<PluginListItem> iter = ConfigPanel.pluginList.iterator();
|
{
|
||||||
while (iter.hasNext()) {
|
Iterator<PluginListItem> iter = ConfigPanel.pluginList.iterator();
|
||||||
PluginListItem pli = iter.next();
|
while (iter.hasNext())
|
||||||
if (pli.getPlugin() != null) {
|
{
|
||||||
|
PluginListItem pli = iter.next();
|
||||||
|
if (pli.getPlugin() != null)
|
||||||
|
{
|
||||||
switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type())
|
switch (pli.getPlugin().getClass().getAnnotation(PluginDescriptor.class).type())
|
||||||
{
|
{
|
||||||
case PVM:
|
case PVM:
|
||||||
@@ -139,14 +152,15 @@ public class PluginSorterPlugin extends Plugin {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPlugins() {
|
private void showPlugins()
|
||||||
List<PluginListItem> tempList = new ArrayList<>();
|
{
|
||||||
|
List<PluginListItem> tempList = new ArrayList<>();
|
||||||
tempList.addAll(removedPlugins);
|
tempList.addAll(removedPlugins);
|
||||||
tempList.addAll(ConfigPanel.pluginList);
|
tempList.addAll(ConfigPanel.pluginList);
|
||||||
ConfigPanel.pluginList = tempList;
|
ConfigPanel.pluginList = tempList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user