From aa28eb000d3a7be945fb30971d6d96552d565f3d Mon Sep 17 00:00:00 2001 From: wildrun0 Date: Sat, 6 Aug 2022 12:50:17 +0500 Subject: [PATCH] Optimizations & Death fix Fixed death "because of fall" when teleporting. its cuberite bug related Added some tweaks to speed up code executing (such as caching functions & stuff) Preparing to changing color system --- Info.lua | 10 +++++----- README.md | 10 +++++----- homesetter.lua | 4 ++-- main_funcs.lua | 17 ++++++++++------- storage_manager.lua | 8 +++++--- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Info.lua b/Info.lua index 999512d..3b2fedb 100644 --- a/Info.lua +++ b/Info.lua @@ -72,27 +72,27 @@ g_PluginInfo = ["homesetter.home"] = { Description = "Allows the players to teleport to their homes.", - RecommendedGroups = "players", + RecommendedGroups = "Default", }, ["homesetter.sethome"] = { Description = "Allows the players to set their homes.", - RecommendedGroups = "players", + RecommendedGroups = "Default", }, ["homesetter.delhome"] = { Description = "Allows the players to delete their homes.", - RecommendedGroups = "players", + RecommendedGroups = "Default", }, ["homesetter.homes"] = { Description = "Allows the players to view a list of their homes.", - RecommendedGroups = "players", + RecommendedGroups = "Default", }, ["homesetter.maxhomes.3"] = { Description = "Maximum number of homes to be set", - RecommendedGroups = "players", + RecommendedGroups = "Default", }, }, Categories = {}, diff --git a/README.md b/README.md index 6498750..97ed65b 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Use /homes to see existing homes and their amount # Permissions | Permissions | Description | Commands | Recommended groups | | ----------- | ----------- | -------- | ------------------ | -| homesetter.delhome | Allows the players to delete their homes. | `/delhome` | players | -| homesetter.home | Allows the players to teleport to their homes. | `/home` | players | -| homesetter.homes | Allows the players to view a list of their homes. | `/homes` | players | -| homesetter.maxhomes.3 | Maximum number of homes to be set | | players | -| homesetter.sethome | Allows the players to set their homes. | `/sethome` | players | +| homesetter.delhome | Allows the players to delete their homes. | `/delhome` | Default | +| homesetter.home | Allows the players to teleport to their homes. | `/home` | Default | +| homesetter.homes | Allows the players to view a list of their homes. | `/homes` | Default | +| homesetter.maxhomes.3 | Maximum number of homes to be set | | Default | +| homesetter.sethome | Allows the players to set their homes. | `/sethome` | Default | diff --git a/homesetter.lua b/homesetter.lua index e16241c..9dccd7f 100644 --- a/homesetter.lua +++ b/homesetter.lua @@ -1,6 +1,6 @@ function Initialize(Plugin) Plugin:SetName("HomeSetter") - Plugin:SetVersion(2) + Plugin:SetVersion(3) dofile(cPluginManager:GetPluginsPath() .. "/InfoReg.lua") RegisterPluginInfoCommands() @@ -38,7 +38,7 @@ function SetHome(command, Player) local sethome_state = SetPlayerHome( Player, homename, cJson:Serialize(PlayerPos) ) - + if sethome_state == nil then Player:SendMessageFailure("@cMaximum homes have been set!") elseif sethome_state then diff --git a/main_funcs.lua b/main_funcs.lua index cc6256d..278e159 100644 --- a/main_funcs.lua +++ b/main_funcs.lua @@ -1,4 +1,5 @@ local croot = cRoot:Get() +local strfind = string.find local function checkPerms(Player) @@ -6,10 +7,11 @@ local function checkPerms(Player) local PlayerPermissions = Player:GetPermissions() for i = 1, #PlayerPermissions do - if PlayerPermissions[i] == "*" then + local PlayerPerm = PlayerPermissions[i] + if PlayerPerm == "*" then return true - elseif string.find(PlayerPermissions[i], "homesetter.maxhomes.") then - local amount = string.sub(PlayerPermissions[i], -1) + elseif strfind(PlayerPerm, "homesetter.maxhomes.") then + local amount = string.sub(PlayerPerm, -1) if amount == "*" then return true else @@ -48,10 +50,11 @@ function TpPlayerHome(Player, HomeName) if doesExist(PlayerName, HomeName) then local world, x, y, z = getHomePos(PlayerName, HomeName) if world ~= Player:GetWorld():GetName() then - local cworld = croot:GetWorld(world) - local VectorCoords = Vector3d(x, y, z) - Player:MoveToWorld(cworld, true, VectorCoords) + Player:MoveToWorld( + croot:GetWorld(world), true, Vector3d(x, y, z) + ) else + Player:SetInvulnerableTicks(2) -- to prevent getting damage because of "fall" (cuberite bug) Player:TeleportToCoords(x, y, z) end return true @@ -64,7 +67,7 @@ function SetPermissions() local default_rank_name = "Default" local default_group = cRankManager:GetGroupPermissions(default_rank_name) for i = 1, #default_group do - if string.find(default_group[i], "homesetter.") then + if strfind(default_group[i], "homesetter.") then return end end diff --git a/storage_manager.lua b/storage_manager.lua index f99afc6..18e06c9 100644 --- a/storage_manager.lua +++ b/storage_manager.lua @@ -1,5 +1,5 @@ -DB = sqlite3.open(cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/data.sqlite") local DB_TABLE_EXIST = false +DB = sqlite3.open(cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/data.sqlite") function doesExist(name, homename) @@ -17,7 +17,7 @@ function doesExist(name, homename) ]] stmt:bind_values(homename, name) for count in stmt:urows() do - return (count > 0) + return (count > 0) -- i wish there was a more nicer way to do this end end end @@ -69,8 +69,10 @@ function getUserHomes(PlayerName) local homes = {} if stmt ~= nil then stmt:bind_values(PlayerName) + local i = 1 for homename in stmt:urows() do - homes[#homes + 1] = homename + homes[i] = homename + i = i + 1 end end return homes