Skip to content

Commit 8e99efb

Browse files
committed
Merge branch 'master' into Tests
2 parents 7279719 + f72e30a commit 8e99efb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2453
-1513
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Install Lua
13+
run: |
14+
sudo apt install lua5.1 luarocks
15+
sudo luarocks install luafilesystem
16+
sudo luarocks install luacheck
17+
18+
- name: Set up environment
19+
run: |
20+
wget -O .luacheckrc 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/.luacheckrc?job=Windows-x64&pr=false&branch=master'
21+
22+
- name: Run tests
23+
run: |
24+
luacheck . --codes

.luacheckrc_plugin

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- This file contains plugin specific options or tables for luacheck
2+
-- It will be merged with cuberite's luacheck
3+
4+
-- Ignore variables / warning codes
5+
-- Doc: http://luacheck.readthedocs.io/en/stable/warnings.html
6+
ignore =
7+
{
8+
"122", -- Mutating read-only global variable
9+
"131", -- Unused global variable
10+
"142", -- Setting undefined field of global math, string, table
11+
"143", -- Accessing undefined field of global math, table
12+
"211", -- Unused variable
13+
"221", -- Variable is never set
14+
"231", -- Variable is never accessed
15+
"311", -- Value assigned to variable is unused
16+
"411", -- Variable was previously defined
17+
"421", -- Shadowing definition of variable
18+
"423", -- Shadowing definition of loop variable
19+
"432", -- Shadowing upvalue argument
20+
"531", -- Left-hand side of assignment is too short
21+
"542", -- Empty if branch
22+
"631", -- Line too long
23+
}

Api/Check.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
-- a_HookName is the name of the hook to call. Everything after that are arguments for the hook.
1010
function CallHook(a_HookName, ...)
1111
assert(g_Hooks[a_HookName] ~= nil)
12-
12+
1313
for idx, callback in ipairs(g_Hooks[a_HookName]) do
1414
local res = cPluginManager:CallPlugin(callback.PluginName, callback.CallbackName, ...)
1515
if (res) then
1616
-- The callback wants to abort the operation
1717
return true
1818
end
1919
end
20-
20+
2121
return false
2222
end
2323

@@ -36,16 +36,14 @@ function GetMultipleBlockChanges(MinX, MaxX, MinZ, MaxZ, Player, World, Operatio
3636
MaxY = Y
3737
end
3838
end
39-
39+
4040
function Object:Flush()
41-
local FinalCuboid = cCuboid(MinX, MinY, MinZ, MaxX, MaxY, MaxZ)
41+
local FinalCuboid = cCuboid(
42+
Vector3i(MinX, MinY, MinZ),
43+
Vector3i(MaxX, MaxY, MaxZ)
44+
)
4245
return CallHook("OnAreaChanging", FinalCuboid, Player, World, Operation)
4346
end
44-
47+
4548
return Object
4649
end
47-
48-
49-
50-
51-

Api/Manage.lua

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ g_Hooks = {
1111
["OnAreaChanging"] = {}, -- Signature: function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation)
1212
["OnAreaChanged"] = {}, -- Signature: function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation)
1313
["OnAreaCopied"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid)
14-
["OnAreaCopying"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid)
14+
["OnAreaCopying"] = {}, -- Signature: function(a_Player, a_World, a_CopiedAreaCuboid)
1515
["OnPlayerSelectionChanging"] = {}, -- Signature: function(a_Player, a_PosX, a_PosY, a_PosZ, a_PointNr)
1616
["OnPlayerSelectionChanged"] = {}, -- Signature: function(a_Player, a_PosX, a_PosY, a_PosZ, a_PointNr)
1717
}
@@ -31,21 +31,21 @@ function AddHook(a_HookName, a_PluginName, a_CallbackName)
3131
(type(a_PluginName) ~= "string") or (a_PluginName == "") or not cPluginManager:Get():IsPluginLoaded(a_PluginName) or
3232
(type(a_CallbackName) ~= "string") or (a_CallbackName == "")
3333
) then
34-
LOGWARNING("[WorldEdit] Invalid callback registration parameters.")
34+
LOGWARNING("Invalid callback registration parameters.")
3535
LOGWARNING(" AddHook() was called with params " ..
3636
tostring(a_HookName or "<nil>") .. ", " ..
3737
tostring(a_PluginName or "<nil>") .. ", " ..
3838
tostring(a_CallbackName or "<nil>")
3939
)
40-
40+
4141
return false
4242
end
43-
43+
4444
if (not g_Hooks[a_HookName]) then
45-
LOGWARNING("[WorldEdit] Plugin \"" .. a_PluginName .. "\" tried to register an unexisting hook called \"" .. a_HookName .. "\"")
45+
LOGWARNING("Plugin \"" .. a_PluginName .. "\" tried to register an unexisting hook called \"" .. a_HookName .. "\"")
4646
return false
4747
end
48-
48+
4949
table.insert(g_Hooks[a_HookName], {PluginName = a_PluginName, CallbackName = a_CallbackName})
5050
return true
5151
end
@@ -60,7 +60,7 @@ end
6060
-- function(a_AffectedAreaCuboid, a_Player, a_World, a_Operation)
6161
-- The callback should return true to abort the operation, false to continue.
6262
function RegisterAreaCallback(a_PluginName, a_FunctionName, a_WorldName)
63-
LOGWARNING("[WorldEdit] RegisterAreaCallback is obsolete. Please use AddHook(\"OnAreaChanging\", ...)")
63+
LOGWARNING("RegisterAreaCallback is obsolete. Please use AddHook(\"OnAreaChanging\", ...)")
6464
LOGWARNING(" The callback signature changed as well. All individual coordinates are now a single cCuboid")
6565
return AddHook("OnAreaChanging", a_PluginName, a_FunctionName)
6666
end
@@ -76,7 +76,7 @@ end
7676
-- a_PointNr can be 0 for Left click or 1 for right click.
7777
-- The callback should return true to abort the operation, or false to continue.
7878
function RegisterPlayerSelectingPoint(a_PluginName, a_FunctionName)
79-
LOGWARNING("[WorldEdit] RegisterPlayerSelectingPoint is obsolete. Please use AddHook(\"OnPlayerSelectionChanging\", ...)")
79+
LOGWARNING("RegisterPlayerSelectingPoint is obsolete. Please use AddHook(\"OnPlayerSelectionChanging\", ...)")
8080
LOGWARNING(" The callback signature changed as well. All individual coordinates are now a single cCuboid")
8181
return AddHook("OnPlayerSelectionChanging", a_PluginName, a_FunctionName)
8282
end
@@ -93,14 +93,14 @@ function SetPlayerCuboidSelection(a_Player, a_Cuboid)
9393
(tolua.type(a_Player) ~= "cPlayer") or
9494
(tolua.type(a_Cuboid) ~= "cCuboid")
9595
) then
96-
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelection API function parameters.")
96+
LOGWARNING("Invalid SetPlayerCuboidSelection API function parameters.")
9797
LOGWARNING(" SetPlayerCuboidSelection() was called with param types \"" ..
9898
tolua.type(a_Player) .. "\" (\"cPlayer\" wanted) and \"" ..
9999
tolua.type(a_Cuboid) .. "\" (\"cCuboid\" wanted)."
100100
)
101101
return false
102102
end
103-
103+
104104
-- Set the selection, both points:
105105
local State = GetPlayerState(a_Player)
106106
State.Selection:SetFirstPoint(a_Cuboid.p1.x, a_Cuboid.p1.y, a_Cuboid.p1.z)
@@ -121,23 +121,23 @@ function SetPlayerCuboidSelectionPoint(a_Player, a_PointNumber, a_CoordVector)
121121
(tonumber(a_PointNumber) == nil) or
122122
(tolua.type(a_CoordVector) ~= "Vector3i")
123123
) then
124-
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelectionPoint API function parameters.")
124+
LOGWARNING("Invalid SetPlayerCuboidSelectionPoint API function parameters.")
125125
LOGWARNING(" SetPlayerCuboidSelection() was called with param types \"" ..
126126
tolua.type(a_Player) .. "\" (\"cPlayer\" wanted), \"" ..
127127
type(a_PointNumber) .. "\" (\"number\" wanted) and \"" ..
128128
tolua.type(a_CoordVector) .. "\" (\"cVector3i\" wanted)."
129129
)
130130
return false
131131
end
132-
132+
133133
-- Set the specified selection point:
134134
local State = GetPlayerState(a_Player)
135135
if (tonumber(a_PointNumber) == 1) then
136136
State.Selection:SetFirstPoint(a_CoordVector)
137137
elseif (tonumber(a_PointNumber) == 2) then
138138
State.Selection:SetSecondPoint(a_CoordVector)
139139
else
140-
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelectionPoint API function parameters.")
140+
LOGWARNING("Invalid SetPlayerCuboidSelectionPoint API function parameters.")
141141
LOGWARNING(" SetPlayerCuboidSelection() was called with invalid point number " .. a_PointNumber)
142142
return false
143143
end
@@ -169,14 +169,14 @@ function GetPlayerCuboidSelection(a_Player, a_CuboidToSet)
169169
(tolua.type(a_Player) ~= "cPlayer") or
170170
(tolua.type(a_CuboidToSet) ~= "cCuboid")
171171
) then
172-
LOGWARNING("[WorldEdit] Invalid SetPlayerCuboidSelection API function parameters.")
172+
LOGWARNING("Invalid SetPlayerCuboidSelection API function parameters.")
173173
LOGWARNING(" SetPlayerCuboidSelection() was called with param types \"" ..
174174
tolua.type(a_Player) .. "\" (\"cPlayer\" wanted) and \"" ..
175175
tolua.type(a_CuboidToSet) .. "\" (\"cCuboid\" wanted)."
176176
)
177177
return false
178178
end
179-
179+
180180
-- Set the output cuboid to the selection:
181181
local State = GetPlayerState(a_Player)
182182
a_CuboidToSet:Assign(State.Selection.Cuboid)
@@ -201,15 +201,15 @@ function WEPushUndo(a_Player, a_World, a_Cuboid, a_Description)
201201
(tolua.type(a_Cuboid) ~= "cCuboid") or
202202
(type(a_Description) ~= "string")
203203
) then
204-
LOGWARNING("[WorldEdit] Invalid WEPushUndo API function parameters.")
204+
LOGWARNING("Invalid WEPushUndo API function parameters.")
205205
LOGWARNING(" WePushUndo() was called with these param types:")
206206
LOGWARNING(" " .. tolua.type(a_Player) .. " (cPlayer wanted),")
207207
LOGWARNING(" " .. tolua.type(a_World) .. " (cWorld wanted),")
208208
LOGWARNING(" " .. tolua.type(a_Cuboid) .. " (cCuboid wanted),")
209209
LOGWARNING(" " .. type(a_Description) .. " (string wanted),")
210210
return false, "bad params"
211211
end
212-
212+
213213
-- Push the undo:
214214
local State = GetPlayerState(a_Player)
215215
return State.UndoStack:PushUndoFromCuboid(a_World, a_Cuboid, a_Description)
@@ -238,7 +238,7 @@ function WEPushUndoAsync(a_Player, a_World, a_Cuboid, a_Description, a_CallbackP
238238
(type(a_CallbackPluginName) ~= "string") or
239239
(type(a_CallbackFunctionName) ~= "string")
240240
) then
241-
LOGWARNING("[WorldEdit] Invalid WEPushUndoAsync() API function parameters.")
241+
LOGWARNING("Invalid WEPushUndoAsync() API function parameters.")
242242
LOGWARNING(" WePushUndo() was called with these param types:")
243243
LOGWARNING(" " .. tolua.type(a_Player) .. " (cPlayer wanted),")
244244
LOGWARNING(" " .. tolua.type(a_World) .. " (cWorld wanted),")
@@ -248,23 +248,23 @@ function WEPushUndoAsync(a_Player, a_World, a_Cuboid, a_Description, a_CallbackP
248248
LOGWARNING(" " .. type(a_CallbackFunctionName) .. " (string wanted),")
249249
return false, "bad params"
250250
end
251-
251+
252252
-- if the input cuboid isn't sorted, create a sorted copy:
253253
if not(a_Cuboid:IsSorted()) then
254254
a_Cuboid = cCuboid(a_Cuboid)
255255
a_Cuboid:Sort()
256256
end
257-
257+
258258
-- Create a callback for the ChunkStay:
259259
local State = GetPlayerState(a_Player) -- a_Player may be deleted in the meantime, but the State table won't
260260
local OnAllChunksAvailable = function()
261261
local IsSuccess, Msg = State.UndoStack:PushUndoFromCuboid(a_World, a_Cuboid, a_Description)
262262
cPluginManager:CallPlugin(a_CallbackPluginName, a_CallbackFunctionName, IsSuccess, Msg)
263263
end
264-
264+
265265
-- Get a list of chunks that need to be present:
266266
local Chunks = ListChunksForCuboid(a_Cuboid)
267-
267+
268268
-- Initiate a ChunkStay operation, pushing the undo when all the chunks are available
269269
a_World:ChunkStay(Chunks, nil, OnAllChunksAvailable)
270270
return true
@@ -283,10 +283,6 @@ function ExecuteString(a_String, ...)
283283
if (not Function) then
284284
return false, Error
285285
end
286-
286+
287287
return pcall(Function, ...)
288288
end
289-
290-
291-
292-

0 commit comments

Comments
 (0)