Skip to content

Commit

Permalink
Optimizations & Death fix
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wildrun0 committed Aug 6, 2022
1 parent 907bb96 commit aa28eb0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
10 changes: 5 additions & 5 deletions Info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
4 changes: 2 additions & 2 deletions homesetter.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Initialize(Plugin)
Plugin:SetName("HomeSetter")
Plugin:SetVersion(2)
Plugin:SetVersion(3)

dofile(cPluginManager:GetPluginsPath() .. "/InfoReg.lua")
RegisterPluginInfoCommands()
Expand Down Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions main_funcs.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
local croot = cRoot:Get()
local strfind = string.find


local function checkPerms(Player)
local PlayerHomes = #getUserHomes(Player:GetName())
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions storage_manager.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa28eb0

Please sign in to comment.