Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /op and /deop commands #192

Merged
merged 5 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -754,6 +768,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 @@ -7,6 +7,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 @@ -22,6 +23,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 @@ -82,7 +84,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