Skip to content

Commit

Permalink
Merge branch 'master' into Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiLSPACE committed Jun 14, 2024
2 parents 7279719 + f72e30a commit 8e99efb
Show file tree
Hide file tree
Showing 45 changed files with 2,453 additions and 1,513 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Lua
run: |
sudo apt install lua5.1 luarocks
sudo luarocks install luafilesystem
sudo luarocks install luacheck
- name: Set up environment
run: |
wget -O .luacheckrc 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/.luacheckrc?job=Windows-x64&pr=false&branch=master'
- name: Run tests
run: |
luacheck . --codes
23 changes: 23 additions & 0 deletions .luacheckrc_plugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- This file contains plugin specific options or tables for luacheck
-- It will be merged with cuberite's luacheck

-- Ignore variables / warning codes
-- Doc: http://luacheck.readthedocs.io/en/stable/warnings.html
ignore =
{
"122", -- Mutating read-only global variable
"131", -- Unused global variable
"142", -- Setting undefined field of global math, string, table
"143", -- Accessing undefined field of global math, table
"211", -- Unused variable
"221", -- Variable is never set
"231", -- Variable is never accessed
"311", -- Value assigned to variable is unused
"411", -- Variable was previously defined
"421", -- Shadowing definition of variable
"423", -- Shadowing definition of loop variable
"432", -- Shadowing upvalue argument
"531", -- Left-hand side of assignment is too short
"542", -- Empty if branch
"631", -- Line too long
}
18 changes: 8 additions & 10 deletions Api/Check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
-- a_HookName is the name of the hook to call. Everything after that are arguments for the hook.
function CallHook(a_HookName, ...)
assert(g_Hooks[a_HookName] ~= nil)

for idx, callback in ipairs(g_Hooks[a_HookName]) do
local res = cPluginManager:CallPlugin(callback.PluginName, callback.CallbackName, ...)
if (res) then
-- The callback wants to abort the operation
return true
end
end

return false
end

Expand All @@ -36,16 +36,14 @@ function GetMultipleBlockChanges(MinX, MaxX, MinZ, MaxZ, Player, World, Operatio
MaxY = Y
end
end

function Object:Flush()
local FinalCuboid = cCuboid(MinX, MinY, MinZ, MaxX, MaxY, MaxZ)
local FinalCuboid = cCuboid(
Vector3i(MinX, MinY, MinZ),
Vector3i(MaxX, MaxY, MaxZ)
)
return CallHook("OnAreaChanging", FinalCuboid, Player, World, Operation)
end

return Object
end





50 changes: 23 additions & 27 deletions Api/Manage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ g_Hooks = {
["OnAreaChanging"] = {}, -- Signature: function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation)
["OnAreaChanged"] = {}, -- Signature: function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation)
["OnAreaCopied"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid)
["OnAreaCopying"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid)
["OnAreaCopying"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid)
["OnPlayerSelectionChanging"] = {}, -- Signature: function(a_Player, a_PosX, a_PosY, a_PosZ, a_PointNr)
["OnPlayerSelectionChanged"] = {}, -- Signature: function(a_Player, a_PosX, a_PosY, a_PosZ, a_PointNr)
}
Expand All @@ -31,21 +31,21 @@ function AddHook(a_HookName, a_PluginName, a_CallbackName)
(type(a_PluginName) ~= "string") or (a_PluginName == "") or not cPluginManager:Get():IsPluginLoaded(a_PluginName) or
(type(a_CallbackName) ~= "string") or (a_CallbackName == "")
) then
LOGWARNING("[WorldEdit] Invalid callback registration parameters.")
LOGWARNING("Invalid callback registration parameters.")
LOGWARNING(" AddHook() was called with params " ..
tostring(a_HookName or "<nil>") .. ", " ..
tostring(a_PluginName or "<nil>") .. ", " ..
tostring(a_CallbackName or "<nil>")
)

return false
end

if (not g_Hooks[a_HookName]) then
LOGWARNING("[WorldEdit] Plugin \"" .. a_PluginName .. "\" tried to register an unexisting hook called \"" .. a_HookName .. "\"")
LOGWARNING("Plugin \"" .. a_PluginName .. "\" tried to register an unexisting hook called \"" .. a_HookName .. "\"")
return false
end

table.insert(g_Hooks[a_HookName], {PluginName = a_PluginName, CallbackName = a_CallbackName})
return true
end
Expand All @@ -60,7 +60,7 @@ end
-- function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation)
-- The callback should return true to abort the operation, false to continue.
function RegisterAreaCallback(a_PluginName, a_FunctionName, a_WorldName)
LOGWARNING("[WorldEdit] RegisterAreaCallback is obsolete. Please use AddHook(\"OnAreaChanging\", ...)")
LOGWARNING("RegisterAreaCallback is obsolete. Please use AddHook(\"OnAreaChanging\", ...)")
LOGWARNING(" The callback signature changed as well. All individual coordinates are now a single cCuboid")
return AddHook("OnAreaChanging", a_PluginName, a_FunctionName)
end
Expand All @@ -76,7 +76,7 @@ end
-- a_PointNr can be 0 for Left click or 1 for right click.
-- The callback should return true to abort the operation, or false to continue.
function RegisterPlayerSelectingPoint(a_PluginName, a_FunctionName)
LOGWARNING("[WorldEdit] RegisterPlayerSelectingPoint is obsolete. Please use AddHook(\"OnPlayerSelectionChanging\", ...)")
LOGWARNING("RegisterPlayerSelectingPoint is obsolete. Please use AddHook(\"OnPlayerSelectionChanging\", ...)")
LOGWARNING(" The callback signature changed as well. All individual coordinates are now a single cCuboid")
return AddHook("OnPlayerSelectionChanging", a_PluginName, a_FunctionName)
end
Expand All @@ -93,14 +93,14 @@ function SetPlayerCuboidSelection(a_Player, a_Cuboid)
(tolua.type(a_Player) ~= "cPlayer") or
(tolua.type(a_Cuboid) ~= "cCuboid")
) then
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelection API function parameters.")
LOGWARNING("Invalid SetPlayerCuboidSelection API function parameters.")
LOGWARNING(" SetPlayerCuboidSelection() was called with param types \"" ..
tolua.type(a_Player) .. "\" (\"cPlayer\" wanted) and \"" ..
tolua.type(a_Cuboid) .. "\" (\"cCuboid\" wanted)."
)
return false
end

-- Set the selection, both points:
local State = GetPlayerState(a_Player)
State.Selection:SetFirstPoint(a_Cuboid.p1.x, a_Cuboid.p1.y, a_Cuboid.p1.z)
Expand All @@ -121,23 +121,23 @@ function SetPlayerCuboidSelectionPoint(a_Player, a_PointNumber, a_CoordVector)
(tonumber(a_PointNumber) == nil) or
(tolua.type(a_CoordVector) ~= "Vector3i")
) then
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelectionPoint API function parameters.")
LOGWARNING("Invalid SetPlayerCuboidSelectionPoint API function parameters.")
LOGWARNING(" SetPlayerCuboidSelection() was called with param types \"" ..
tolua.type(a_Player) .. "\" (\"cPlayer\" wanted), \"" ..
type(a_PointNumber) .. "\" (\"number\" wanted) and \"" ..
tolua.type(a_CoordVector) .. "\" (\"cVector3i\" wanted)."
)
return false
end

-- Set the specified selection point:
local State = GetPlayerState(a_Player)
if (tonumber(a_PointNumber) == 1) then
State.Selection:SetFirstPoint(a_CoordVector)
elseif (tonumber(a_PointNumber) == 2) then
State.Selection:SetSecondPoint(a_CoordVector)
else
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelectionPoint API function parameters.")
LOGWARNING("Invalid SetPlayerCuboidSelectionPoint API function parameters.")
LOGWARNING(" SetPlayerCuboidSelection() was called with invalid point number " .. a_PointNumber)
return false
end
Expand Down Expand Up @@ -169,14 +169,14 @@ function GetPlayerCuboidSelection(a_Player, a_CuboidToSet)
(tolua.type(a_Player) ~= "cPlayer") or
(tolua.type(a_CuboidToSet) ~= "cCuboid")
) then
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelection API function parameters.")
LOGWARNING("Invalid SetPlayerCuboidSelection API function parameters.")
LOGWARNING(" SetPlayerCuboidSelection() was called with param types \"" ..
tolua.type(a_Player) .. "\" (\"cPlayer\" wanted) and \"" ..
tolua.type(a_CuboidToSet) .. "\" (\"cCuboid\" wanted)."
)
return false
end

-- Set the output cuboid to the selection:
local State = GetPlayerState(a_Player)
a_CuboidToSet:Assign(State.Selection.Cuboid)
Expand All @@ -201,15 +201,15 @@ function WEPushUndo(a_Player, a_World, a_Cuboid, a_Description)
(tolua.type(a_Cuboid) ~= "cCuboid") or
(type(a_Description) ~= "string")
) then
LOGWARNING("[WorldEdit] Invalid WEPushUndo API function parameters.")
LOGWARNING("Invalid WEPushUndo API function parameters.")
LOGWARNING(" WePushUndo() was called with these param types:")
LOGWARNING(" " .. tolua.type(a_Player) .. " (cPlayer wanted),")
LOGWARNING(" " .. tolua.type(a_World) .. " (cWorld wanted),")
LOGWARNING(" " .. tolua.type(a_Cuboid) .. " (cCuboid wanted),")
LOGWARNING(" " .. type(a_Description) .. " (string wanted),")
return false, "bad params"
end

-- Push the undo:
local State = GetPlayerState(a_Player)
return State.UndoStack:PushUndoFromCuboid(a_World, a_Cuboid, a_Description)
Expand Down Expand Up @@ -238,7 +238,7 @@ function WEPushUndoAsync(a_Player, a_World, a_Cuboid, a_Description, a_CallbackP
(type(a_CallbackPluginName) ~= "string") or
(type(a_CallbackFunctionName) ~= "string")
) then
LOGWARNING("[WorldEdit] Invalid WEPushUndoAsync() API function parameters.")
LOGWARNING("Invalid WEPushUndoAsync() API function parameters.")
LOGWARNING(" WePushUndo() was called with these param types:")
LOGWARNING(" " .. tolua.type(a_Player) .. " (cPlayer wanted),")
LOGWARNING(" " .. tolua.type(a_World) .. " (cWorld wanted),")
Expand All @@ -248,23 +248,23 @@ function WEPushUndoAsync(a_Player, a_World, a_Cuboid, a_Description, a_CallbackP
LOGWARNING(" " .. type(a_CallbackFunctionName) .. " (string wanted),")
return false, "bad params"
end

-- if the input cuboid isn't sorted, create a sorted copy:
if not(a_Cuboid:IsSorted()) then
a_Cuboid = cCuboid(a_Cuboid)
a_Cuboid:Sort()
end

-- Create a callback for the ChunkStay:
local State = GetPlayerState(a_Player) -- a_Player may be deleted in the meantime, but the State table won't
local OnAllChunksAvailable = function()
local IsSuccess, Msg = State.UndoStack:PushUndoFromCuboid(a_World, a_Cuboid, a_Description)
cPluginManager:CallPlugin(a_CallbackPluginName, a_CallbackFunctionName, IsSuccess, Msg)
end

-- Get a list of chunks that need to be present:
local Chunks = ListChunksForCuboid(a_Cuboid)

-- Initiate a ChunkStay operation, pushing the undo when all the chunks are available
a_World:ChunkStay(Chunks, nil, OnAllChunksAvailable)
return true
Expand All @@ -283,10 +283,6 @@ function ExecuteString(a_String, ...)
if (not Function) then
return false, Error
end

return pcall(Function, ...)
end




Loading

0 comments on commit 8e99efb

Please sign in to comment.