mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-10 10:20:44 -07:00
Update to allow plugin metadata definition from annotations and load other classes in same folder as plugin.class.
This commit is contained in:
parent
9750195081
commit
3e12a9115d
15 changed files with 122 additions and 68 deletions
|
|
@ -1,4 +0,0 @@
|
||||||
|
|
||||||
AUTHOR='Ceikry'
|
|
||||||
DESCRIPTION='Draws some info about varp changes on the screen.'
|
|
||||||
VERSION=-1.0
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package plugin;
|
package plugin;
|
||||||
|
|
||||||
|
import plugin.annotations.PluginMeta;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
|
|
@ -42,6 +44,20 @@ class PluginInfo {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PluginInfo loadFromClass(Class<?> clazz) {
|
||||||
|
PluginMeta info = clazz.getAnnotation(PluginMeta.class);
|
||||||
|
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PluginInfo(
|
||||||
|
info.author(),
|
||||||
|
info.description(),
|
||||||
|
info.version()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responsible for loading and broadcasting methods to all plugins.
|
* Responsible for loading and broadcasting methods to all plugins.
|
||||||
|
|
@ -39,16 +41,11 @@ public class PluginRepository {
|
||||||
|
|
||||||
for(File file : Objects.requireNonNull(pluginsDirectory.listFiles())) {
|
for(File file : Objects.requireNonNull(pluginsDirectory.listFiles())) {
|
||||||
if(!file.isDirectory()) continue;
|
if(!file.isDirectory()) continue;
|
||||||
|
if(file.getName().equals("META-INF")) continue;
|
||||||
|
|
||||||
File infoFile = new File(file.getAbsoluteFile() + File.separator + "plugin.properties");
|
File infoFile = new File(file.getAbsoluteFile() + File.separator + "plugin.properties");
|
||||||
File pluginRoot = new File(file.getAbsoluteFile() + File.separator + "plugin.class");
|
File pluginRoot = new File(file.getAbsoluteFile() + File.separator + "plugin.class");
|
||||||
|
|
||||||
PluginInfo info;
|
|
||||||
if (infoFile.exists())
|
|
||||||
info = PluginInfo.loadFromFile(infoFile);
|
|
||||||
else
|
|
||||||
info = new PluginInfo("Unknown", "", 1.0);
|
|
||||||
|
|
||||||
if (!pluginRoot.exists()) {
|
if (!pluginRoot.exists()) {
|
||||||
System.err.println("Unable to load plugin " + file.getName() + " because plugin.class is absent!");
|
System.err.println("Unable to load plugin " + file.getName() + " because plugin.class is absent!");
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -56,6 +53,17 @@ public class PluginRepository {
|
||||||
|
|
||||||
Class<?> clazz = loader.loadClass(file.getName() + ".plugin");
|
Class<?> clazz = loader.loadClass(file.getName() + ".plugin");
|
||||||
|
|
||||||
|
PluginInfo info;
|
||||||
|
if (infoFile.exists())
|
||||||
|
info = PluginInfo.loadFromFile(infoFile);
|
||||||
|
else
|
||||||
|
info = PluginInfo.loadFromClass(clazz);
|
||||||
|
|
||||||
|
if (info == null) {
|
||||||
|
System.err.println("Unable to load plugin " + file.getName() + " because it contains no information about author, version, etc!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Plugin thisPlugin = (Plugin) clazz.newInstance();
|
Plugin thisPlugin = (Plugin) clazz.newInstance();
|
||||||
thisPlugin._init();
|
thisPlugin._init();
|
||||||
|
|
@ -66,6 +74,15 @@ public class PluginRepository {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<File> otherClasses = Arrays.stream(Objects.requireNonNull(file.listFiles()))
|
||||||
|
.filter((f) ->
|
||||||
|
!f.getName().equals("plugin.class") && f.getName().contains(".class"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (File f : otherClasses) {
|
||||||
|
loader.loadClass(file.getName() + "." + f.getName().replace(".class",""));
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Successfully loaded plugin " + file.getName() + ", version " + info.version);
|
System.out.println("Successfully loaded plugin " + file.getName() + ", version " + info.version);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
||||||
11
client/src/main/java/plugin/annotations/PluginMeta.java
Normal file
11
client/src/main/java/plugin/annotations/PluginMeta.java
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
package plugin.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface PluginMeta {
|
||||||
|
String author();
|
||||||
|
String description();
|
||||||
|
double version();
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package InterfaceDebugPlugin;
|
package InterfaceDebugPlugin;
|
||||||
|
|
||||||
import plugin.Plugin;
|
import plugin.Plugin;
|
||||||
|
import plugin.annotations.PluginMeta;
|
||||||
import plugin.api.*;
|
import plugin.api.*;
|
||||||
import rt4.Component;
|
import rt4.Component;
|
||||||
import rt4.GameShell;
|
import rt4.GameShell;
|
||||||
|
|
@ -8,6 +9,11 @@ import rt4.GameShell;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@PluginMeta(
|
||||||
|
author = "Ceikry",
|
||||||
|
description = "Aids in identifying interface components/varps/model IDs.",
|
||||||
|
version = 1.2
|
||||||
|
)
|
||||||
public class plugin extends Plugin {
|
public class plugin extends Plugin {
|
||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
private boolean isVerbose;
|
private boolean isVerbose;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
AUTHOR='Ceikry'
|
|
||||||
DESCRIPTION='Enables visual display of component children and a log of interface-related varps.'
|
|
||||||
VERSION=1.1
|
|
||||||
|
|
@ -1,12 +1,15 @@
|
||||||
package OverheadDebugPlugin;
|
package OverheadDebugPlugin;
|
||||||
|
|
||||||
import plugin.Plugin;
|
import plugin.Plugin;
|
||||||
|
import plugin.annotations.PluginMeta;
|
||||||
import plugin.api.*;
|
import plugin.api.*;
|
||||||
import rt4.*;
|
import rt4.*;
|
||||||
|
|
||||||
/**
|
@PluginMeta(
|
||||||
* @author ceikry
|
author = "Ceikry",
|
||||||
*/
|
description = "Draws helpful overhead debug information.",
|
||||||
|
version = 1.3
|
||||||
|
)
|
||||||
public class plugin extends Plugin {
|
public class plugin extends Plugin {
|
||||||
private boolean isEnabled = false;
|
private boolean isEnabled = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
AUTHOR="Ceikry"
|
|
||||||
DESCRIPTION="Renders helpful debug text over the heads of players and NPCs."
|
|
||||||
VERSION=1.0
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
package VarpLogPlugin;
|
package VarpLogPlugin;
|
||||||
|
|
||||||
import plugin.Plugin;
|
import plugin.Plugin;
|
||||||
|
import plugin.annotations.PluginMeta;
|
||||||
import plugin.api.*;
|
import plugin.api.*;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@PluginMeta(
|
||||||
|
author = "Ceikry",
|
||||||
|
description = "Adds a simple log of varp changes drawn directly to the screen.",
|
||||||
|
version = 1.0
|
||||||
|
)
|
||||||
public class plugin extends Plugin {
|
public class plugin extends Plugin {
|
||||||
boolean isEnabled = false;
|
boolean isEnabled = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
AUTHOR='Ceikry'
|
|
||||||
DESCRIPTION='Draws some info about varp changes on the screen.'
|
|
||||||
VERSION=1.0
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package SlayerTrackerPlugin
|
package SlayerTrackerPlugin
|
||||||
|
|
||||||
import plugin.Plugin
|
import plugin.Plugin
|
||||||
|
import plugin.annotations.PluginMeta
|
||||||
import plugin.api.API
|
import plugin.api.API
|
||||||
import plugin.api.FontColor
|
import plugin.api.FontColor
|
||||||
import plugin.api.FontType
|
import plugin.api.FontType
|
||||||
|
|
@ -9,10 +10,11 @@ import rt4.Sprite
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
|
|
||||||
/**
|
@PluginMeta(
|
||||||
* Very simple slayer task tracker
|
author = "Ceikry",
|
||||||
* @author Ceikry
|
description = "Draws a simple slayer task tracker onto the screen if one is active.",
|
||||||
*/
|
version = 1.0
|
||||||
|
)
|
||||||
class plugin : Plugin() {
|
class plugin : Plugin() {
|
||||||
val boxColor = 6116423
|
val boxColor = 6116423
|
||||||
val posX = 5
|
val posX = 5
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
AUTHOR='Ceikry'
|
|
||||||
DESCRIPTION='Helps to keep track of kills remaining on a slayer task.'
|
|
||||||
VERSION=1.1
|
|
||||||
40
plugin-playground/src/main/kotlin/XPDropPlugin/XPSprites.kt
Normal file
40
plugin-playground/src/main/kotlin/XPDropPlugin/XPSprites.kt
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
package XPDropPlugin
|
||||||
|
|
||||||
|
import plugin.api.API
|
||||||
|
import rt4.Sprite
|
||||||
|
|
||||||
|
object XPSprites {
|
||||||
|
fun getSpriteForSkill(skillId: Int) : Sprite? {
|
||||||
|
return API.GetSprite(getSpriteId(skillId))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getSpriteId(skillId: Int) : Int {
|
||||||
|
return when (skillId) {
|
||||||
|
0 -> 197
|
||||||
|
1 -> 199
|
||||||
|
2 -> 198
|
||||||
|
3 -> 203
|
||||||
|
4 -> 200
|
||||||
|
5 -> 201
|
||||||
|
6 -> 202
|
||||||
|
7 -> 212
|
||||||
|
8 -> 214
|
||||||
|
9 -> 208
|
||||||
|
10 -> 211
|
||||||
|
11 -> 213
|
||||||
|
12 -> 207
|
||||||
|
13 -> 210
|
||||||
|
14 -> 209
|
||||||
|
15 -> 205
|
||||||
|
16 -> 204
|
||||||
|
17 -> 206
|
||||||
|
18 -> 216
|
||||||
|
19 -> 217
|
||||||
|
20 -> 215
|
||||||
|
21 -> 220
|
||||||
|
22 -> 221
|
||||||
|
23 -> 222
|
||||||
|
else -> 222
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
package XPDropPlugin;
|
package XPDropPlugin;
|
||||||
|
|
||||||
import plugin.Plugin
|
import plugin.Plugin
|
||||||
|
import plugin.annotations.PluginMeta
|
||||||
import plugin.api.*
|
import plugin.api.*
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
||||||
/**
|
@PluginMeta(
|
||||||
* Displays some simple XP drops.
|
author = "Ceikry",
|
||||||
* @author Ceikry
|
description = "Draws nice and clean experience drops onto the screen.",
|
||||||
*/
|
version = 1.2
|
||||||
|
)
|
||||||
class plugin : Plugin() {
|
class plugin : Plugin() {
|
||||||
private val displayTimeout = 10000L // 10 seconds
|
private val displayTimeout = 10000L // 10 seconds
|
||||||
private val drawStart = 175
|
private val drawStart = 175
|
||||||
|
|
@ -37,7 +39,7 @@ class plugin : Plugin() {
|
||||||
removeList.add(gain)
|
removeList.add(gain)
|
||||||
totalXp += gain.xp
|
totalXp += gain.xp
|
||||||
} else if (gain.currentPos <= drawStart){
|
} else if (gain.currentPos <= drawStart){
|
||||||
val sprite = API.GetSprite(getSpriteArchive(gain.skill))
|
val sprite = XPSprites.getSpriteForSkill(skillId = gain.skill)
|
||||||
sprite?.render(posX - 25, gain.currentPos - 20)
|
sprite?.render(posX - 25, gain.currentPos - 20)
|
||||||
API.DrawText(
|
API.DrawText(
|
||||||
FontType.SMALL,
|
FontType.SMALL,
|
||||||
|
|
@ -143,34 +145,4 @@ class plugin : Plugin() {
|
||||||
}
|
}
|
||||||
return newString.reversed()
|
return newString.reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSpriteArchive(skillId: Int): Int{
|
|
||||||
return when(skillId) {
|
|
||||||
0 -> 197
|
|
||||||
1 -> 199
|
|
||||||
2 -> 198
|
|
||||||
3 -> 203
|
|
||||||
4 -> 200
|
|
||||||
5 -> 201
|
|
||||||
6 -> 202
|
|
||||||
7 -> 212
|
|
||||||
8 -> 214
|
|
||||||
9 -> 208
|
|
||||||
10 -> 211
|
|
||||||
11 -> 213
|
|
||||||
12 -> 207
|
|
||||||
13 -> 210
|
|
||||||
14 -> 209
|
|
||||||
15 -> 205
|
|
||||||
16 -> 204
|
|
||||||
17 -> 206
|
|
||||||
18 -> 216
|
|
||||||
19 -> 217
|
|
||||||
20 -> 215
|
|
||||||
21 -> 220
|
|
||||||
22 -> 221
|
|
||||||
23 -> 222
|
|
||||||
else -> 222
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
AUTHOR='Ceikry'
|
|
||||||
DESCRIPTION='Displays some pretty awesome XP drops :)'
|
|
||||||
VERSION=1.1
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue