mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
More plugin system work
This commit is contained in:
parent
a6577064b0
commit
8dfbcb9423
8 changed files with 91 additions and 9 deletions
|
|
@ -6,6 +6,7 @@ import rt4.Player;
|
|||
/**
|
||||
* The base plugin class which is meant to be extended by plugins.
|
||||
* Contains callbacks to many parts of the internal client code.
|
||||
* @author ceikry
|
||||
*/
|
||||
public abstract class Plugin {
|
||||
long timeOfLastDraw;
|
||||
|
|
@ -55,4 +56,6 @@ public abstract class Plugin {
|
|||
* @param screenY the Y coordinate on the screen for overhead drawing
|
||||
*/
|
||||
public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {}
|
||||
|
||||
public void ProcessCommand(String commandStr, String[] args) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package plugin;
|
||||
|
||||
import rt4.GlobalJsonConfig;
|
||||
import rt4.JagString;
|
||||
import rt4.Npc;
|
||||
import rt4.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
|
|
@ -90,4 +92,10 @@ public class PluginRepository {
|
|||
public static void PlayerOverheadDraw(Player player, int screenX, int screenY) {
|
||||
loadedPlugins.values().forEach((plugin) -> plugin.PlayerOverheadDraw(player, screenX, screenY));
|
||||
}
|
||||
|
||||
public static void ProcessCommand(JagString commandStr) {
|
||||
String[] tokens = commandStr.toString().split(" ");
|
||||
String[] args = Arrays.copyOfRange(tokens, 1, tokens.length);
|
||||
loadedPlugins.values().forEach((plugin) -> plugin.ProcessCommand(tokens[0], args));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package plugin.api;
|
||||
|
||||
import rt4.Font;
|
||||
import rt4.Fonts;
|
||||
import rt4.JagString;
|
||||
import rt4.*;
|
||||
|
||||
/**
|
||||
* API used for writing plugins, so dozens of plugins don't break when we rename shit :)
|
||||
* @author ceikry
|
||||
*/
|
||||
public class API {
|
||||
public static void DrawText(FontType fontType, FontColor color, TextModifier mod, String text, int screenX, int screenY) {
|
||||
JagString js = JagString.parse(text);
|
||||
|
|
@ -41,4 +43,8 @@ public class API {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean PlayerHasPrivilege(Privileges privilege) {
|
||||
return LoginManager.staffModLevel >= privilege.ordinal();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
client/src/main/java/plugin/api/Privileges.java
Normal file
7
client/src/main/java/plugin/api/Privileges.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package plugin.api;
|
||||
|
||||
public enum Privileges {
|
||||
NONE,
|
||||
PMOD,
|
||||
JMOD
|
||||
}
|
||||
|
|
@ -109,6 +109,7 @@ public class Cheat {
|
|||
|
||||
@OriginalMember(owner = "client!k", name = "a", descriptor = "(Lclient!na;Z)V")
|
||||
public static void execute(@OriginalArg(0) JagString arg0) {
|
||||
PluginRepository.ProcessCommand(arg0);
|
||||
// if (LoginManager.staffModLevel >= 2) {
|
||||
@Pc(18) int local18;
|
||||
@Pc(38) int local38;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,46 @@ test {
|
|||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
task buildPlugins {
|
||||
dependsOn(classes)
|
||||
task initializeNewPlugin {
|
||||
doLast {
|
||||
def pluginFile = new File("src/main/java/MyPlugin")
|
||||
pluginFile.mkdirs()
|
||||
|
||||
def props = new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/java/MyPlugin/plugin.properties").text = """
|
||||
AUTHOR='Me'
|
||||
DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java!
|
||||
VERSION=-1.1
|
||||
"""
|
||||
def java = new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/java/MyPlugin/plugin.java").text = """
|
||||
package MyPlugin;
|
||||
|
||||
import plugin.Plugin;
|
||||
|
||||
public class plugin extends Plugin {
|
||||
@Override
|
||||
public void Init() {
|
||||
//Init() is called when the plugin is loaded
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Update() {
|
||||
//Update() is called once per tick (600ms)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Draw(long deltaTime) {
|
||||
//Draw() is called once per frame, with deltaTime being the time since last frame.
|
||||
}
|
||||
|
||||
//Check the source of plugin.Plugin for more methods you can override! Happy hacking! <3
|
||||
//There are also many methods to aid in plugin development in plugin.api.API
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
task buildPlugins(type: Copy, dependsOn: classes) {
|
||||
def pluginsPath = rootProject.project("client").projectDir.absolutePath + File.separator + "plugins"
|
||||
from "build/classes/java/main"
|
||||
into pluginsPath
|
||||
}
|
||||
|
|
@ -1,15 +1,19 @@
|
|||
package OverheadDebugPlugin;
|
||||
|
||||
import plugin.Plugin;
|
||||
import plugin.api.API;
|
||||
import plugin.api.FontColor;
|
||||
import plugin.api.FontType;
|
||||
import plugin.api.TextModifier;
|
||||
import plugin.api.*;
|
||||
import rt4.*;
|
||||
|
||||
/**
|
||||
* @author ceikry
|
||||
*/
|
||||
public class plugin extends Plugin {
|
||||
private boolean isEnabled = false;
|
||||
|
||||
@Override
|
||||
public void PlayerOverheadDraw(Player player, int screenX, int screenY) {
|
||||
if (!isEnabled) return;
|
||||
|
||||
API.DrawText(
|
||||
FontType.SMALL,
|
||||
FontColor.YELLOW,
|
||||
|
|
@ -22,6 +26,8 @@ public class plugin extends Plugin {
|
|||
|
||||
@Override
|
||||
public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {
|
||||
if (!isEnabled) return;
|
||||
|
||||
String npcSb =
|
||||
(npc.type.name.strEquals(JagString.parse("null"))
|
||||
? npc.type.getMultiNpc() != null
|
||||
|
|
@ -44,4 +50,13 @@ public class plugin extends Plugin {
|
|||
screenY
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ProcessCommand(String commandStr, String[] args) {
|
||||
if (!API.PlayerHasPrivilege(Privileges.JMOD)) return;
|
||||
|
||||
if (commandStr.equalsIgnoreCase("::npcdebug")) {
|
||||
isEnabled = !isEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
AUTHOR="Ceikry"
|
||||
DESCRIPTION="Renders helpful debug text over the heads of players and NPCs."
|
||||
VERSION=1.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue