Lua Paper API - tsukinoko-kun/papermc-web-api GitHub Wiki

All entities are always specified by their UUID.

Paper table

getEntityName(entity) function

Gets the display name of an Entity.

getEntityPersistentData(entity, key, type) function

Gets data from the PersistentDataContainer of the specified entity.

inspect function

Gets a human-readable string representation of the given object.

local testTable = {
    ["test"] = nil,
    ["test2"] = 42,
    ["test3"] = {
        ["test4"] = true,
        ["test5"] = function()
            print("test5")
        end,
        ["test6"] = {
            ["test7"] = "test7",
            ["test8"] = false,
            ["test9"] = function()
                print("test9")
            end
        }
    }
}

print(testTable)

print(Paper.inspect(testTable))

logs

[15:47:48 INFO]: table: 1e41cf99
[15:47:48 INFO]: {
[15:47:48 INFO]:         ["test3"] = {
[15:47:48 INFO]:                 ["test5"] = function </Users/frank/Downloads/mc/plugins/papermc-web-api/lua/init.lua:6>,
[15:47:48 INFO]:                 ["test6"] = {
[15:47:48 INFO]:                         ["test9"] = function </Users/frank/Downloads/mc/plugins/papermc-web-api/lua/init.lua:12>,
[15:47:48 INFO]:                         ["test7"] = "test7",
[15:47:48 INFO]:                         ["test8"] = false,
[15:47:48 INFO]:                 },
[15:47:48 INFO]:                 ["test4"] = true,
[15:47:48 INFO]:         },
[15:47:48 INFO]:         ["test2"] = 42,
[15:47:48 INFO]: }

registerApiFunction(name, function) function

Register a function to make it available for any player to execute.

Paper.registerApiFunction("hello", function(authorized)
    local name = Paper.getEntityName(authorized)
    Paper.sendMessage(authorized, "Hello " .. name)
end)

The function takes the UUID of the authorized player as the first parameter, this might be nil if no player is authorized.

This registered function can now be executed using the in-game command /lua hello or the API request /lua?script=hello.

sendBroadcastMessage(message) function

Send a message to all active players on the server.

sendMessage(receiver, message) function

Send a message to a specific player.

stop() function

Shut down the server.