Skip to content

Commit

Permalink
Add /op and /deop commands (#192)
Browse files Browse the repository at this point in the history
* Add /op and /deop commands

* Assign GetDefaultRank() on /deop instead of hardcoding 'Default'

* /op finds and matches rank with '*' perm instead of hardcoding 'Admin'

* Refactor into GetAdminRank() helper function

* Fix documentation to refer to administrator and default rank
  • Loading branch information
satoshinm authored and NiLSPACE committed Jul 11, 2017
1 parent f9939d6 commit 8f21401
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
28 changes: 28 additions & 0 deletions Info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ g_PluginInfo =
HelpString = "Shows or sets a player's rank.",
},

["/op"] =
{
Permission = "core.rank",
Handler = HandleOpCommand,
HelpString = "Add a player to the administrator rank.",
},

["/deop"] =
{
Permission = "core.rank",
Handler = HandleDeOpCommand,
HelpString = "Add a player to the default rank.",
},

["/regen"] =
{
Permission = "core.regen",
Expand Down Expand Up @@ -761,6 +775,20 @@ g_PluginInfo =
Handler = HandleConsoleRank,
HelpString = "Shows or sets a player's rank.",
},

["op"] =
{
Permission = "core.rank",
Handler = HandleConsoleOp,
HelpString = "Add a player to the Admin rank.",
},

["deop"] =
{
Permission = "core.rank",
Handler = HandleConsoleDeOp,
HelpString = "Add a player to the Default rank.",
},

["regen"] =
{
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Implements some of the basic commands needed to run a simple server.
| ------- | ---------- | ----------- |
|/ban | core.ban | Bans a player.|
|/clear | core.clear | Clears the inventory of a player.|
|/deop | core.rank | Add a player to the default rank.|
|/difficulty | core.difficulty | Changes the difficulty level of the world you're located in.|
|/do | core.do | Runs a command as a player.|
|/effect | core.effect | Adds an effect to a player.|
Expand All @@ -23,6 +24,7 @@ Implements some of the basic commands needed to run a simple server.
|/listranks | core.listranks | Shows a list of the available ranks.|
|/me | core.me | Broadcasts what you are doing.|
|/motd | core.motd | Shows the message of the day.|
|/op | core.rank | Add a player to the administrator rank. |
|/plugins | core.plugins | Shows a list of the plugins.|
|/portal | core.portal | Moves your player to a different world.|
|/r | core.tell | Replies to the latest private message you recieved.|
Expand Down Expand Up @@ -85,7 +87,7 @@ Implements some of the basic commands needed to run a simple server.
| core.motd | | `/motd` | |
| core.plugins | | `/plugins` | |
| core.portal | | `/portal` | |
| core.rank | | `/rank` | |
| core.rank | | `/rank`, `/op`, `/deop` | |
| core.regen | | `/regen` | |
| core.reload | | `/reload` | |
| core.save-all | | `/save-all` | |
Expand Down
39 changes: 39 additions & 0 deletions console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,45 @@ end



function HandleConsoleOp(a_Split)
-- Check the params:
if ((a_Split[2] == nil) or (a_Split[3] ~= nil)) then
-- Not enough or too many parameters
return true, "Usage: " .. a_Split[1] .. " <player>"
end

local PlayerName = a_Split[2]
local AdminRank = GetAdminRank()

if not AdminRank then
SendMessage(a_Player, "No admin rank found, missing * permission")
return true
end

return HandleConsoleRank({"rank", PlayerName, AdminRank})
end





function HandleConsoleDeOp(a_Split)
-- Check the params:
if ((a_Split[2] == nil) or (a_Split[3] ~= nil)) then
-- Not enough or too many parameters
return true, "Usage: " .. a_Split[1] .. " <player>"
end

local PlayerName = a_Split[2]
local DefaultRank = cRankManager:GetDefaultRank()

return HandleConsoleRank({"rank", PlayerName, DefaultRank})
end





function HandleConsoleSaveAll(Split)
cRoot:Get():SaveAllChunks()
return true
Expand Down
14 changes: 14 additions & 0 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,17 @@ function GetWorld( WorldName, Player )
return World
end
end


function GetAdminRank()
local AdminRank
local Ranks = cRankManager:GetAllRanks()
for _, Rank in ipairs(Ranks) do
local Permissions = cRankManager:GetRankPermissions(Rank)
for _, Permission in ipairs(Permissions) do
if Permission == "*" then
return Rank
end
end
end
end
37 changes: 37 additions & 0 deletions ranks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,40 @@ end



function HandleOpCommand(a_Split, a_Player)
-- Check the params:
if ((a_Split[2] == nil) or (a_Split[3] ~= nil)) then
-- Too many or too few parameters, print the usage:
SendMessage(a_Player, "Usage: " .. a_Split[1] .. " <player>")
return true
end

local PlayerName = a_Split[2]
local AdminRank = GetAdminRank()

if not AdminRank then
SendMessage(a_Player, "No admin rank found, missing * permission")
return true
end

return HandleRankCommand({"rank", PlayerName, AdminRank}, a_Player)
end





function HandleDeOpCommand(a_Split, a_Player)
-- Check the params:
if ((a_Split[2] == nil) or (a_Split[3] ~= nil)) then
-- Too many or too few parameters, print the usage:
SendMessage(a_Player, "Usage: " .. a_Split[1] .. " <player>")
return true
end

local PlayerName = a_Split[2]
local DefaultRank = cRankManager:GetDefaultRank()

return HandleRankCommand({"rank", PlayerName, DefaultRank}, a_Player)
end

0 comments on commit 8f21401

Please sign in to comment.