More plugin system work

This commit is contained in:
ceikry 2022-07-10 09:58:08 -05:00 committed by Ceikry
parent a6577064b0
commit 8dfbcb9423
8 changed files with 91 additions and 9 deletions

View file

@ -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
}

View file

@ -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;
}
}
}

View file

@ -0,0 +1,3 @@
AUTHOR="Ceikry"
DESCRIPTION="Renders helpful debug text over the heads of players and NPCs."
VERSION=1.0