-
Notifications
You must be signed in to change notification settings - Fork 1
Getting started
To begin using the API you will need to add this to your onEnable() method LuaCore.setupCore(this);, This is used in the API for various things.
NOTES:
1, setupCore is required for the core to work
2, If you used older versions you are likely calling LuaCore.setPlugin(this).
If this is the case please change it to LuaCore.setupCore(this)
registerItemEvents() -> You should only have 1 plugin on the server that uses this option, It is used to make the ItemBuilder#setUsable(boolean) function.
setVerbose(boolean) -> Used for getting extra debug messages
setDefaultMessageTrace(boolean) -> as of version 1.2.1, the verboseMessage and other verbose functions now support adding the call trace to the start of a message.
The structure looks something like some.package.ClassName:methodName:lineNumber -> message. By default the trace will not be included
setDefaultWarnTrace(boolean) -> same as message trace only for warnings
setDefaultErrorTrace(boolean) -> same as the others just for errors
In order to save anything requiring saving and to deal with lock files
you should add LuaCore.disable() to your onDisable() method, this is highly recommended but isn't required
Once you have your onEnable options setup, you should load all required resource folders (Auto loads sub folders)
all resources loaded by this API need to be in a sub folder due to the loading method.
example usage LuaManager.loadResourceFolder("foo");
You can call lua scripts in many ways refer to the LuaManager docs
Example event call using runEvent(script, LuaArgValue ... args)
The runEvent method calls an event(args) code block in the lua
@EventHandler
public void blockPlace(BlockPlaceEvent event) {
LuaManager.runEvent("test/Test.lua",
new LuaArgValue("player", event.getPlayer()),
new LuaArgValue("event", event),
new LuaArgValue("messageUtils", new LuaMessageUtils()));
}function event(args)
local event = args.event -- get the event from args
local player = args.player -- get the player from args
local messageUtils = args.messageUtils -- get the message utils from args
if player then -- check if player is not nil
if event then -- check if event is not nil
if event:getEventName() == "BlockPlaceEvent" then -- check if the event is a BlockPlaceEvent
print("BlockPlaceEvent triggered by " .. player:getName()) -- log the event to the console
messageUtils:playerSend(player, "You placed a block!") -- send a message to the player
end
end
end
end
return {
event = event
}