diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69db480..ca6cc10 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,14 +11,25 @@ jobs: - name: Install Lua run: | - sudo apt install lua5.1 luarocks + sudo apt install lua5.1 luarocks libsqlite3-dev sudo luarocks install luafilesystem + sudo luarocks install lsqlite3 + sudo luarocks install luasocket sudo luarocks install luacheck + sudo luarocks install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu - 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' + wget -O ../InfoReg.lua https://raw.githubusercontent.com/cuberite/cuberite/master/Server/Plugins/InfoReg.lua + mkdir ~/AutoAPI + wget -O ~/AutoAPI.zip --no-check-certificate 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/AutoAPI.zip?job=Windows-x64&pr=false&branch=master' + unzip ~/AutoAPI.zip -d ~/AutoAPI + wget -O ~/ManualAPI.zip --no-check-certificate 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/ManualAPI.zip?job=Windows-x64&pr=false&branch=master' + unzip ~/ManualAPI.zip -d ~ + git clone https://github.com/cuberite/CuberitePluginChecker ~/Checker + wget -O .luacheckrc --no-check-certificate 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/.luacheckrc?job=Windows-x64&pr=false&branch=master' - name: Run tests run: | - luacheck . --codes + cd ~/Checker && lua CuberitePluginChecker.lua -p $GITHUB_WORKSPACE -a ~/AutoAPI -e ~/ManualAPI.lua -i APIImpl/All.lua -s $GITHUB_WORKSPACE/Tests/selection.lua -g + cd $GITHUB_WORKSPACE && luacheck . --codes --exclude-files Tests/* diff --git a/Classes/PlayerState.lua b/Classes/PlayerState.lua index 961f460..a49e254 100644 --- a/Classes/PlayerState.lua +++ b/Classes/PlayerState.lua @@ -212,3 +212,7 @@ end -- Register the hooks needed: cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_DESTROYED, OnPlayerDestroyed) cPluginManager:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage) + + + + diff --git a/Classes/ToolRegistrator.lua b/Classes/ToolRegistrator.lua index 8c4d050..290f8bb 100644 --- a/Classes/ToolRegistrator.lua +++ b/Classes/ToolRegistrator.lua @@ -326,6 +326,8 @@ end -- Register the hooks needed: -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook); -cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook); +cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook); +cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook); +cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook); + + diff --git a/Commands/Special.lua b/Commands/Special.lua index 2f5955a..dbfa9fc 100644 --- a/Commands/Special.lua +++ b/Commands/Special.lua @@ -25,7 +25,7 @@ end function HandleWorldEditVersionCommand(a_Split, a_Player) -- /we version - a_Player:SendMessage(cChatColor.LightPurple .. "This is version " .. PLUGIN:GetVersion()) + a_Player:SendMessage(cChatColor.LightPurple .. "This is version " .. cPluginManager:GetCurrentPlugin():GetVersion()) return true end diff --git a/Config.lua b/Config.lua index 8e75876..c0df2b9 100644 --- a/Config.lua +++ b/Config.lua @@ -16,7 +16,7 @@ g_Config = {} -- Create an environment for the config loader where the admin can use item names directly without quotes. local g_LoaderEnv = {} for Key, Value in pairs(_G) do - if (Key:match("E_.*")) then + if (Key:match("^E_.*")) then g_LoaderEnv[ItemTypeToString(Value)] = Value end end diff --git a/Tests/selection.lua b/Tests/selection.lua new file mode 100644 index 0000000..b3e12fd --- /dev/null +++ b/Tests/selection.lua @@ -0,0 +1,46 @@ +-- selection.lua + +-- These files are used with the CuberitePluginChecker script. +-- This test tests the selection and actions on the selection. +-- Usage: lua CuberitePluginChecker.lua -a AutoAPI -e ManualAPI.lua -i APIImpl/All.lua -p -s /selection.lua -f ^E_ + + + + + +scenario +{ + redirectPluginFiles + { + -- Redirect the default config file. + -- This disables the update check and also works around a bug in the simulator which causes block/item enums to not be in the global environment. + ["config.cfg"] = "test.config.cfg" + }, + world + { + name = "world" + }, + initializePlugin(), + connectPlayer + { + name = "TestUser" + }, + playerCommand + { + playerName = "TestUser", + command = "//pos1", + }, + playerCommand + { + playerName = "TestUser", + command = "//pos2", + }, + playerCommand + { + playerName = "TestUser", + command = "//set 0", + }, +} + + + diff --git a/Tests/test.config.cfg b/Tests/test.config.cfg new file mode 100644 index 0000000..6f5f190 --- /dev/null +++ b/Tests/test.config.cfg @@ -0,0 +1,52 @@ +WandItem = 271, +Limits = +{ + ButcherRadius = -1, + MaxBrushRadius = 5, + DisallowedBlocks = {6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83}, +}, + +Defaults = +{ + ButcherRadius = 20, +}, + +NavigationWand = +{ + Item = 345, + MaxDistance = 120, + TeleportNoHit = true, +}, + +Scripting = +{ + -- If true it logs an error when a craftscript failed + Debug = false, + + -- The amount of seconds that a script may be active. Any longer and the script will be aborted. + -- If negative the time a script can run is unlimited. + MaxExecutionTime = 5, +}, + +Schematics = +{ + OverrideExistingFiles = true, +}, + +Updates = +{ + CheckForUpdates = false, + NumAttempts = 3, + ShowMessageWhenUpToDate = true, + DownloadNewerVersion = true, +}, + +Storage = +{ + -- If set to true the selection of a player will be remembered once he leaves. + RememberPlayerSelection = true, + + -- If WorldEdit needs to change a format in the database the database will be backuped first before changing. + -- This doesn't mean when adding or removing data the database will be backed up. Only when the used database is outdated. + BackupDatabaseWhenUpdating = true, +} diff --git a/main.lua b/main.lua index 6bd0625..45031f1 100644 --- a/main.lua +++ b/main.lua @@ -8,7 +8,7 @@ -- First of all load all the library expansions -dofolder(cPluginManager:GetCurrentPlugin():GetLocalFolder() .. "/LibrariesExpansion") +dofolder(cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/LibrariesExpansion") @@ -18,6 +18,7 @@ dofolder(cPluginManager:GetCurrentPlugin():GetLocalFolder() .. "/LibrariesExpans g_ExcludedFolders = table.todictionary{ "craftscripts", "LibrariesExpansion", + "Tests", ".", "..", } @@ -27,7 +28,7 @@ g_ExcludedFolders = table.todictionary{ -- Load all the folders -local WorldEditPath = cPluginManager:GetCurrentPlugin():GetLocalFolder() +local WorldEditPath = cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() for _, Folder in ipairs(cFile:GetFolderContents(WorldEditPath)) do repeat local Path = WorldEditPath .. "/" .. Folder if (not cFile:IsFolder(Path)) then @@ -41,13 +42,13 @@ for _, Folder in ipairs(cFile:GetFolderContents(WorldEditPath)) do repeat dofolder(Path) until true end -PLUGIN = nil + + function Initialize(a_Plugin) - PLUGIN = a_Plugin - PLUGIN:SetName(g_PluginInfo.Name) - PLUGIN:SetVersion(g_PluginInfo.Version) + a_Plugin:SetName(g_PluginInfo.Name) + a_Plugin:SetVersion(g_PluginInfo.Version) InitializeConfiguration(a_Plugin:GetLocalFolder() .. "/config.cfg")