1/n
This commit is contained in:
@@ -70,6 +70,7 @@ import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.LootManager;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
import net.runelite.client.menus.MenuManager;
|
||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||
import net.runelite.client.rs.ClientLoader;
|
||||
import net.runelite.client.rs.ClientUpdateCheckMode;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
@@ -114,7 +115,7 @@ public class RuneLite
|
||||
private ExternalPluginManager externalPluginManager;
|
||||
|
||||
@Inject
|
||||
private com.openosrs.client.plugins.ExternalPluginManager oprsExternalPluginManager;
|
||||
private OPRSExternalPluginManager oprsExternalPluginManager;
|
||||
|
||||
@Inject
|
||||
private EventBus eventBus;
|
||||
@@ -241,6 +242,8 @@ public class RuneLite
|
||||
}
|
||||
});
|
||||
|
||||
OpenOSRS.preload();
|
||||
|
||||
OkHttpClient.Builder okHttpClientBuilder = RuneLiteAPI.CLIENT.newBuilder()
|
||||
.cache(new Cache(new File(CACHE_DIR, "okhttp"), MAX_OKHTTP_CACHE_SIZE));
|
||||
|
||||
@@ -286,8 +289,6 @@ public class RuneLite
|
||||
|
||||
injector.getInstance(RuneLite.class).start();
|
||||
|
||||
OpenOSRS.init();
|
||||
|
||||
final long end = System.currentTimeMillis();
|
||||
final RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
|
||||
final long uptime = rb.getUptime();
|
||||
|
||||
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@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 net.runelite.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 OPRSExternalPf4jPluginManager extends DefaultPluginManager
|
||||
{
|
||||
private final OPRSExternalPluginManager externalPluginManager;
|
||||
|
||||
public OPRSExternalPf4jPluginManager(OPRSExternalPluginManager 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(OPRSExternalPluginManager.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 OPRSExternalPluginClasspath()), 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,38 @@
|
||||
/*
|
||||
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@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 net.runelite.client.plugins;
|
||||
|
||||
import org.pf4j.DevelopmentPluginClasspath;
|
||||
|
||||
class OPRSExternalPluginClasspath extends DevelopmentPluginClasspath
|
||||
{
|
||||
static final String GRADLE_DEPS_PATH = "build/deps";
|
||||
|
||||
OPRSExternalPluginClasspath()
|
||||
{
|
||||
addJarsDirectories(GRADLE_DEPS_PATH);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@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 net.runelite.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 OPRSExternalPluginFileFilter 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, OPRSExternalPluginManager.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
@@ -27,8 +27,9 @@ package net.runelite.client.plugins;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
import org.pf4j.ExtensionPoint;
|
||||
|
||||
public abstract class Plugin implements Module
|
||||
public abstract class Plugin implements Module, ExtensionPoint
|
||||
{
|
||||
protected Injector injector;
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import java.awt.Dimension;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JToggleButton;
|
||||
import com.openosrs.client.util.ImageUtil;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
|
||||
class PluginToggleButton extends JToggleButton
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.info;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.inject.Inject;
|
||||
import com.openosrs.client.OpenOSRS;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
@@ -135,8 +136,11 @@ public class InfoPanel extends PluginPanel
|
||||
|
||||
final Font smallFont = FontManager.getRunescapeSmallFont();
|
||||
|
||||
JLabel version = new JLabel(htmlLabel("RuneLite version: ", runeliteVersion));
|
||||
version.setFont(smallFont);
|
||||
JLabel rlVersion = new JLabel(htmlLabel("RuneLite version: ", runeliteVersion));
|
||||
rlVersion.setFont(smallFont);
|
||||
|
||||
JLabel oprsVersion = new JLabel(htmlLabel("OpenOSRS version: ", OpenOSRS.SYSTEM_VERSION));
|
||||
oprsVersion.setFont(smallFont);
|
||||
|
||||
JLabel revision = new JLabel();
|
||||
revision.setFont(smallFont);
|
||||
@@ -147,7 +151,7 @@ public class InfoPanel extends PluginPanel
|
||||
engineVer = String.format("Rev %d", client.getRevision());
|
||||
}
|
||||
|
||||
revision.setText(htmlLabel("Oldschool revision: ", engineVer));
|
||||
revision.setText(htmlLabel("OldSchool revision: ", engineVer));
|
||||
|
||||
JLabel launcher = new JLabel(htmlLabel("Launcher version: ", MoreObjects
|
||||
.firstNonNull(RuneLiteProperties.getLauncherVersion(), "Unknown")));
|
||||
@@ -170,7 +174,8 @@ public class InfoPanel extends PluginPanel
|
||||
}
|
||||
});
|
||||
|
||||
versionPanel.add(version);
|
||||
versionPanel.add(rlVersion);
|
||||
versionPanel.add(oprsVersion);
|
||||
versionPanel.add(revision);
|
||||
versionPanel.add(launcher);
|
||||
versionPanel.add(Box.createGlue());
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@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 net.runelite.client.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
public class DeferredDocumentChangedListener implements DocumentListener
|
||||
{
|
||||
private final Timer timer;
|
||||
private final List<ChangeListener> listeners;
|
||||
|
||||
public DeferredDocumentChangedListener()
|
||||
{
|
||||
listeners = new ArrayList<>(25);
|
||||
timer = new Timer(200, e -> fireStateChanged());
|
||||
timer.setRepeats(false);
|
||||
}
|
||||
|
||||
public void addChangeListener(ChangeListener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
private void fireStateChanged()
|
||||
{
|
||||
if (!listeners.isEmpty())
|
||||
{
|
||||
ChangeEvent evt = new ChangeEvent(this);
|
||||
for (ChangeListener listener : listeners)
|
||||
{
|
||||
listener.stateChanged(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e)
|
||||
{
|
||||
timer.restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e)
|
||||
{
|
||||
timer.restart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e)
|
||||
{
|
||||
timer.restart();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -34,10 +34,12 @@ import java.awt.image.BufferedImage;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.PixelGrabber;
|
||||
import java.awt.image.RescaleOp;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.GrayFilter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -524,4 +526,54 @@ public class ImageUtil
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recolors pixels of the given image with the given color based on a given recolor condition
|
||||
* predicate.
|
||||
*
|
||||
* @param image The image which should have its non-transparent pixels recolored.
|
||||
* @param color The color with which to recolor pixels.
|
||||
* @param recolorCondition The condition on which to recolor pixels with the given color.
|
||||
* @return The given image with all pixels fulfilling the recolor condition predicate
|
||||
* set to the given color.
|
||||
*/
|
||||
public static BufferedImage recolorImage(final BufferedImage image, final Color color, final Predicate<Color> recolorCondition)
|
||||
{
|
||||
final BufferedImage recoloredImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
for (int x = 0; x < recoloredImage.getWidth(); x++)
|
||||
{
|
||||
for (int y = 0; y < recoloredImage.getHeight(); y++)
|
||||
{
|
||||
final Color pixelColor = new Color(image.getRGB(x, y), true);
|
||||
if (!recolorCondition.test(pixelColor))
|
||||
{
|
||||
recoloredImage.setRGB(x, y, image.getRGB(x, y));
|
||||
continue;
|
||||
}
|
||||
|
||||
recoloredImage.setRGB(x, y, color.getRGB());
|
||||
}
|
||||
}
|
||||
return recoloredImage;
|
||||
}
|
||||
|
||||
public static BufferedImage recolorImage(BufferedImage image, final Color color)
|
||||
{
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
WritableRaster raster = image.getRaster();
|
||||
|
||||
for (int xx = 0; xx < width; xx++)
|
||||
{
|
||||
for (int yy = 0; yy < height; yy++)
|
||||
{
|
||||
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
|
||||
pixels[0] = color.getRed();
|
||||
pixels[1] = color.getGreen();
|
||||
pixels[2] = color.getBlue();
|
||||
raster.setPixel(xx, yy, pixels);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2021, ThatGamerBlue <thatgamerblue@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 net.runelite.client.util;
|
||||
|
||||
import java.awt.Polygon;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.WorldType;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.api.geometry.Cuboid;
|
||||
|
||||
public class PvPUtil
|
||||
{
|
||||
private static final Polygon NOT_WILDERNESS_BLACK_KNIGHTS = new Polygon( // this is black knights castle
|
||||
new int[]{2994, 2995, 2996, 2996, 2994, 2994, 2997, 2998, 2998, 2999, 3000, 3001, 3002, 3003, 3004, 3005, 3005,
|
||||
3005, 3019, 3020, 3022, 3023, 3024, 3025, 3026, 3026, 3027, 3027, 3028, 3028, 3029, 3029, 3030, 3030, 3031,
|
||||
3031, 3032, 3033, 3034, 3035, 3036, 3037, 3037},
|
||||
new int[]{3525, 3526, 3527, 3529, 3529, 3534, 3534, 3535, 3536, 3537, 3538, 3539, 3540, 3541, 3542, 3543, 3544,
|
||||
3545, 3545, 3546, 3546, 3545, 3544, 3543, 3543, 3542, 3541, 3540, 3539, 3537, 3536, 3535, 3534, 3533, 3532,
|
||||
3531, 3530, 3529, 3528, 3527, 3526, 3526, 3525},
|
||||
43
|
||||
);
|
||||
private static final Cuboid MAIN_WILDERNESS_CUBOID = new Cuboid(2944, 3525, 0, 3391, 4351, 3);
|
||||
private static final Cuboid GOD_WARS_WILDERNESS_CUBOID = new Cuboid(3008, 10112, 0, 3071, 10175, 3);
|
||||
private static final Cuboid WILDERNESS_UNDERGROUND_CUBOID = new Cuboid(2944, 9920, 0, 3391, 10879, 3);
|
||||
|
||||
/**
|
||||
* Gets the wilderness level based on a world point
|
||||
* Java reimplementation of clientscript 384 [proc,wilderness_level]
|
||||
*
|
||||
* @param point the point in the world to get the wilderness level for
|
||||
* @return the int representing the wilderness level
|
||||
*/
|
||||
public static int getWildernessLevelFrom(WorldPoint point)
|
||||
{
|
||||
if (MAIN_WILDERNESS_CUBOID.contains(point))
|
||||
{
|
||||
if (NOT_WILDERNESS_BLACK_KNIGHTS.contains(point.getX(), point.getY()))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((point.getY() - 3520) / 8) + 1; // calc(((coordz(coord) - (55 * 64)) / 8) + 1)
|
||||
}
|
||||
else if (GOD_WARS_WILDERNESS_CUBOID.contains(point))
|
||||
{
|
||||
return ((point.getY() - 9920) / 8) - 1; // calc(((coordz(coord) - (155 * 64)) / 8) - 1)
|
||||
}
|
||||
else if (WILDERNESS_UNDERGROUND_CUBOID.contains(point))
|
||||
{
|
||||
return ((point.getY() - 9920) / 8) + 1; // calc(((coordz(coord) - (155 * 64)) / 8) + 1)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if another player is attackable based off of wilderness level and combat levels
|
||||
*
|
||||
* @param client The client of the local player
|
||||
* @param player the player to determine attackability
|
||||
* @return returns true if the player is attackable, false otherwise
|
||||
*/
|
||||
public static boolean isAttackable(Client client, Player player)
|
||||
{
|
||||
int wildernessLevel = 0;
|
||||
|
||||
if (WorldType.isDeadmanWorld(client.getWorldType()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (WorldType.isPvpWorld(client.getWorldType()))
|
||||
{
|
||||
wildernessLevel += 15;
|
||||
}
|
||||
if (client.getVar(Varbits.IN_WILDERNESS) == 1)
|
||||
{
|
||||
wildernessLevel += getWildernessLevelFrom(client.getLocalPlayer().getWorldLocation());
|
||||
}
|
||||
return wildernessLevel != 0 && Math.abs(client.getLocalPlayer().getCombatLevel() - player.getCombatLevel()) <= wildernessLevel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user