LuaInMinecraftBukkt
Using lua script to make Bukkit plugin.
There are two lua script running modes here. The first one is default one, it is lua VM made by Java, and supports to lua 5.2. And the other one is native vm, it is supports to lua 5.4; about this mode, it is just support the server which is running in Windows or Linux, not MacOS.
Java to calculate 1 plus to 1000000000, it used time: 25s
Mode 2 to calculate 1 plus to 1000000000, it used time: 14s
Mode 1 to calculate 1 plus to 1000000000, it used time: bukkit break.
Install:
download this plugin, put in plugins folder and restart server.
Add a lua script plugin:
when you add this plugin, it will create a folder named 'plugins' in '[bukkit's plugins folder]/LuaInMinecraftBukkit/plugins'
into '[bukkit's plugins folder]/LuaInMinecraftBukkit/plugins' folder, and then create a folder named 'HelloLua' (You can make any name you want, in this example i call it HelloLua).
then, make a file named 'lua_plugin.yml' and write these text in this yml file.
Code (YAML):
# Display Name
displayName
: My Lua Plugin
# lua script id, make sure as same as folder name, and just contants a-zA-Z0-9
id
: HelloLua
# author
author
: SmileYik
# version
version
: 1.0
# dependens lua script ids
dependents
:
[
]
# soft dependents lua script ids
softDependents
:
[
]
after modify 'lua_plugin.yml', make a file named 'main.lua', and write
Code (Text):
-- get logger
local logger = self:getLogger()
command = {}
listener = {}
-- onEnable function will be run after load this script.
function onEnable()
logger:info("Hello lua!!!!!")
-- register a command
-- param two allow this format: '<lua script id>.<function>'
-- in this example, my lua script named 'HelloLua',
-- and this function is 'command.dispatch'.
-- then i will use 'HelloLua.command.dispatch'
luaBukkit.commandRegister:registerCommand(
"test", "HelloLua.command.dispatch"
)
-- register a player join event
-- the param two is as same as register command.
luaBukkit.eventRegister:registerListener(
"PlayerJoinEvent", "HelloLua.listener.onPlayerJoin", 2
)
end
-- onDisable function will be called after disable this script plugin.
function onDisable()
logger:info("I am disabled!")
end
function listener.onPlayerJoin(event)
local playername = event:getPlayer():getName()
event:setJoinMessage("Nice to meet you, " .. playername)
event:getPlayer():sendMessage("Hi" .. playername)
end
function command.dispatch(arg, sender, strs)
args = {}
if (sender == nil) then
args.isPlayer = arg[1]
args.sender = arg[2]
args.args = arg[3]
else
args.isPlayer = arg
args.sender = sender
args.args = strs
end
-- isPlayer(bool), sender(who), args(command params)
if (args.args[2] == "openInventory" and args.isPlayer) then
local inv = luaBukkit.server:createInventory(NIL, 27, "First window~")
args.sender:openInventory(inv)
logger:info("excute command over")
return
end
args.sender:sendMessage("this command is wrong!")
end
logger:info("Hello Lua, loaded!")
In quick start documentation you can see the running picture like that.
Have fun!
