From f0b4f37177bea1fab30b54a301d18ad25afcc153 Mon Sep 17 00:00:00 2001 From: Arnah Date: Tue, 3 Oct 2023 05:16:38 -0600 Subject: [PATCH] Add builtin plugin to handle additional pluginhubs --- README.md | 17 +++- .../ca/arnah/runelite/HijackedClient.java | 46 +++++++++-- .../arnah/runelite/RuneLiteHijackConfig.java | 16 ++++ .../runelite/RuneLiteHijackProperties.java | 4 +- .../plugin/config/ArnahPluginListPanel.java | 80 +++++++++++-------- 5 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 src/main/java/ca/arnah/runelite/RuneLiteHijackConfig.java diff --git a/README.md b/README.md index 663f703..55825c5 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,26 @@ Random project I made to run my own custom or modified external plugins on the o ![example](https://im.arnah.ca/3cB8zf5ZaE.png) -If properly done, you should see "RuneLiteHijack Plugin Hub" in plugin configuration +If properly done, you should see "RuneLiteHijack Plugin Hub" or a "RuneLiteHijack" plugin in plugin configuration ![example](https://im.arnah.ca/Bn1tEIgJLC9rWGF.png) # Adding additional Plugin Hubs +RuneLite Hijack comes with a builtin plugin that allows you to add additional plugin hubs. You can access this plugin like the similar "RuneLite" builtin +plugin. + +![example](https://im.arnah.ca/c4orAVtodc7VkeE.png) + The default plugin hub is a GitHub repository viewable [here](https://github.com/Arnuh/RuneLiteHijack-PluginHub). You can use this as a template to create -your own plugin hub, while also using the provided plugin to customize additional plugin hubs by using a comma separated list. +your own plugin hub. + +For GitHub repositories, you need to make sure the url is a "raw githubusercontent" link +like the following `https://raw.githubusercontent.com/Arnuh/RuneLiteHijack-PluginHub/master/`. + +With the "Plugin Hubs" settings, you can add additional plugin hubs to the list by using a comma separated list of urls. -For GitHub repositories, you need to make sure the url is a "raw githubusercontent" link like `https://raw.githubusercontent. -com/Arnuh/RuneLiteHijack-PluginHub/master/`. +![Plugin Hub Example](https://im.arnah.ca/jHNzJb81jtxWDfP.png) # Structure of Plugin Hubs diff --git a/src/main/java/ca/arnah/runelite/HijackedClient.java b/src/main/java/ca/arnah/runelite/HijackedClient.java index 3707f97..4a388b8 100644 --- a/src/main/java/ca/arnah/runelite/HijackedClient.java +++ b/src/main/java/ca/arnah/runelite/HijackedClient.java @@ -3,6 +3,10 @@ import javax.inject.Inject; import ca.arnah.runelite.plugin.ArnahPluginManager; import ca.arnah.runelite.plugin.config.ArnahPluginListPanel; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.eventbus.EventBus; +import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.ConfigChanged; import net.runelite.client.ui.SplashScreen; /** @@ -11,12 +15,24 @@ */ public class HijackedClient{ + private final ArnahPluginManager arnahPluginManager; + + private final ArnahPluginListPanel pluginListPanel; + private final EventBus eventBus; + private final ConfigManager configManager; + private final RuneLiteHijackConfig runeLiteHijackConfig; + @Inject - private ArnahPluginManager arnahPluginManager; - @Inject - private ArnahPluginListPanel pluginListPanel; + public HijackedClient(ArnahPluginManager arnahPluginManager, ArnahPluginListPanel pluginListPanel, EventBus eventBus, ConfigManager configManager){ + this.arnahPluginManager = arnahPluginManager; + this.pluginListPanel = pluginListPanel; + this.eventBus = eventBus; + this.configManager = configManager; + this.runeLiteHijackConfig = configManager.getConfig(RuneLiteHijackConfig.class); + } public void start(){ + eventBus.register(this); System.out.println("Start"); new Thread(()->{ while(SplashScreen.isOpen()){ @@ -27,13 +43,33 @@ public void start(){ } } System.out.println("Splash Screen done"); - try{ - arnahPluginManager.loadExternalPlugins(); pluginListPanel.init(); + startup(); + arnahPluginManager.loadExternalPlugins(); }catch(Exception ex){ ex.printStackTrace(); } }).start(); } + + private void startup(){ + pluginListPanel.addFakePlugin("RuneLiteHijack", "RuneLiteHijack settings", new String[]{"pluginhub"}, runeLiteHijackConfig, configManager.getConfigDescriptor(runeLiteHijackConfig)); + refreshConfig(false); + } + + + @Subscribe + public void onConfigChanged(ConfigChanged e){ + if(e.getGroup().equals(RuneLiteHijackConfig.GROUP_NAME)){ + refreshConfig(true); + } + } + + private void refreshConfig(boolean update){ + System.setProperty(RuneLiteHijackProperties.PLUGINHUB_BASE, runeLiteHijackConfig.urls()); + if(update){ + arnahPluginManager.update(); + } + } } \ No newline at end of file diff --git a/src/main/java/ca/arnah/runelite/RuneLiteHijackConfig.java b/src/main/java/ca/arnah/runelite/RuneLiteHijackConfig.java new file mode 100644 index 0000000..3df316d --- /dev/null +++ b/src/main/java/ca/arnah/runelite/RuneLiteHijackConfig.java @@ -0,0 +1,16 @@ +package ca.arnah.runelite; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup(RuneLiteHijackConfig.GROUP_NAME) +public interface RuneLiteHijackConfig extends Config{ + + String GROUP_NAME = "runelitehijack"; + + @ConfigItem(keyName = "pluginhub", name = "Plugin Hubs", description = "List of plugin hubs separated by commas", position = 1) + default String urls(){ + return RuneLiteHijackProperties.PLUGINHUB_BASE_URL; + } +} diff --git a/src/main/java/ca/arnah/runelite/RuneLiteHijackProperties.java b/src/main/java/ca/arnah/runelite/RuneLiteHijackProperties.java index 6a590e0..e48a8ea 100644 --- a/src/main/java/ca/arnah/runelite/RuneLiteHijackProperties.java +++ b/src/main/java/ca/arnah/runelite/RuneLiteHijackProperties.java @@ -11,8 +11,8 @@ **/ public class RuneLiteHijackProperties{ - private static final String PLUGINHUB_BASE = "runelitehijack.pluginhub.url"; - private static final String PLUGINHUB_BASE_URL = "https://raw.githubusercontent.com/Arnuh/RuneLiteHijack-PluginHub/master/"; + public static final String PLUGINHUB_BASE = "runelitehijack.pluginhub.url"; + public static final String PLUGINHUB_BASE_URL = "https://raw.githubusercontent.com/Arnuh/RuneLiteHijack-PluginHub/master/"; public static List getPluginHubBase(){ return Arrays.stream(getPluginHubs()).map(HttpUrl::parse).collect(Collectors.toList()); diff --git a/src/main/java/ca/arnah/runelite/plugin/config/ArnahPluginListPanel.java b/src/main/java/ca/arnah/runelite/plugin/config/ArnahPluginListPanel.java index 574f755..8f1a0ab 100644 --- a/src/main/java/ca/arnah/runelite/plugin/config/ArnahPluginListPanel.java +++ b/src/main/java/ca/arnah/runelite/plugin/config/ArnahPluginListPanel.java @@ -39,6 +39,8 @@ import ca.arnah.runelite.plugin.ArnahPluginManager; import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigDescriptor; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; @@ -76,38 +78,36 @@ public ArnahPluginListPanel(ConfigManager configManager, PluginManager pluginMan } public void init(){ - pluginManager.getPlugins().stream() - .filter(ConfigPlugin.class::isInstance) - .findAny().ifPresent(plugin->{ - try{ - Field field = ConfigPlugin.class.getDeclaredField("pluginListPanelProvider"); - field.setAccessible(true); - Provider pluginPanelProvider = (Provider) field.get(plugin); - pluginListPanel = (PluginPanel) (objPluginListPanel = pluginPanelProvider.get()); - SwingUtilities.invokeLater(()->{ - JPanel southPanel = new FixedWidthPanel(); - southPanel.setLayout(new BorderLayout()); - for(Component maybeAButton : pluginListPanel.getComponents()){ - if(maybeAButton instanceof JButton){ - JButton button = (JButton) maybeAButton; - if(button.getText() == null) continue; - if(!button.getText().equals("Plugin Hub")) continue; - pluginListPanel.remove(button); - southPanel.add(button, "North"); - } - } - JButton externalPluginButton = new JButton("RuneLiteHijack Plugin Hub"); - externalPluginButton.setBorder(new EmptyBorder(5, 5, 5, 5)); - externalPluginButton.setLayout(new BorderLayout(0, PluginPanel.BORDER_OFFSET)); - externalPluginButton.addActionListener(l->getMuxer().pushState(pluginHubPanelProvider.get())); - southPanel.add(externalPluginButton, "South"); - pluginListPanel.add(southPanel, "South"); - rebuildPluginList(); - }); - }catch(Exception ex){ - log.error("Failed to initialize RuneLiteHijack Plugin Hub", ex); - } - }); + pluginManager.getPlugins().stream().filter(ConfigPlugin.class::isInstance).findAny().ifPresent(plugin->{ + try{ + Field field = ConfigPlugin.class.getDeclaredField("pluginListPanelProvider"); + field.setAccessible(true); + Provider pluginPanelProvider = (Provider) field.get(plugin); + pluginListPanel = (PluginPanel) (objPluginListPanel = pluginPanelProvider.get()); + SwingUtilities.invokeLater(()->{ + JPanel southPanel = new FixedWidthPanel(); + southPanel.setLayout(new BorderLayout()); + for(Component maybeAButton : pluginListPanel.getComponents()){ + if(maybeAButton instanceof JButton){ + JButton button = (JButton) maybeAButton; + if(button.getText() == null) continue; + if(!button.getText().equals("Plugin Hub")) continue; + pluginListPanel.remove(button); + southPanel.add(button, "North"); + } + } + JButton externalPluginButton = new JButton("RuneLiteHijack Plugin Hub"); + externalPluginButton.setBorder(new EmptyBorder(5, 5, 5, 5)); + externalPluginButton.setLayout(new BorderLayout(0, PluginPanel.BORDER_OFFSET)); + externalPluginButton.addActionListener(l->getMuxer().pushState(pluginHubPanelProvider.get())); + southPanel.add(externalPluginButton, "South"); + pluginListPanel.add(southPanel, "South"); + rebuildPluginList(); + }); + }catch(Exception ex){ + log.error("Failed to initialize RuneLiteHijack Plugin Hub", ex); + } + }); } public MultiplexingPluginPanel getMuxer(){ @@ -135,6 +135,22 @@ void rebuildPluginList(){ refresh(); } + public void addFakePlugin(String name, String description, String[] tags, Config config, ConfigDescriptor configDescriptor){ + try{ + var method = objPluginListPanel.getClass().getDeclaredField("fakePlugins"); + method.setAccessible(true); + List fakePlugins = (List) method.get(objPluginListPanel); + + var clazz = Class.forName("net.runelite.client.plugins.config.PluginConfigurationDescriptor") + .getDeclaredConstructor(String.class, String.class, String[].class, Config.class, ConfigDescriptor.class); + clazz.setAccessible(true); + Object descriptor = clazz.newInstance(name, description, tags, config, configDescriptor); + fakePlugins.add(descriptor); + }catch(Exception ex){ + ex.printStackTrace(); + } + } + void refresh(){ // update enabled / disabled status of all items /*pluginList.forEach(listItem ->