rl-client: implement our pf4j plugins, extract pf4j out of net.runelite package. (#2883)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package com.openosrs.client.plugins;
|
||||
|
||||
import com.openosrs.client.plugins.openosrs.OpenOSRSPlugin;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.runelite.client.externalplugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.PluginInstantiationException;
|
||||
|
||||
public class BuiltInPluginManager
|
||||
{
|
||||
public static List<Class<?>> oprsPlugins = new ArrayList<>();
|
||||
|
||||
public static void loadPlugins()
|
||||
{
|
||||
try
|
||||
{
|
||||
ExternalPluginManager.pluginManager.loadPlugins(oprsPlugins, null);
|
||||
}
|
||||
catch (PluginInstantiationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
oprsPlugins.add(OpenOSRSPlugin.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
package com.openosrs.client.plugins;
|
||||
|
||||
import com.openosrs.client.OpenOSRS;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.BasePluginLoader;
|
||||
import org.pf4j.CompoundPluginLoader;
|
||||
import org.pf4j.CompoundPluginRepository;
|
||||
import org.pf4j.DefaultPluginManager;
|
||||
import org.pf4j.DependencyResolver;
|
||||
import org.pf4j.JarPluginLoader;
|
||||
import org.pf4j.JarPluginRepository;
|
||||
import org.pf4j.ManifestPluginDescriptorFinder;
|
||||
import org.pf4j.PluginAlreadyLoadedException;
|
||||
import org.pf4j.PluginDescriptorFinder;
|
||||
import org.pf4j.PluginLoader;
|
||||
import org.pf4j.PluginRepository;
|
||||
import org.pf4j.PluginRuntimeException;
|
||||
import org.pf4j.PluginState;
|
||||
import org.pf4j.PluginStateEvent;
|
||||
import org.pf4j.PluginWrapper;
|
||||
import org.pf4j.RuntimeMode;
|
||||
|
||||
@Slf4j
|
||||
class ExternalPf4jPluginManager extends DefaultPluginManager
|
||||
{
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
|
||||
public ExternalPf4jPluginManager(ExternalPluginManager externalPluginManager)
|
||||
{
|
||||
super(OpenOSRS.EXTERNALPLUGIN_DIR.toPath());
|
||||
this.externalPluginManager = externalPluginManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PluginDescriptorFinder createPluginDescriptorFinder()
|
||||
{
|
||||
return new ManifestPluginDescriptorFinder()
|
||||
{
|
||||
protected Path getManifestPath(Path pluginPath)
|
||||
{
|
||||
if (isDevelopment())
|
||||
{
|
||||
// The superclass performs a find, which is slow in development mode since we're pointing
|
||||
// at a sources directory, which can have a lot of files. The external plugin template
|
||||
// will always output the manifest at the following location, so we can hardcode this path.
|
||||
return pluginPath.resolve(ExternalPluginManager.DEVELOPMENT_MANIFEST_PATH);
|
||||
}
|
||||
|
||||
return super.getManifestPath(pluginPath);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PluginRepository createPluginRepository()
|
||||
{
|
||||
CompoundPluginRepository compoundPluginRepository = new CompoundPluginRepository();
|
||||
|
||||
JarPluginRepository jarPluginRepository = new JarPluginRepository(getPluginsRoot());
|
||||
compoundPluginRepository.add(jarPluginRepository);
|
||||
|
||||
return compoundPluginRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PluginLoader createPluginLoader()
|
||||
{
|
||||
return new CompoundPluginLoader()
|
||||
.add(new BasePluginLoader(this, new ExternalPluginClasspath()), this::isDevelopment)
|
||||
.add(new JarPluginLoader(this), this::isNotDevelopment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadPlugins()
|
||||
{
|
||||
for (Path path : pluginsRoots)
|
||||
{
|
||||
if (Files.notExists(path) || !Files.isDirectory(path))
|
||||
{
|
||||
log.warn("No '{}' root", path);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
List<Path> pluginPaths = pluginRepository.getPluginPaths();
|
||||
Collections.reverse(pluginPaths);
|
||||
|
||||
if (pluginPaths.isEmpty())
|
||||
{
|
||||
log.warn("No plugins");
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Found {} possible plugins: {}", pluginPaths.size(), pluginPaths);
|
||||
|
||||
Set<String> duplicatePlugins = new HashSet<>();
|
||||
for (Path pluginPath : pluginPaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!isPluginEligibleForLoading(pluginPath) && isNotDevelopment())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
loadPluginFromPath(pluginPath);
|
||||
}
|
||||
catch (PluginRuntimeException e)
|
||||
{
|
||||
if (!(e instanceof PluginAlreadyLoadedException))
|
||||
{
|
||||
log.error("Could not load plugin {}", pluginPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!duplicatePlugins.isEmpty())
|
||||
{
|
||||
log.error("Duplicate plugins detected: {}", String.join(", ", duplicatePlugins));
|
||||
|
||||
String formatted = String.join("\n", duplicatePlugins);
|
||||
|
||||
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(null, "You have duplicate plugins in your externalmanager.\n" +
|
||||
"Having duplicate plugins will result in an unstable\n" +
|
||||
"experience, It is highly recommended to delete any\n" +
|
||||
"duplicates, here is a list of the plugins.\n\n" +
|
||||
formatted, "Duplicate Plugins Detected", JOptionPane.WARNING_MESSAGE));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
resolvePlugins();
|
||||
}
|
||||
catch (PluginRuntimeException e)
|
||||
{
|
||||
if (e instanceof DependencyResolver.DependenciesNotFoundException)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
log.error("Could not resolve plugins", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void resolvePlugins()
|
||||
{
|
||||
// retrieves the plugins descriptors
|
||||
List<org.pf4j.PluginDescriptor> descriptors = new ArrayList<>();
|
||||
for (PluginWrapper plugin : plugins.values())
|
||||
{
|
||||
descriptors.add(plugin.getDescriptor());
|
||||
}
|
||||
|
||||
// retrieves the plugins descriptors from the resolvedPlugins list. This allows to load plugins that have already loaded dependencies.
|
||||
for (PluginWrapper plugin : resolvedPlugins)
|
||||
{
|
||||
descriptors.add(plugin.getDescriptor());
|
||||
}
|
||||
|
||||
DependencyResolver.Result result = dependencyResolver.resolve(descriptors);
|
||||
|
||||
if (result.hasCyclicDependency())
|
||||
{
|
||||
throw new DependencyResolver.CyclicDependencyException();
|
||||
}
|
||||
|
||||
List<String> notFoundDependencies = result.getNotFoundDependencies();
|
||||
if (!notFoundDependencies.isEmpty())
|
||||
{
|
||||
throw new DependencyResolver.DependenciesNotFoundException(notFoundDependencies);
|
||||
}
|
||||
|
||||
List<DependencyResolver.WrongDependencyVersion> wrongVersionDependencies = result.getWrongVersionDependencies();
|
||||
if (!wrongVersionDependencies.isEmpty())
|
||||
{
|
||||
throw new DependencyResolver.DependenciesWrongVersionException(wrongVersionDependencies);
|
||||
}
|
||||
|
||||
List<String> sortedPlugins = result.getSortedPlugins();
|
||||
|
||||
// move plugins from "unresolved" to "resolved"
|
||||
for (String pluginId : sortedPlugins)
|
||||
{
|
||||
PluginWrapper pluginWrapper = plugins.get(pluginId);
|
||||
|
||||
//The plugin is already resolved. Don't put a copy in the resolvedPlugins.
|
||||
if (resolvedPlugins.contains(pluginWrapper))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unresolvedPlugins.remove(pluginWrapper))
|
||||
{
|
||||
PluginState pluginState = pluginWrapper.getPluginState();
|
||||
if (pluginState != PluginState.DISABLED)
|
||||
{
|
||||
pluginWrapper.setPluginState(PluginState.RESOLVED);
|
||||
}
|
||||
|
||||
resolvedPlugins.add(pluginWrapper);
|
||||
|
||||
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeMode getRuntimeMode()
|
||||
{
|
||||
return RuntimeMode.DEPLOYMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginState stopPlugin(String pluginId)
|
||||
{
|
||||
if (!plugins.containsKey(pluginId))
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId));
|
||||
}
|
||||
|
||||
PluginWrapper pluginWrapper = getPlugin(pluginId);
|
||||
org.pf4j.PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor();
|
||||
PluginState pluginState = pluginWrapper.getPluginState();
|
||||
if (PluginState.STOPPED == pluginState)
|
||||
{
|
||||
log.debug("Already stopped plugin '{}'", getPluginLabel(pluginDescriptor));
|
||||
return PluginState.STOPPED;
|
||||
}
|
||||
|
||||
// test for disabled plugin
|
||||
if (PluginState.DISABLED == pluginState)
|
||||
{
|
||||
// do nothing
|
||||
return pluginState;
|
||||
}
|
||||
|
||||
pluginWrapper.getPlugin().stop();
|
||||
pluginWrapper.setPluginState(PluginState.STOPPED);
|
||||
startedPlugins.remove(pluginWrapper);
|
||||
|
||||
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
|
||||
|
||||
return pluginWrapper.getPluginState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unloadPlugin(String pluginId)
|
||||
{
|
||||
try
|
||||
{
|
||||
PluginState pluginState = stopPlugin(pluginId);
|
||||
if (PluginState.STARTED == pluginState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginWrapper pluginWrapper = getPlugin(pluginId);
|
||||
|
||||
// remove the plugin
|
||||
plugins.remove(pluginId);
|
||||
getResolvedPlugins().remove(pluginWrapper);
|
||||
|
||||
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
|
||||
|
||||
// remove the classloader
|
||||
Map<String, ClassLoader> pluginClassLoaders = getPluginClassLoaders();
|
||||
if (pluginClassLoaders.containsKey(pluginId))
|
||||
{
|
||||
ClassLoader classLoader = pluginClassLoaders.remove(pluginId);
|
||||
if (classLoader instanceof Closeable)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Closeable) classLoader).close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new PluginRuntimeException(e, "Cannot close classloader");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// ignore not found exceptions because this method is recursive
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deletePlugin(String pluginId)
|
||||
{
|
||||
if (!plugins.containsKey(pluginId))
|
||||
{
|
||||
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId));
|
||||
}
|
||||
|
||||
PluginWrapper pluginWrapper = getPlugin(pluginId);
|
||||
// stop the plugin if it's started
|
||||
PluginState pluginState = stopPlugin(pluginId);
|
||||
if (PluginState.STARTED == pluginState)
|
||||
{
|
||||
log.error("Failed to stop plugin '{}' on delete", pluginId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get an instance of plugin before the plugin is unloaded
|
||||
// for reason see https://github.com/pf4j/pf4j/issues/309
|
||||
|
||||
org.pf4j.Plugin plugin = pluginWrapper.getPlugin();
|
||||
|
||||
if (!unloadPlugin(pluginId))
|
||||
{
|
||||
log.error("Failed to unload plugin '{}' on delete", pluginId);
|
||||
return false;
|
||||
}
|
||||
|
||||
// notify the plugin as it's deleted
|
||||
plugin.delete();
|
||||
|
||||
Path pluginPath = pluginWrapper.getPluginPath();
|
||||
|
||||
return pluginRepository.deletePluginPath(pluginPath);
|
||||
}
|
||||
|
||||
private boolean isPluginEligibleForLoading(Path path)
|
||||
{
|
||||
return path.toFile().getName().endsWith(".jar");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.openosrs.client.plugins;
|
||||
|
||||
import org.pf4j.DevelopmentPluginClasspath;
|
||||
|
||||
class ExternalPluginClasspath extends DevelopmentPluginClasspath
|
||||
{
|
||||
static final String GRADLE_DEPS_PATH = "build/deps";
|
||||
|
||||
ExternalPluginClasspath()
|
||||
{
|
||||
addJarsDirectories(GRADLE_DEPS_PATH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.openosrs.client.plugins;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Determines whether a {@link File} is an external plugin folder. To be considered a plugin a folder must:
|
||||
* <p>
|
||||
* * Must not be a blacklisted name
|
||||
* * Have a {@code .gradle.kts} file in the root named after the folder
|
||||
* * Have a {@code MANIFEST.MF} located at {@code build/tmp/jar/MANIFEST.MF}
|
||||
*/
|
||||
public class ExternalPluginFileFilter implements FileFilter
|
||||
{
|
||||
private static final List<String> blacklist = Arrays.asList(
|
||||
".git",
|
||||
"build",
|
||||
"target",
|
||||
"release"
|
||||
);
|
||||
|
||||
private static final List<String> buildFiles = Arrays.asList(
|
||||
"%s.gradle.kts",
|
||||
"%s.gradle"
|
||||
);
|
||||
|
||||
@Override
|
||||
public boolean accept(File pathName)
|
||||
{
|
||||
// Check if this path looks like a plugin development directory
|
||||
if (!pathName.isDirectory())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String dirName = pathName.getName();
|
||||
if (blacklist.contains(dirName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the plugin directory has a MANIFEST.MF which si required for loading
|
||||
if (!new File(pathName, ExternalPluginManager.DEVELOPMENT_MANIFEST_PATH).exists())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// By convention plugins their directory is $name and they have a $name.gradle.kts or $name.gradle file in their root
|
||||
for (String buildFile : buildFiles)
|
||||
{
|
||||
if (new File(pathName, String.format(buildFile, dirName)).exists())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
package com.openosrs.client.plugins;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import org.pf4j.ExtensionPoint;
|
||||
|
||||
public class Plugin extends net.runelite.client.plugins.Plugin implements ExtensionPoint
|
||||
{
|
||||
public Injector injector;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, OpenOSRS <https://github.com/open-osrs>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.openosrs.client.plugins.neverlog;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Never Logout",
|
||||
enabledByDefault = false,
|
||||
description = "Overrides the 5 minute AFK logout timer.",
|
||||
tags = {"openosrs", "never log", "idle", "logout", "log", "never"}
|
||||
)
|
||||
@SuppressWarnings("unchecked")
|
||||
public class NeverLogoutPlugin extends Plugin
|
||||
{
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Subscribe
|
||||
private void onGameTick(GameTick gameTick)
|
||||
{
|
||||
if (client.getKeyboardIdleTicks() > 14900)
|
||||
{
|
||||
client.setKeyboardIdleTicks(0);
|
||||
}
|
||||
if (client.getMouseIdleTicks() > 14900)
|
||||
{
|
||||
client.setMouseIdleTicks(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2019, Zeruth <TheRealNull@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
package com.openosrs.client.plugins.openosrs;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import static net.runelite.api.ScriptID.BANK_PIN_OP;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_1;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_10;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_2;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_3;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_4;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_5;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_6;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_7;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_8;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_9;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_EXIT_BUTTON;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_FIRST_ENTERED;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_FORGOT_BUTTON;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_FOURTH_ENTERED;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_INSTRUCTION_TEXT;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_SECOND_ENTERED;
|
||||
import static net.runelite.api.widgets.WidgetInfo.BANK_PIN_THIRD_ENTERED;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.Keybind;
|
||||
import com.openosrs.client.config.OpenOSRSConfig;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import com.openosrs.client.plugins.openosrs.externals.ExternalPluginManagerPanel;
|
||||
import net.runelite.client.ui.ClientToolbar;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.util.HotkeyListener;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@PluginDescriptor(
|
||||
loadWhenOutdated = true, // prevent users from disabling
|
||||
hidden = true, // prevent users from disabling
|
||||
name = "OpenOSRS"
|
||||
)
|
||||
@Singleton
|
||||
@Slf4j
|
||||
public class OpenOSRSPlugin extends Plugin
|
||||
{
|
||||
private final openosrsKeyListener keyListener = new openosrsKeyListener();
|
||||
|
||||
@Inject
|
||||
private OpenOSRSConfig config;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Inject
|
||||
private ClientToolbar clientToolbar;
|
||||
|
||||
private NavigationButton navButton;
|
||||
|
||||
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> this.keybind)
|
||||
{
|
||||
@Override
|
||||
public void hotkeyPressed()
|
||||
{
|
||||
detach = !detach;
|
||||
client.setOculusOrbState(detach ? 1 : 0);
|
||||
client.setOculusOrbNormalSpeed(detach ? 36 : 12);
|
||||
}
|
||||
};
|
||||
private int entered = -1;
|
||||
private int enterIdx;
|
||||
private boolean expectInput;
|
||||
private boolean detach;
|
||||
private Keybind keybind;
|
||||
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
ExternalPluginManagerPanel panel = injector.getInstance(ExternalPluginManagerPanel.class);
|
||||
|
||||
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "externalmanager_icon.png");
|
||||
|
||||
navButton = NavigationButton.builder()
|
||||
.tooltip("External Plugin Manager")
|
||||
.icon(icon)
|
||||
.priority(1)
|
||||
.panel(panel)
|
||||
.build();
|
||||
clientToolbar.addNavigation(navButton);
|
||||
|
||||
entered = -1;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
this.keybind = config.detachHotkey();
|
||||
keyManager.registerKeyListener(hotkeyListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
clientToolbar.removeNavigation(navButton);
|
||||
|
||||
entered = 0;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
keyManager.unregisterKeyListener(hotkeyListener);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onConfigChanged(ConfigChanged event)
|
||||
{
|
||||
if (!event.getGroup().equals("openosrs"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.keybind = config.detachHotkey();
|
||||
|
||||
if (!config.keyboardPin())
|
||||
{
|
||||
entered = 0;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
}
|
||||
|
||||
if (event.getKey().equals("shareLogs") && !config.shareLogs())
|
||||
{
|
||||
final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
|
||||
logger.detachAppender("Sentry");
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onScriptCallbackEvent(ScriptCallbackEvent e)
|
||||
{
|
||||
if (!config.keyboardPin())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getEventName().equals("bankpin"))
|
||||
{
|
||||
int[] intStack = client.getIntStack();
|
||||
int intStackSize = client.getIntStackSize();
|
||||
|
||||
// This'll be anywhere from -1 to 3
|
||||
// 0 = first number, 1 second, etc
|
||||
// Anything other than 0123 means the bankpin interface closes
|
||||
int enterIdx = intStack[intStackSize - 1];
|
||||
|
||||
if (enterIdx < 0 || enterIdx > 3)
|
||||
{
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
this.enterIdx = 0;
|
||||
this.entered = 0;
|
||||
expectInput = false;
|
||||
return;
|
||||
}
|
||||
else if (enterIdx == 0)
|
||||
{
|
||||
keyManager.registerKeyListener(keyListener);
|
||||
}
|
||||
|
||||
this.enterIdx = enterIdx;
|
||||
expectInput = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleKey(char c)
|
||||
{
|
||||
if (client.getWidget(WidgetID.BANK_PIN_GROUP_ID, BANK_PIN_INSTRUCTION_TEXT.getChildId()) == null
|
||||
|| !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("First click the FIRST digit.")
|
||||
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Now click the SECOND digit.")
|
||||
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Time for the THIRD digit.")
|
||||
&& !client.getWidget(BANK_PIN_INSTRUCTION_TEXT).getText().equals("Finally, the FOURTH digit."))
|
||||
|
||||
{
|
||||
entered = 0;
|
||||
enterIdx = 0;
|
||||
expectInput = false;
|
||||
keyManager.unregisterKeyListener(keyListener);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!expectInput)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int num = Character.getNumericValue(c);
|
||||
|
||||
// We gotta copy this cause enteridx changes while the script is executing
|
||||
int oldEnterIdx = enterIdx;
|
||||
|
||||
// Script 685 will call 653, which in turn will set expectInput to true
|
||||
expectInput = false;
|
||||
client.runScript(BANK_PIN_OP, num, enterIdx, entered, BANK_PIN_EXIT_BUTTON.getId(), BANK_PIN_FORGOT_BUTTON.getId(), BANK_PIN_1.getId(), BANK_PIN_2.getId(), BANK_PIN_3.getId(), BANK_PIN_4.getId(), BANK_PIN_5.getId(), BANK_PIN_6.getId(), BANK_PIN_7.getId(), BANK_PIN_8.getId(), BANK_PIN_9.getId(), BANK_PIN_10.getId(), BANK_PIN_FIRST_ENTERED.getId(), BANK_PIN_SECOND_ENTERED.getId(), BANK_PIN_THIRD_ENTERED.getId(), BANK_PIN_FOURTH_ENTERED.getId(), BANK_PIN_INSTRUCTION_TEXT.getId());
|
||||
|
||||
if (oldEnterIdx == 0)
|
||||
{
|
||||
entered = num * 1000;
|
||||
}
|
||||
else if (oldEnterIdx == 1)
|
||||
{
|
||||
entered += num * 100;
|
||||
}
|
||||
else if (oldEnterIdx == 2)
|
||||
{
|
||||
entered += num * 10;
|
||||
}
|
||||
}
|
||||
|
||||
private class openosrsKeyListener implements KeyListener
|
||||
{
|
||||
private int lastKeyCycle;
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent keyEvent)
|
||||
{
|
||||
if (!Character.isDigit(keyEvent.getKeyChar()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (client.getGameCycle() - lastKeyCycle <= 5)
|
||||
{
|
||||
keyEvent.consume();
|
||||
return;
|
||||
}
|
||||
|
||||
lastKeyCycle = client.getGameCycle();
|
||||
|
||||
clientThread.invoke(() -> handleKey(keyEvent.getKeyChar()));
|
||||
keyEvent.consume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent keyEvent)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
97
runelite-client/src/main/java/com/openosrs/client/plugins/openosrs/externals/ExternalBox.java
vendored
Normal file
97
runelite-client/src/main/java/com/openosrs/client/plugins/openosrs/externals/ExternalBox.java
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.net.URL;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.text.DefaultCaret;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import org.pf4j.update.PluginInfo;
|
||||
|
||||
public class ExternalBox extends JPanel
|
||||
{
|
||||
private static final Font normalFont = FontManager.getRunescapeFont();
|
||||
private static final Font smallFont = FontManager.getRunescapeSmallFont();
|
||||
|
||||
PluginInfo pluginInfo;
|
||||
JLabel install = new JLabel();
|
||||
JMultilineLabel description = new JMultilineLabel();
|
||||
|
||||
ExternalBox(String name, URL url)
|
||||
{
|
||||
this(name, url.toString().replace("https://raw.githubusercontent.com/", "").replace("/master/", ""));
|
||||
}
|
||||
|
||||
ExternalBox(PluginInfo pluginInfo)
|
||||
{
|
||||
this(pluginInfo.name, pluginInfo.description);
|
||||
}
|
||||
|
||||
ExternalBox(String name, String desc)
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
JPanel titleWrapper = new JPanel(new BorderLayout());
|
||||
titleWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
titleWrapper.setBorder(new CompoundBorder(
|
||||
BorderFactory.createMatteBorder(0, 0, 1, 0, ColorScheme.DARK_GRAY_COLOR),
|
||||
BorderFactory.createLineBorder(ColorScheme.DARKER_GRAY_COLOR)
|
||||
));
|
||||
|
||||
JLabel title = new JLabel();
|
||||
title.setText(name);
|
||||
title.setFont(normalFont);
|
||||
title.setBorder(null);
|
||||
title.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
title.setPreferredSize(new Dimension(0, 24));
|
||||
title.setForeground(Color.WHITE);
|
||||
title.setBorder(new EmptyBorder(0, 8, 0, 0));
|
||||
|
||||
JPanel titleActions = new JPanel(new BorderLayout(3, 0));
|
||||
titleActions.setBorder(new EmptyBorder(0, 0, 0, 8));
|
||||
titleActions.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
titleActions.add(install, BorderLayout.EAST);
|
||||
|
||||
titleWrapper.add(title, BorderLayout.CENTER);
|
||||
titleWrapper.add(titleActions, BorderLayout.EAST);
|
||||
|
||||
description.setText(desc);
|
||||
description.setFont(smallFont);
|
||||
description.setDisabledTextColor(Color.WHITE);
|
||||
description.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
add(titleWrapper, BorderLayout.NORTH);
|
||||
add(description, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
public static class JMultilineLabel extends JTextArea
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JMultilineLabel()
|
||||
{
|
||||
super();
|
||||
setEditable(false);
|
||||
setCursor(null);
|
||||
setOpaque(false);
|
||||
setFocusable(false);
|
||||
setWrapStyleWord(true);
|
||||
setLineWrap(true);
|
||||
setBorder(new EmptyBorder(0, 8, 0, 8));
|
||||
setAlignmentY(JLabel.CENTER_ALIGNMENT);
|
||||
|
||||
DefaultCaret caret = (DefaultCaret) getCaret();
|
||||
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
|
||||
public class ExternalPluginManagerPanel extends PluginPanel
|
||||
{
|
||||
private static final ImageIcon ADD_ICON_RAW;
|
||||
private static final ImageIcon ADD_HOVER_ICON_RAW;
|
||||
private static final ImageIcon ADD_ICON_GH;
|
||||
private static final ImageIcon ADD_HOVER_ICON_GH;
|
||||
|
||||
static
|
||||
{
|
||||
final BufferedImage addIconRaw =
|
||||
ImageUtil.getResourceStreamFromClass(ExternalPluginManagerPanel.class, "add_raw_icon.png");
|
||||
final BufferedImage addIconGh = ImageUtil
|
||||
.resizeImage(ImageUtil.getResourceStreamFromClass(ExternalPluginManagerPanel.class, "gh_icon.png"), 14, 14);
|
||||
ADD_ICON_RAW = new ImageIcon(addIconRaw);
|
||||
ADD_HOVER_ICON_RAW = new ImageIcon(ImageUtil.alphaOffset(addIconRaw, 0.53f));
|
||||
ADD_ICON_GH = new ImageIcon(addIconGh);
|
||||
ADD_HOVER_ICON_GH = new ImageIcon(ImageUtil.alphaOffset(addIconGh, 0.53f));
|
||||
}
|
||||
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
private ExternalPluginManagerPanel(ExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
|
||||
{
|
||||
super(false);
|
||||
|
||||
this.externalPluginManager = externalPluginManager;
|
||||
this.executor = executor;
|
||||
this.eventBus = eventBus;
|
||||
|
||||
buildPanel();
|
||||
}
|
||||
|
||||
private void buildPanel()
|
||||
{
|
||||
removeAll();
|
||||
|
||||
setLayout(new BorderLayout(0, 10));
|
||||
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||
|
||||
add(titleBar(), BorderLayout.NORTH);
|
||||
add(tabbedPane(), BorderLayout.CENTER);
|
||||
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private JPanel titleBar()
|
||||
{
|
||||
JPanel titlePanel = new JPanel(new BorderLayout());
|
||||
titlePanel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||
|
||||
JLabel title = new JLabel();
|
||||
JLabel addGHRepo = new JLabel(ADD_ICON_GH);
|
||||
JLabel addRawRepo = new JLabel(ADD_ICON_RAW);
|
||||
|
||||
JPanel buttonHolder = new JPanel(new BorderLayout());
|
||||
buttonHolder.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
|
||||
title.setText("External Plugin Manager");
|
||||
title.setForeground(Color.WHITE);
|
||||
|
||||
addGHRepo.setToolTipText("Add new GitHub repository");
|
||||
addGHRepo.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
if (externalPluginManager.getWarning())
|
||||
{
|
||||
JCheckBox checkbox = new JCheckBox("Don't show again.");
|
||||
int answer = showWarningDialog(checkbox);
|
||||
|
||||
if (answer == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkbox.isSelected())
|
||||
{
|
||||
externalPluginManager.setWarning(false);
|
||||
}
|
||||
}
|
||||
|
||||
JTextField owner = new JTextField();
|
||||
JTextField name = new JTextField();
|
||||
Object[] message = {
|
||||
"Github Repository owner:", owner,
|
||||
"Github Repository name:", name
|
||||
};
|
||||
|
||||
int option =
|
||||
JOptionPane.showConfirmDialog(ClientUI.getFrame(), message, "Add repository", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (option != JOptionPane.OK_OPTION || owner.getText().equals("") || name.getText().equals(""))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (externalPluginManager.doesGhRepoExist(owner.getText(), name.getText()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This repository already exists.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ExternalPluginManager.testGHRepository(owner.getText(), name.getText()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
externalPluginManager.addGHRepository(owner.getText(), name.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent)
|
||||
{
|
||||
addGHRepo.setIcon(ADD_HOVER_ICON_GH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent)
|
||||
{
|
||||
addGHRepo.setIcon(ADD_ICON_GH);
|
||||
}
|
||||
});
|
||||
addGHRepo.setBorder(new EmptyBorder(0, 3, 0, 0));
|
||||
|
||||
addRawRepo.setToolTipText("Add new raw repository");
|
||||
addRawRepo.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent mouseEvent)
|
||||
{
|
||||
if (externalPluginManager.getWarning())
|
||||
{
|
||||
JCheckBox checkbox = new JCheckBox("Don't show again.");
|
||||
int answer = showWarningDialog(checkbox);
|
||||
|
||||
if (answer == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkbox.isSelected())
|
||||
{
|
||||
externalPluginManager.setWarning(false);
|
||||
}
|
||||
}
|
||||
|
||||
JTextField id = new JTextField();
|
||||
JTextField url = new JTextField();
|
||||
Object[] message = {
|
||||
"Repository ID:", id,
|
||||
"Repository URL:", url
|
||||
};
|
||||
|
||||
int option =
|
||||
JOptionPane.showConfirmDialog(ClientUI.getFrame(), message, "Add repository", JOptionPane.OK_CANCEL_OPTION);
|
||||
if (option != JOptionPane.OK_OPTION || id.getText().equals("") || url.getText().equals(""))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (id.getText().startsWith("gh:") || id.getText().contains("|"))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(),
|
||||
"Repository id cannot begin with \"gh:\"\nor contain the pipe character '|'.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (externalPluginManager.doesRepoExist(id.getText()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(),
|
||||
String.format("The repository with id %s already exists.", id.getText()), "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
URL urlActual;
|
||||
try
|
||||
{
|
||||
urlActual = new URL(url.getText());
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ExternalPluginManager.testRepository(urlActual))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
externalPluginManager.addRepository(id.getText(), urlActual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent mouseEvent)
|
||||
{
|
||||
addRawRepo.setIcon(ADD_HOVER_ICON_RAW);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent mouseEvent)
|
||||
{
|
||||
addRawRepo.setIcon(ADD_ICON_RAW);
|
||||
}
|
||||
});
|
||||
addRawRepo.setBorder(new EmptyBorder(0, 0, 0, 3));
|
||||
|
||||
titlePanel.add(title, BorderLayout.WEST);
|
||||
buttonHolder.add(addRawRepo, BorderLayout.WEST);
|
||||
buttonHolder.add(addGHRepo, BorderLayout.EAST);
|
||||
titlePanel.add(buttonHolder, BorderLayout.EAST);
|
||||
|
||||
return titlePanel;
|
||||
}
|
||||
|
||||
private JTabbedPane tabbedPane()
|
||||
{
|
||||
JTabbedPane mainTabPane = new JTabbedPane();
|
||||
|
||||
PluginsPanel pluginPanel = new PluginsPanel(this.externalPluginManager, this.executor, this.eventBus);
|
||||
JScrollPane repositoryPanel = wrapContainer(new RepositoryPanel(this.externalPluginManager, this.eventBus));
|
||||
|
||||
mainTabPane.add("Plugins", pluginPanel);
|
||||
mainTabPane.add("Repositories", repositoryPanel);
|
||||
|
||||
return mainTabPane;
|
||||
}
|
||||
|
||||
private int showWarningDialog(JCheckBox checkbox)
|
||||
{
|
||||
Object[] options = {"Okay, I accept the risk", "Never mind, turn back", checkbox};
|
||||
return JOptionPane.showOptionDialog(new JFrame(),
|
||||
"Adding plugins from unverified sources may put your account, or personal information at risk! \n",
|
||||
"Account security warning",
|
||||
JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.WARNING_MESSAGE,
|
||||
null,
|
||||
options,
|
||||
options[0]);
|
||||
}
|
||||
|
||||
static JScrollPane wrapContainer(final JPanel container)
|
||||
{
|
||||
final JPanel wrapped = new JPanel(new BorderLayout());
|
||||
wrapped.add(container, BorderLayout.NORTH);
|
||||
|
||||
final JScrollPane scroller = new JScrollPane(wrapped);
|
||||
scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
scroller.getVerticalScrollBar().setPreferredSize(new Dimension(8, 0));
|
||||
|
||||
return scroller;
|
||||
}
|
||||
}
|
||||
592
runelite-client/src/main/java/com/openosrs/client/plugins/openosrs/externals/PluginsPanel.java
vendored
Normal file
592
runelite-client/src/main/java/com/openosrs/client/plugins/openosrs/externals/PluginsPanel.java
vendored
Normal file
@@ -0,0 +1,592 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import static net.runelite.api.util.Text.DISTANCE;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import com.openosrs.client.events.ExternalPluginChanged;
|
||||
import com.openosrs.client.events.ExternalRepositoryChanged;
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import static com.openosrs.client.plugins.openosrs.externals.ExternalPluginManagerPanel.wrapContainer;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
import net.runelite.client.ui.components.IconTextField;
|
||||
import net.runelite.client.ui.components.shadowlabel.JShadowedLabel;
|
||||
import com.openosrs.client.util.DeferredDocumentChangedListener;
|
||||
import com.openosrs.client.util.ImageUtil;
|
||||
import com.openosrs.client.util.SwingUtil;
|
||||
import org.pf4j.update.PluginInfo;
|
||||
import org.pf4j.update.UpdateManager;
|
||||
import org.pf4j.update.UpdateRepository;
|
||||
import org.pf4j.update.VerifyException;
|
||||
|
||||
@Slf4j
|
||||
public class PluginsPanel extends JPanel
|
||||
{
|
||||
private static final ImageIcon ADD_ICON;
|
||||
private static final ImageIcon ADD_HOVER_ICON;
|
||||
private static final ImageIcon DELETE_ICON;
|
||||
private static final ImageIcon DELETE_HOVER_ICON;
|
||||
private static final ImageIcon DELETE_ICON_GRAY;
|
||||
private static final ImageIcon DELETE_HOVER_ICON_GRAY;
|
||||
|
||||
static
|
||||
{
|
||||
final BufferedImage addIcon =
|
||||
ImageUtil.recolorImage(
|
||||
ImageUtil.getResourceStreamFromClass(PluginsPanel.class, "add_icon.png"), ColorScheme.BRAND_BLUE
|
||||
);
|
||||
ADD_ICON = new ImageIcon(addIcon);
|
||||
ADD_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(addIcon, 0.53f));
|
||||
|
||||
final BufferedImage deleteImg =
|
||||
ImageUtil.recolorImage(
|
||||
ImageUtil.resizeCanvas(
|
||||
ImageUtil.getResourceStreamFromClass(PluginsPanel.class, "delete_icon.png"), 14, 14
|
||||
), ColorScheme.BRAND_BLUE
|
||||
);
|
||||
DELETE_ICON = new ImageIcon(deleteImg);
|
||||
DELETE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(deleteImg, 0.53f));
|
||||
|
||||
DELETE_ICON_GRAY = new ImageIcon(ImageUtil.grayscaleImage(deleteImg));
|
||||
DELETE_HOVER_ICON_GRAY = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.grayscaleImage(deleteImg), 0.53f));
|
||||
}
|
||||
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
private final UpdateManager updateManager;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final EventBus eventBus;
|
||||
|
||||
private final IconTextField searchBar = new IconTextField();
|
||||
private final JPanel filterwrapper = new JPanel(new BorderLayout(0, 10));
|
||||
private final List<PluginInfo> installedPluginsList = new ArrayList<>();
|
||||
private final List<PluginInfo> availablePluginsList = new ArrayList<>();
|
||||
private final JPanel installedPluginsPanel = new JPanel(new GridBagLayout());
|
||||
private final JPanel availablePluginsPanel = new JPanel(new GridBagLayout());
|
||||
|
||||
private JComboBox<String> filterComboBox;
|
||||
private Set<String> deps;
|
||||
|
||||
PluginsPanel(ExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
|
||||
{
|
||||
this.externalPluginManager = externalPluginManager;
|
||||
this.updateManager = externalPluginManager.getUpdateManager();
|
||||
this.executor = executor;
|
||||
this.eventBus = eventBus;
|
||||
|
||||
setLayout(new BorderLayout(0, 10));
|
||||
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||
|
||||
buildFilter();
|
||||
|
||||
JTabbedPane mainTabPane = new JTabbedPane();
|
||||
|
||||
mainTabPane.add("Installed", wrapContainer(installedPluginsPanel()));
|
||||
mainTabPane.add("Available", wrapContainer(availablePluginsPanel()));
|
||||
|
||||
add(filterwrapper, BorderLayout.NORTH);
|
||||
add(mainTabPane, BorderLayout.CENTER);
|
||||
|
||||
eventBus.register(this);
|
||||
|
||||
reloadPlugins();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onExternalRepositoryChanged(ExternalRepositoryChanged event)
|
||||
{
|
||||
buildFilter();
|
||||
reloadPlugins();
|
||||
repaint();
|
||||
}
|
||||
|
||||
private void buildFilter()
|
||||
{
|
||||
filterwrapper.removeAll();
|
||||
|
||||
DeferredDocumentChangedListener listener = new DeferredDocumentChangedListener();
|
||||
listener.addChangeListener(e ->
|
||||
{
|
||||
installedPlugins();
|
||||
availablePlugins();
|
||||
});
|
||||
|
||||
filterwrapper.setBorder(new EmptyBorder(10, 10, 0, 10));
|
||||
|
||||
List<String> repositories = getRepositories();
|
||||
filterComboBox = new JComboBox<>(repositories.toArray(new String[0]));
|
||||
filterComboBox.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
|
||||
filterComboBox.addActionListener(e -> {
|
||||
installedPlugins();
|
||||
availablePlugins();
|
||||
});
|
||||
|
||||
if (repositories.size() > 2)
|
||||
{
|
||||
filterwrapper.add(filterComboBox, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
searchBar.setIcon(IconTextField.Icon.SEARCH);
|
||||
searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
|
||||
searchBar.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
searchBar.setHoverBackgroundColor(ColorScheme.DARK_GRAY_HOVER_COLOR);
|
||||
searchBar.getDocument().addDocumentListener(listener);
|
||||
|
||||
filterwrapper.add(searchBar, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private List<String> getRepositories()
|
||||
{
|
||||
List<String> repositories = new ArrayList<>();
|
||||
repositories.add("All");
|
||||
for (UpdateRepository updateRepository : this.updateManager.getRepositories())
|
||||
{
|
||||
repositories.add(updateRepository.getUrl().toString().replace("https://raw.githubusercontent.com/", "").replace("/master/", ""));
|
||||
}
|
||||
|
||||
return repositories;
|
||||
}
|
||||
|
||||
private JLabel titleLabel(String text)
|
||||
{
|
||||
JLabel title = new JShadowedLabel();
|
||||
|
||||
title.setFont(FontManager.getRunescapeSmallFont());
|
||||
title.setForeground(Color.WHITE);
|
||||
title.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
title.setText("<html><body style = 'text-align:center'>" + text + "</body></html>");
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
private JPanel installedPluginsPanel()
|
||||
{
|
||||
JPanel installedPluginsContainer = new JPanel();
|
||||
installedPluginsContainer.setLayout(new BorderLayout(0, 5));
|
||||
installedPluginsContainer.setBorder(new EmptyBorder(0, 10, 10, 10));
|
||||
installedPluginsContainer.add(installedPluginsPanel, BorderLayout.CENTER);
|
||||
|
||||
return installedPluginsContainer;
|
||||
}
|
||||
|
||||
private JPanel availablePluginsPanel()
|
||||
{
|
||||
JPanel availablePluginsContainer = new JPanel();
|
||||
availablePluginsContainer.setLayout(new BorderLayout(0, 5));
|
||||
availablePluginsContainer.setBorder(new EmptyBorder(0, 10, 10, 10));
|
||||
availablePluginsContainer.add(availablePluginsPanel, BorderLayout.CENTER);
|
||||
|
||||
return availablePluginsContainer;
|
||||
}
|
||||
|
||||
static boolean mismatchesSearchTerms(String search, PluginInfo pluginInfo)
|
||||
{
|
||||
final String[] searchTerms = search.toLowerCase().split(" ");
|
||||
final String[] pluginTerms = (pluginInfo.name + " " + pluginInfo.description).toLowerCase().split("[/\\s]");
|
||||
for (String term : searchTerms)
|
||||
{
|
||||
if (Arrays.stream(pluginTerms).noneMatch((t) -> t.contains(term) ||
|
||||
DISTANCE.apply(t, term) > 0.9))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void reloadPlugins()
|
||||
{
|
||||
fetchPlugins();
|
||||
|
||||
try
|
||||
{
|
||||
SwingUtil.syncExec(() -> {
|
||||
this.installedPlugins();
|
||||
this.availablePlugins();
|
||||
});
|
||||
|
||||
}
|
||||
catch (InvocationTargetException | InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchPlugins()
|
||||
{
|
||||
List<PluginInfo> availablePlugins = null;
|
||||
List<PluginInfo> plugins = null;
|
||||
List<String> disabledPlugins = externalPluginManager.getDisabledPlugins();
|
||||
|
||||
try
|
||||
{
|
||||
availablePlugins = updateManager.getAvailablePlugins();
|
||||
plugins = updateManager.getPlugins();
|
||||
}
|
||||
catch (JsonSyntaxException ex)
|
||||
{
|
||||
log.error(String.valueOf(ex));
|
||||
}
|
||||
|
||||
if (availablePlugins == null || plugins == null)
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "The external plugin list could not be loaded.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
availablePluginsList.clear();
|
||||
installedPluginsList.clear();
|
||||
|
||||
deps = externalPluginManager.getDependencies();
|
||||
|
||||
for (PluginInfo pluginInfo : plugins)
|
||||
{
|
||||
if (availablePlugins.contains(pluginInfo) || disabledPlugins.contains(pluginInfo.id))
|
||||
{
|
||||
availablePluginsList.add(pluginInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
installedPluginsList.add(pluginInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onExternalPluginChanged(ExternalPluginChanged externalPluginChanged)
|
||||
{
|
||||
String pluginId = externalPluginChanged.getPluginId();
|
||||
Optional<Component> externalBox;
|
||||
|
||||
if (externalPluginChanged.isAdded())
|
||||
{
|
||||
externalBox = Arrays.stream(
|
||||
availablePluginsPanel.getComponents()
|
||||
).filter(extBox ->
|
||||
extBox instanceof ExternalBox && ((ExternalBox) extBox).pluginInfo.id.equals(pluginId)
|
||||
).findFirst();
|
||||
}
|
||||
else
|
||||
{
|
||||
externalBox = Arrays.stream(
|
||||
installedPluginsPanel.getComponents()
|
||||
).filter(extBox ->
|
||||
extBox instanceof ExternalBox && ((ExternalBox) extBox).pluginInfo.id.equals(pluginId)
|
||||
).findFirst();
|
||||
}
|
||||
|
||||
if (externalBox.isEmpty())
|
||||
{
|
||||
log.info("EXTERNALBOX IS EMPTY: {}", pluginId);
|
||||
return;
|
||||
}
|
||||
|
||||
ExternalBox extBox = (ExternalBox) externalBox.get();
|
||||
deps = externalPluginManager.getDependencies();
|
||||
|
||||
try
|
||||
{
|
||||
SwingUtil.syncExec(() ->
|
||||
{
|
||||
if (externalPluginChanged.isAdded())
|
||||
{
|
||||
availablePluginsPanel.remove(externalBox.get());
|
||||
availablePluginsList.remove(extBox.pluginInfo);
|
||||
|
||||
installedPluginsList.add(extBox.pluginInfo);
|
||||
installedPluginsList.sort(Comparator.naturalOrder());
|
||||
|
||||
installedPlugins();
|
||||
|
||||
pluginInstallButton(extBox.install, extBox.pluginInfo, true, deps.contains(extBox.pluginInfo.id));
|
||||
}
|
||||
else
|
||||
{
|
||||
installedPluginsPanel.remove(externalBox.get());
|
||||
installedPluginsList.remove(extBox.pluginInfo);
|
||||
|
||||
availablePluginsList.add(extBox.pluginInfo);
|
||||
availablePluginsList.sort(Comparator.naturalOrder());
|
||||
|
||||
availablePlugins();
|
||||
|
||||
pluginInstallButton(extBox.install, extBox.pluginInfo, false, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (InvocationTargetException | InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void installedPlugins()
|
||||
{
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
installedPluginsPanel.removeAll();
|
||||
String search = searchBar.getText();
|
||||
|
||||
for (PluginInfo pluginInfo : installedPluginsList)
|
||||
{
|
||||
if (!search.equals("") && mismatchesSearchTerms(search, pluginInfo))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filterComboBox.getSelectedIndex() != 0)
|
||||
{
|
||||
boolean filtered = true;
|
||||
String filter = String.valueOf(filterComboBox.getSelectedItem());
|
||||
for (UpdateRepository updateRepository : updateManager.getRepositories())
|
||||
{
|
||||
if (filter.equals(updateRepository.getUrl().toString().replace("https://raw.githubusercontent.com/", "").replace("/master/", "")) &&
|
||||
pluginInfo.getRepositoryId().equals(updateRepository.getId()))
|
||||
{
|
||||
filtered = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (filtered)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ExternalBox pluginBox = new ExternalBox(pluginInfo);
|
||||
pluginBox.pluginInfo = pluginInfo;
|
||||
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.weightx = 1.0;
|
||||
c.gridy += 1;
|
||||
c.insets = new Insets(5, 0, 0, 0);
|
||||
|
||||
pluginInstallButton(pluginBox.install, pluginInfo, true, deps.contains(pluginInfo.id));
|
||||
installedPluginsPanel.add(pluginBox, c);
|
||||
}
|
||||
|
||||
if (installedPluginsPanel.getComponents().length < 1)
|
||||
{
|
||||
installedPluginsPanel.add(titleLabel("No plugins found"));
|
||||
}
|
||||
}
|
||||
|
||||
private void availablePlugins()
|
||||
{
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
availablePluginsPanel.removeAll();
|
||||
String search = searchBar.getText();
|
||||
|
||||
for (PluginInfo pluginInfo : availablePluginsList)
|
||||
{
|
||||
if (!search.equals("") && mismatchesSearchTerms(search, pluginInfo))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filterComboBox.getSelectedIndex() != 0)
|
||||
{
|
||||
boolean filtered = true;
|
||||
String filter = String.valueOf(filterComboBox.getSelectedItem());
|
||||
for (UpdateRepository updateRepository : updateManager.getRepositories())
|
||||
{
|
||||
if (filter.equals(updateRepository.getUrl().toString().replace("https://raw.githubusercontent.com/", "").replace("/master/", "")) &&
|
||||
pluginInfo.getRepositoryId().equals(updateRepository.getId()))
|
||||
{
|
||||
filtered = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (filtered)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
ExternalBox pluginBox = new ExternalBox(pluginInfo);
|
||||
pluginBox.pluginInfo = pluginInfo;
|
||||
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.weightx = 1.0;
|
||||
c.gridy += 1;
|
||||
c.insets = new Insets(5, 0, 0, 0);
|
||||
|
||||
pluginInstallButton(pluginBox.install, pluginInfo, false, false);
|
||||
availablePluginsPanel.add(pluginBox, c);
|
||||
}
|
||||
|
||||
if (availablePluginsPanel.getComponents().length < 1)
|
||||
{
|
||||
availablePluginsPanel.add(titleLabel("No plugins found"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void pluginInstallButton(JLabel install, PluginInfo pluginInfo, boolean installed, boolean hideAction)
|
||||
{
|
||||
install.setIcon(installed ? hideAction ? DELETE_ICON_GRAY : DELETE_ICON : ADD_ICON);
|
||||
install.setText("");
|
||||
|
||||
if (!hideAction)
|
||||
{
|
||||
install.setToolTipText(installed ? "Uninstall" : "Install");
|
||||
}
|
||||
install.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
if (installed)
|
||||
{
|
||||
if (hideAction)
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This plugin can't be uninstalled because one or more other plugins have a dependency on it.", "Error!", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
else
|
||||
{
|
||||
install.setIcon(null);
|
||||
install.setText("Uninstalling");
|
||||
|
||||
SwingWorker<Boolean, Void> worker = new SwingWorker<>()
|
||||
{
|
||||
@Override
|
||||
protected Boolean doInBackground()
|
||||
{
|
||||
return externalPluginManager.uninstall(pluginInfo.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done()
|
||||
{
|
||||
|
||||
boolean status = false;
|
||||
try
|
||||
{
|
||||
status = get();
|
||||
}
|
||||
catch (InterruptedException | ExecutionException e)
|
||||
{
|
||||
}
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pluginInstallButton(install, pluginInfo, installed, hideAction);
|
||||
}
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
install.setIcon(null);
|
||||
install.setText("Installing");
|
||||
|
||||
SwingWorker<Boolean, Void> worker = new SwingWorker<>()
|
||||
{
|
||||
@Override
|
||||
protected Boolean doInBackground()
|
||||
{
|
||||
return installPlugin(pluginInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done()
|
||||
{
|
||||
|
||||
boolean status = false;
|
||||
try
|
||||
{
|
||||
status = get();
|
||||
}
|
||||
catch (InterruptedException | ExecutionException e)
|
||||
{
|
||||
}
|
||||
|
||||
if (!status)
|
||||
{
|
||||
pluginInstallButton(install, pluginInfo, installed, hideAction);
|
||||
}
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
if (install.getText().toLowerCase().contains("installing"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
install.setIcon(installed ? hideAction ? DELETE_HOVER_ICON_GRAY : DELETE_HOVER_ICON : ADD_HOVER_ICON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
if (install.getText().toLowerCase().contains("installing"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
install.setIcon(installed ? hideAction ? DELETE_ICON_GRAY : DELETE_ICON : ADD_ICON);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean installPlugin(PluginInfo pluginInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
return externalPluginManager.install(pluginInfo.id);
|
||||
}
|
||||
catch (VerifyException ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
SwingUtil.syncExec(() ->
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), pluginInfo.name + " could not be installed, the hash could not be verified.", "Error!", JOptionPane.ERROR_MESSAGE));
|
||||
}
|
||||
catch (InvocationTargetException | InterruptedException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
179
runelite-client/src/main/java/com/openosrs/client/plugins/openosrs/externals/RepositoryBox.java
vendored
Normal file
179
runelite-client/src/main/java/com/openosrs/client/plugins/openosrs/externals/RepositoryBox.java
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Optional;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import com.openosrs.client.ui.JMultilineLabel;
|
||||
import com.openosrs.client.util.ImageUtil;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
import org.pf4j.update.PluginInfo;
|
||||
import org.pf4j.update.UpdateRepository;
|
||||
|
||||
public class RepositoryBox extends JPanel
|
||||
{
|
||||
private static final Font normalFont = FontManager.getRunescapeFont();
|
||||
private static final Font smallFont = FontManager.getRunescapeSmallFont();
|
||||
private static final ImageIcon DELETE_ICON;
|
||||
private static final ImageIcon DELETE_HOVER_ICON;
|
||||
private static final ImageIcon DISCORD_ICON;
|
||||
private static final ImageIcon DISCORD_HOVER_ICON;
|
||||
|
||||
static
|
||||
{
|
||||
final BufferedImage deleteImg =
|
||||
ImageUtil.recolorImage(
|
||||
ImageUtil.resizeCanvas(
|
||||
ImageUtil.getResourceStreamFromClass(ExternalPluginManagerPanel.class, "delete_icon.png"), 14, 14
|
||||
), ColorScheme.BRAND_BLUE
|
||||
);
|
||||
DELETE_ICON = new ImageIcon(deleteImg);
|
||||
DELETE_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(deleteImg, 0.53f));
|
||||
|
||||
final BufferedImage discordImg =
|
||||
ImageUtil.recolorImage(
|
||||
ImageUtil.resizeCanvas(
|
||||
ImageUtil.getResourceStreamFromClass(ExternalPluginManagerPanel.class, "discord_icon.png"), 14, 14
|
||||
), Color.WHITE
|
||||
);
|
||||
DISCORD_ICON = new ImageIcon(discordImg);
|
||||
DISCORD_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(discordImg, 0.53f));
|
||||
}
|
||||
|
||||
RepositoryBox(ExternalPluginManager externalPluginManager, UpdateRepository updateRepository)
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
String name = updateRepository.getId();
|
||||
String urlString = updateRepository.getUrl().toString();
|
||||
if (urlString.startsWith("/"))
|
||||
{
|
||||
urlString = urlString.substring(1);
|
||||
}
|
||||
|
||||
JPanel titleWrapper = new JPanel(new BorderLayout());
|
||||
titleWrapper.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
titleWrapper.setBorder(new CompoundBorder(
|
||||
BorderFactory.createMatteBorder(0, 0, 1, 0, ColorScheme.DARK_GRAY_COLOR),
|
||||
BorderFactory.createLineBorder(ColorScheme.DARKER_GRAY_COLOR)
|
||||
));
|
||||
|
||||
JLabel title = new JLabel();
|
||||
title.setText(name);
|
||||
title.setFont(normalFont);
|
||||
title.setBorder(null);
|
||||
title.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
title.setPreferredSize(new Dimension(0, 24));
|
||||
title.setForeground(Color.WHITE);
|
||||
title.setBorder(new EmptyBorder(0, 8, 0, 0));
|
||||
|
||||
JPanel titleActions = new JPanel(new BorderLayout(3, 0));
|
||||
titleActions.setBorder(new EmptyBorder(0, 0, 0, 8));
|
||||
titleActions.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
Optional<PluginInfo> firstPlugin = updateRepository.getPlugins().values().stream().findFirst();
|
||||
|
||||
if (firstPlugin.isPresent() && !firstPlugin.get().projectUrl.equals(""))
|
||||
{
|
||||
JLabel support = new JLabel();
|
||||
support.setIcon(DISCORD_ICON);
|
||||
support.setToolTipText("Support");
|
||||
support.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
LinkBrowser.browse(firstPlugin.get().projectUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
support.setIcon(DISCORD_HOVER_ICON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
support.setIcon(DISCORD_ICON);
|
||||
}
|
||||
});
|
||||
|
||||
titleActions.add(support, BorderLayout.WEST);
|
||||
}
|
||||
|
||||
if (!name.equals("OpenOSRS") && !name.equals("Plugin-Hub"))
|
||||
{
|
||||
JLabel install = new JLabel();
|
||||
install.setIcon(DELETE_ICON);
|
||||
install.setToolTipText("Remove");
|
||||
install.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e)
|
||||
{
|
||||
externalPluginManager.removeRepository(updateRepository.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e)
|
||||
{
|
||||
install.setIcon(DELETE_HOVER_ICON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e)
|
||||
{
|
||||
install.setIcon(DELETE_ICON);
|
||||
}
|
||||
});
|
||||
|
||||
titleActions.add(install, BorderLayout.EAST);
|
||||
}
|
||||
|
||||
titleWrapper.add(title, BorderLayout.CENTER);
|
||||
titleWrapper.add(titleActions, BorderLayout.EAST);
|
||||
|
||||
JMultilineLabel repository = new JMultilineLabel();
|
||||
repository.setText(formatURL(urlString));
|
||||
repository.setFont(smallFont);
|
||||
repository.setDisabledTextColor(Color.WHITE);
|
||||
|
||||
String finalUrlString = urlString;
|
||||
repository.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e)
|
||||
{
|
||||
LinkBrowser.browse(formatURL(finalUrlString));
|
||||
}
|
||||
});
|
||||
|
||||
add(titleWrapper, BorderLayout.NORTH);
|
||||
add(repository, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private String formatURL(String url)
|
||||
{
|
||||
if (url.contains("githubusercontent"))
|
||||
{
|
||||
url = url.replace("raw.githubusercontent", "github").replace("/master/", "");
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import javax.inject.Inject;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import com.openosrs.client.events.ExternalRepositoryChanged;
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import org.pf4j.update.UpdateRepository;
|
||||
|
||||
public class RepositoryPanel extends JPanel
|
||||
{
|
||||
@Inject
|
||||
public EventBus eventBus;
|
||||
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
|
||||
private final GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
RepositoryPanel(ExternalPluginManager externalPluginManager, EventBus eventBus)
|
||||
{
|
||||
this.externalPluginManager = externalPluginManager;
|
||||
|
||||
setLayout(new GridBagLayout());
|
||||
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||
setBorder(new EmptyBorder(0, 10, 0, 10));
|
||||
|
||||
onExternalRepositoryChanged(null);
|
||||
|
||||
eventBus.register(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onExternalRepositoryChanged(ExternalRepositoryChanged event)
|
||||
{
|
||||
removeAll();
|
||||
|
||||
c.fill = GridBagConstraints.HORIZONTAL;
|
||||
c.weightx = 1;
|
||||
c.gridy = 0;
|
||||
c.insets = new Insets(5, 0, 0, 0);
|
||||
|
||||
for (UpdateRepository repository : externalPluginManager.getRepositories())
|
||||
{
|
||||
final RepositoryBox p = new RepositoryBox(externalPluginManager, repository);
|
||||
add(p, c);
|
||||
c.gridy++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user