1/n
This commit is contained in:
@@ -1,27 +1,33 @@
|
||||
package com.openosrs.client;
|
||||
|
||||
import com.openosrs.client.game.NPCStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
public class OpenOSRS
|
||||
{
|
||||
public static final File OPENOSRS_DIR = new File(System.getProperty("user.home"), ".openosrs");
|
||||
public static final File EXTERNALPLUGIN_DIR = new File(OPENOSRS_DIR, "plugins");
|
||||
public static final String SYSTEM_VERSION = "0.0.1";
|
||||
public static final String SYSTEM_VERSION;
|
||||
|
||||
public static String uuid = UUID.randomUUID().toString();
|
||||
|
||||
public static void init()
|
||||
static
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
try
|
||||
{
|
||||
NPCStats.loadStats();
|
||||
properties.load(OpenOSRS.class.getResourceAsStream("/openosrs.properties"));
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
SYSTEM_VERSION = properties.getProperty("oprs.version", "0.0.0");
|
||||
}
|
||||
|
||||
public static void preload()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.Keybind;
|
||||
import net.runelite.client.config.Range;
|
||||
import net.runelite.client.config.Units;
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||
|
||||
@ConfigGroup("openosrs")
|
||||
public interface OpenOSRSConfig extends Config
|
||||
@@ -136,7 +136,7 @@ public interface OpenOSRSConfig extends Config
|
||||
)
|
||||
default String getExternalRepositories()
|
||||
{
|
||||
return ExternalPluginManager.DEFAULT_PLUGIN_REPOS;
|
||||
return OPRSExternalPluginManager.DEFAULT_PLUGIN_REPOS;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
|
||||
@@ -25,11 +25,10 @@
|
||||
package com.openosrs.client.events;
|
||||
|
||||
import lombok.Data;
|
||||
import net.runelite.api.events.Event;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
|
||||
@Data
|
||||
public class ExternalPluginChanged implements Event
|
||||
public class ExternalPluginChanged
|
||||
{
|
||||
private final String pluginId;
|
||||
private final Plugin plugin;
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
package com.openosrs.client.events;
|
||||
|
||||
import lombok.Data;
|
||||
import net.runelite.api.events.Event;
|
||||
|
||||
@Data
|
||||
public class ExternalPluginsLoaded implements Event
|
||||
public class ExternalPluginsLoaded
|
||||
{}
|
||||
|
||||
@@ -25,10 +25,9 @@
|
||||
package com.openosrs.client.events;
|
||||
|
||||
import lombok.Data;
|
||||
import net.runelite.api.events.Event;
|
||||
|
||||
@Data
|
||||
public class ExternalRepositoryChanged implements Event
|
||||
public class ExternalRepositoryChanged
|
||||
{
|
||||
private final String owner;
|
||||
private final boolean added;
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, TheStonedTurtle <https://github.com/TheStonedTurtle>
|
||||
* 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.game;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
|
||||
@Value
|
||||
@Builder(builderClassName = "Builder")
|
||||
public class NPCStats
|
||||
{
|
||||
public static ImmutableMap<Integer, NPCStats> statsMap;
|
||||
|
||||
String name;
|
||||
|
||||
int hitpoints;
|
||||
int combatLevel;
|
||||
int slayerLevel;
|
||||
int attackSpeed;
|
||||
|
||||
int attackLevel;
|
||||
int strengthLevel;
|
||||
int defenceLevel;
|
||||
int rangeLevel;
|
||||
int magicLevel;
|
||||
|
||||
int stab;
|
||||
int slash;
|
||||
int crush;
|
||||
int range;
|
||||
int magic;
|
||||
|
||||
int stabDef;
|
||||
int slashDef;
|
||||
int crushDef;
|
||||
int rangeDef;
|
||||
int magicDef;
|
||||
|
||||
int bonusAttack;
|
||||
int bonusStrength;
|
||||
int bonusRangeStrength;
|
||||
int bonusMagicDamage;
|
||||
|
||||
boolean poisonImmune;
|
||||
boolean venomImmune;
|
||||
|
||||
boolean dragon;
|
||||
boolean demon;
|
||||
boolean undead;
|
||||
|
||||
/**
|
||||
* Based off the formula found here: http://services.runescape.com/m=forum/c=PLuJ4cy6gtA/forums.ws?317,318,712,65587452,209,337584542#209
|
||||
*
|
||||
* @return bonus XP modifier
|
||||
*/
|
||||
public double calculateXpModifier()
|
||||
{
|
||||
final double averageLevel = Math.floor((attackLevel + strengthLevel + defenceLevel + hitpoints) / 4);
|
||||
final double averageDefBonus = Math.floor((stabDef + slashDef + crushDef) / 3);
|
||||
|
||||
return (1 + Math.floor(averageLevel * (averageDefBonus + bonusStrength + bonusAttack) / 5120) / 40);
|
||||
}
|
||||
|
||||
// Because this class is here we can't add the TypeAdapter to gson (easily)
|
||||
// doesn't mean we can't use one to do it a bit quicker
|
||||
public static final TypeAdapter<NPCStats> NPC_STATS_TYPE_ADAPTER = new TypeAdapter<NPCStats>()
|
||||
{
|
||||
@Override
|
||||
public void write(JsonWriter out, NPCStats value)
|
||||
{
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCStats read(JsonReader in) throws IOException
|
||||
{
|
||||
in.beginObject();
|
||||
NPCStats.Builder builder = NPCStats.builder();
|
||||
|
||||
// Name is the only one that's guaranteed
|
||||
in.skipValue();
|
||||
builder.name(in.nextString());
|
||||
|
||||
while (in.hasNext())
|
||||
{
|
||||
switch (in.nextName())
|
||||
{
|
||||
case "hitpoints":
|
||||
builder.hitpoints(in.nextInt());
|
||||
break;
|
||||
case "combatLevel":
|
||||
builder.combatLevel(in.nextInt());
|
||||
break;
|
||||
case "slayerLevel":
|
||||
builder.slayerLevel(in.nextInt());
|
||||
break;
|
||||
case "attackSpeed":
|
||||
builder.attackSpeed(in.nextInt());
|
||||
break;
|
||||
case "attackLevel":
|
||||
builder.attackLevel(in.nextInt());
|
||||
break;
|
||||
case "strengthLevel":
|
||||
builder.strengthLevel(in.nextInt());
|
||||
break;
|
||||
case "defenceLevel":
|
||||
builder.defenceLevel(in.nextInt());
|
||||
break;
|
||||
case "rangeLevel":
|
||||
builder.rangeLevel(in.nextInt());
|
||||
break;
|
||||
case "magicLevel":
|
||||
builder.magicLevel(in.nextInt());
|
||||
break;
|
||||
case "stab":
|
||||
builder.stab(in.nextInt());
|
||||
break;
|
||||
case "slash":
|
||||
builder.slash(in.nextInt());
|
||||
break;
|
||||
case "crush":
|
||||
builder.crush(in.nextInt());
|
||||
break;
|
||||
case "range":
|
||||
builder.range(in.nextInt());
|
||||
break;
|
||||
case "magic":
|
||||
builder.magic(in.nextInt());
|
||||
break;
|
||||
case "stabDef":
|
||||
builder.stabDef(in.nextInt());
|
||||
break;
|
||||
case "slashDef":
|
||||
builder.slashDef(in.nextInt());
|
||||
break;
|
||||
case "crushDef":
|
||||
builder.crushDef(in.nextInt());
|
||||
break;
|
||||
case "rangeDef":
|
||||
builder.rangeDef(in.nextInt());
|
||||
break;
|
||||
case "magicDef":
|
||||
builder.magicDef(in.nextInt());
|
||||
break;
|
||||
case "bonusAttack":
|
||||
builder.bonusAttack(in.nextInt());
|
||||
break;
|
||||
case "bonusStrength":
|
||||
builder.bonusStrength(in.nextInt());
|
||||
break;
|
||||
case "bonusRangeStrength":
|
||||
builder.bonusRangeStrength(in.nextInt());
|
||||
break;
|
||||
case "bonusMagicDamage":
|
||||
builder.bonusMagicDamage(in.nextInt());
|
||||
break;
|
||||
case "poisonImmune":
|
||||
builder.poisonImmune(in.nextBoolean());
|
||||
break;
|
||||
case "venomImmune":
|
||||
builder.venomImmune(in.nextBoolean());
|
||||
break;
|
||||
case "dragon":
|
||||
builder.dragon(in.nextBoolean());
|
||||
break;
|
||||
case "demon":
|
||||
builder.demon(in.nextBoolean());
|
||||
break;
|
||||
case "undead":
|
||||
builder.undead(in.nextBoolean());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in.endObject();
|
||||
return builder.build();
|
||||
}
|
||||
};
|
||||
|
||||
public static void loadStats() throws IOException
|
||||
{
|
||||
try (JsonReader reader = new JsonReader(new InputStreamReader(NPCStats.class.getResourceAsStream("npc_stats.json"), StandardCharsets.UTF_8)))
|
||||
{
|
||||
ImmutableMap.Builder<Integer, NPCStats> builder = ImmutableMap.builderWithExpectedSize(2821);
|
||||
reader.beginObject();
|
||||
|
||||
while (reader.hasNext())
|
||||
{
|
||||
builder.put(
|
||||
Integer.parseInt(reader.nextName()),
|
||||
NPCStats.NPC_STATS_TYPE_ADAPTER.read(reader)
|
||||
);
|
||||
}
|
||||
|
||||
reader.endObject();
|
||||
statsMap = builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
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
@@ -1,9 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -27,8 +27,8 @@
|
||||
package com.openosrs.client.plugins.openosrs;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import com.openosrs.client.plugins.openosrs.externals.ExternalPluginManagerPanel;
|
||||
import com.openosrs.client.config.OpenOSRSConfig;
|
||||
import com.openosrs.client.plugins.openosrs.externals.ExternalPluginManagerPanel;
|
||||
import java.awt.image.BufferedImage;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@@ -78,6 +78,10 @@ public class OpenOSRSPlugin extends Plugin
|
||||
@Override
|
||||
public void hotkeyPressed()
|
||||
{
|
||||
if (client == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
detach = !detach;
|
||||
client.setOculusOrbState(detach ? 1 : 0);
|
||||
client.setOculusOrbNormalSpeed(detach ? 36 : 12);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@@ -46,12 +46,12 @@ public class ExternalPluginManagerPanel extends PluginPanel
|
||||
ADD_HOVER_ICON_GH = new ImageIcon(ImageUtil.alphaOffset(addIconGh, 0.53f));
|
||||
}
|
||||
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
private final OPRSExternalPluginManager externalPluginManager;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final EventBus eventBus;
|
||||
|
||||
@Inject
|
||||
private ExternalPluginManagerPanel(ExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
|
||||
private ExternalPluginManagerPanel(OPRSExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
|
||||
{
|
||||
super(false);
|
||||
|
||||
@@ -134,7 +134,7 @@ public class ExternalPluginManagerPanel extends PluginPanel
|
||||
return;
|
||||
}
|
||||
|
||||
if (ExternalPluginManager.testGHRepository(owner.getText(), name.getText()))
|
||||
if (OPRSExternalPluginManager.testGHRepository(owner.getText(), name.getText()))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
@@ -222,7 +222,7 @@ public class ExternalPluginManagerPanel extends PluginPanel
|
||||
return;
|
||||
}
|
||||
|
||||
if (ExternalPluginManager.testRepository(urlActual))
|
||||
if (OPRSExternalPluginManager.testRepository(urlActual))
|
||||
{
|
||||
JOptionPane.showMessageDialog(ClientUI.getFrame(), "This doesn't appear to be a valid repository.", "Error!",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.openosrs.client.events.ExternalPluginChanged;
|
||||
import com.openosrs.client.events.ExternalRepositoryChanged;
|
||||
import com.openosrs.client.util.DeferredDocumentChangedListener;
|
||||
import com.openosrs.client.util.ImageUtil;
|
||||
import net.runelite.client.util.DeferredDocumentChangedListener;
|
||||
import com.openosrs.client.util.SwingUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
@@ -45,6 +44,7 @@ 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 net.runelite.client.util.ImageUtil;
|
||||
import org.pf4j.update.PluginInfo;
|
||||
import org.pf4j.update.UpdateManager;
|
||||
import org.pf4j.update.UpdateRepository;
|
||||
@@ -82,7 +82,7 @@ public class PluginsPanel extends JPanel
|
||||
DELETE_HOVER_ICON_GRAY = new ImageIcon(ImageUtil.alphaOffset(ImageUtil.grayscaleImage(deleteImg), 0.53f));
|
||||
}
|
||||
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
private final OPRSExternalPluginManager externalPluginManager;
|
||||
private final UpdateManager updateManager;
|
||||
private final ScheduledExecutorService executor;
|
||||
private final EventBus eventBus;
|
||||
@@ -97,7 +97,7 @@ public class PluginsPanel extends JPanel
|
||||
private JComboBox<String> filterComboBox;
|
||||
private Set<String> deps;
|
||||
|
||||
PluginsPanel(ExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
|
||||
PluginsPanel(OPRSExternalPluginManager externalPluginManager, ScheduledExecutorService executor, EventBus eventBus)
|
||||
{
|
||||
this.externalPluginManager = externalPluginManager;
|
||||
this.updateManager = externalPluginManager.getUpdateManager();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||
import com.openosrs.client.ui.JMultilineLabel;
|
||||
import com.openosrs.client.util.ImageUtil;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@@ -19,6 +18,7 @@ import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
import org.pf4j.update.PluginInfo;
|
||||
import org.pf4j.update.UpdateRepository;
|
||||
@@ -53,7 +53,7 @@ public class RepositoryBox extends JPanel
|
||||
DISCORD_HOVER_ICON = new ImageIcon(ImageUtil.alphaOffset(discordImg, 0.53f));
|
||||
}
|
||||
|
||||
RepositoryBox(ExternalPluginManager externalPluginManager, UpdateRepository updateRepository)
|
||||
RepositoryBox(OPRSExternalPluginManager externalPluginManager, UpdateRepository updateRepository)
|
||||
{
|
||||
setLayout(new BorderLayout());
|
||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.openosrs.client.plugins.openosrs.externals;
|
||||
|
||||
import com.openosrs.client.plugins.ExternalPluginManager;
|
||||
import net.runelite.client.plugins.OPRSExternalPluginManager;
|
||||
import com.openosrs.client.events.ExternalRepositoryChanged;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
@@ -18,11 +18,11 @@ public class RepositoryPanel extends JPanel
|
||||
@Inject
|
||||
public EventBus eventBus;
|
||||
|
||||
private final ExternalPluginManager externalPluginManager;
|
||||
private final OPRSExternalPluginManager externalPluginManager;
|
||||
|
||||
private final GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
RepositoryPanel(ExternalPluginManager externalPluginManager, EventBus eventBus)
|
||||
RepositoryPanel(OPRSExternalPluginManager externalPluginManager, EventBus eventBus)
|
||||
{
|
||||
this.externalPluginManager = externalPluginManager;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package com.openosrs.client.ui.components;
|
||||
|
||||
import com.openosrs.client.OpenOSRS;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
@@ -88,7 +89,7 @@ public class InfoPanel extends JPanel
|
||||
c.weighty = 0;
|
||||
|
||||
// OpenOSRS version
|
||||
this.add(createPanelTextButton("OpenOSRS Version: " + RuneLiteProperties.getLauncherVersion()), c);
|
||||
this.add(createPanelTextButton("OpenOSRS Version: " + OpenOSRS.SYSTEM_VERSION), c);
|
||||
c.gridy++;
|
||||
|
||||
final JLabel logsFolder = createPanelButton("Open logs folder", null, () -> LinkBrowser.openLocalFile(LOGS_DIR));
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.openosrs.client.util;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class ColorUtil extends net.runelite.client.util.ColorUtil
|
||||
{
|
||||
/**
|
||||
* Modifies the alpha component on a Color
|
||||
*
|
||||
* @param color The color to set the alpha value on
|
||||
* @param alpha The alpha value to set on the color
|
||||
* @return color
|
||||
*/
|
||||
public static int setAlphaComponent(Color color, int alpha)
|
||||
{
|
||||
return setAlphaComponent(color.getRGB(), alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies the alpha component on a Color
|
||||
*
|
||||
* @param color The color to set the alpha value on
|
||||
* @param alpha The alpha value to set on the color
|
||||
* @return color
|
||||
*/
|
||||
public static int setAlphaComponent(int color, int alpha)
|
||||
{
|
||||
if (alpha < 0 || alpha > 255)
|
||||
{
|
||||
throw new IllegalArgumentException("alpha must be between 0 and 255.");
|
||||
}
|
||||
return (color & 0x00ffffff) | (alpha << 24);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.openosrs.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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package com.openosrs.client.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ImageUtil extends net.runelite.client.util.ImageUtil
|
||||
{
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user