Cuberite Forum

Full Version: Not able to run command inside plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello,
I'm writing a plugin and no matter what I try, i allways have "insufficient privileges "/setblock"". Can anyone help me with that?
Here is the source:
Code:
PLUGIN = nil

function Initialize(Plugin)
    Plugin:SetName("VanillaFill")
    Plugin:SetVersion(1)

    -- Hooks

    PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that

    -- Command Bindings
    cPluginManager.BindCommand("/setblock", "vanillafill.setblock", setblock, " ~ Changes a block at X Y Z.");
--    cPluginManager.BindCommand("/fill", "vanillafill.fill", fill, " ~ Fills an area from X Y Z to X2 Y2 Z2.");

    LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
    return true
end

function OnDisable()
    LOG(PLUGIN:GetName() .. " is shutting down...")
end

function setblock(Split, Player)
    if (#Split ~= 4) then
        -- There was more or less than one argument (excluding the "/explode" bit)
        -- Send the proper usage to the player and exit
        Player:SendMessage("Usage: /setblock X Y Z [blocktype]")
        return true
    end

    Player:GetWorld():SetBlock(Split[2], Split[3], Split[4], Split[5])

    return true
end
Console Log output:
Code:
[12:55:56] Player muellerCAM3 is executing command "/setblock" in world "world" at world age 237160.
[12:55:56] Player muellerCAM3 tried to execute forbidden command: "/setblock"
That's because you haven't given yourself more permissions than the basics that Cuberite has by default. You can make yourself admin using 'op muellerCAM3' in the console.
(02-18-2021, 10:42 PM)NiLSPACE Wrote: [ -> ]That's because you haven't given yourself more permissions than the basics that Cuberite has by default. You can make yourself admin using 'op muellerCAM3' in the console.

Thats the problem. I already did that. Didn't work. I even tried making a new group using the webadmin. Worked for all plugins except mine.
Could you show screenshots from the 'Player Ranks', 'Ranks' and 'Permissions' pages in the webadmin?
Ok, got it fixed now. something was messed up with my database.
But now there is a new problem: SetBlock wants a Vector3 and idk what that even is and how to make 3 strings into 1 Vector3.
Ok, this is what I came up with but it doesn't work:

outVector3 = {x = 0, y = 0, z = 0}
outVector3.x = tonumber(Split[2])
outVector3.y = tonumber(Split[3])
outVector3.z = tonumber(Split[4])
Player:GetWorld():SetBlock(outVector3, Split[5])

It gives this error:
argument #2 is 'table'; 'Vector3<int>' expected.
Vector3i is a class which we use to bundle up X, Y and Z coordinates. You can convert the 3 strings using this:
Vector3i(tonumber(string1), tonumber(string2), tonumber(string3))
Ok, idk why but it wants BlockType to be a number? Why?

Code:
error in function 'SetBlock'.
    argument #3 is 'string'; 'number' expected.
 
Here is the plugin as far as I am right now:

Code:
PLUGIN = nil

function Initialize(Plugin)
    Plugin:SetName("VanillaFill")
    Plugin:SetVersion(1)

    -- Hooks

    PLUGIN = Plugin -- NOTE: only needed if you want OnDisable() to use GetName() or something like that

    -- Command Bindings
    cPluginManager.BindCommand("/setblock", "vanillafill.setblock", setblock, " ~ Changes a block at X Y Z.");
--    cPluginManager.BindCommand("/fill", "vanillafill.fill", fill, " ~ Fills an area from X Y Z to X2 Y2 Z2.");

    LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
    return true
end

function OnDisable()
    LOG(PLUGIN:GetName() .. " is shutting down...")
end

function setblock(Split, Player)
    if (#Split ~= 5) then
        -- There was more or less than four arguments (excluding the "/explode" bit)
        -- Send the proper usage to the player and exit
        Player:SendMessage("Usage: /setblock X Y Z [blocktype]")
        return true
    end

    outVector3 = Vector3i(tonumber(Split[2]), tonumber(Split[3]), tonumber(Split[4]))

    Player:GetWorld():SetBlock(outVector3, Split[5])

    return true
end
cWorld:SetBlock doesn't automatically translate strings to the blocktype and meta. You could take WorldEdit's GetBlockTypeMeta function to do this: https://github.com/cuberite/WorldEdit/bl...ns.lua#L12

local type, meta = GetBlockTypeMeta(Split[5])
Player:GetWorld():SetBlock(outVector, type, meta)
We're still using the numeric identification for blocks which was removed by mojang in 1.13. At this point you'll have to use a number. We're working on it

Edit: isn't the C++ function to do this exported to lua? I know there is one in the code
Pages: 1 2