Skip to content

Putting it all together

You now have six small plugins, so let's turn them into one plugin that's ready to share. Make a new folder called MyServerTools and put two files in it.

plugin.yml
name: MyServerTools
version: "1.0"
main: main.lua
author: YourName
description: Heal, feed, fly, rules and join and leave messages
main.lua
plugin.addCommand({
    name = "heal",
    description = "Heal yourself",
    usage = "/heal"
}, function(event)
    local player = event.getSender()
    player:setHealth(20)
    player:sendMessage("Healed!")
end)

plugin.addCommand({
    name = "feed",
    description = "Fill your hunger bar",
    usage = "/feed"
}, function(event)
    local player = event.getSender()
    player:setFoodLevel(20)
    player:sendMessage("Fed!")
end)

plugin.addCommand({
    name = "fly",
    description = "Toggle flying",
    usage = "/fly"
}, function(event)
    local player = event.getSender()
    local canFly = not player:getAllowFlight()
    player:setAllowFlight(canFly)
    if canFly then
        player:sendMessage("Flying is on! Double-tap space to fly.")
    else
        player:sendMessage("Flying is off.")
    end
end)

plugin.addCommand({
    name = "rules",
    description = "Show the server rules",
    usage = "/rules"
}, function(event)
    local sender = event.getSender()
    sender:sendMessage("Server rules:")
    sender:sendMessage("1. Be kind to everyone.")
    sender:sendMessage("2. No griefing.")
    sender:sendMessage("3. Have fun!")
end)

plugin.registerEvent("PlayerJoinEvent", function(event)
    local player = event:getPlayer()
    player:sendMessage("Welcome, " .. player:getName() .. "!")
end)

plugin.registerEvent("PlayerQuitEvent", function(event)
    local player = event:getPlayer()
    logger.info(player:getName() .. " left the server.")
end)

That's every plugin from this section in one file. Each command and event works on its own, so they all fit together without any changes.

Share it

To turn it into something you can share, select main.lua and plugin.yml, make them into a zip file, and rename it to MyServerTools.lkt, just like on the .lkt page. Then upload that file to the JAR generator and download your .jar.

That's the end of Getting the hang of it. Next up is Basics.