forked from cuberite/Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathranks.lua
More file actions
114 lines (83 loc) · 3.02 KB
/
Copy pathranks.lua
File metadata and controls
114 lines (83 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-- ranks.lua
-- Handles the rank-related commands
function HandleListRanksCommand(a_Split, a_Player)
local Ranks = cRankManager:GetAllRanks()
SendMessageSuccess(a_Player, "Ranks available: " .. table.concat(Ranks, ", ") .. " (total: " .. #Ranks .. ")")
return true
end
function HandleRankCommand(a_Split, a_Player)
-- Check the params:
if ((a_Split[2] == nil) or (a_Split[4] ~= nil)) then
-- Too many or too few parameters, print the usage:
SendMessage(a_Player, "Usage: " .. a_Split[1] .. " <player> [rank]")
return true
end
-- Translate the PlayerName to a UUID:
local PlayerName = a_Split[2]
local PlayerUUID
if (cRoot:Get():GetServer():ShouldAuthenticate()) then
-- The server is in online-mode, get the UUID from Mojang servers and check for validity:
PlayerUUID = cMojangAPI:GetUUIDFromPlayerName(PlayerName)
if ((PlayerUUID == nil) or (string.len(PlayerUUID) ~= 32)) then
SendMessage(a_Player, "There is no such player: " .. PlayerName)
return true
end
else
-- The server is in offline mode, generate an offline-mode UUID, no validity check is possible:
PlayerUUID = cClientHandle:GenerateOfflineUUID(PlayerName)
end
-- View the player's rank, if requested:
if (a_Split[3] == nil) then
-- "/rank <PlayerName>" usage, display the rank:
local CurrRank = cRankManager:GetPlayerRankName(PlayerUUID)
if (CurrRank == "") then
SendMessageSuccess(a_Player, "The player has no rank assigned to them.")
else
SendMessageSuccess(a_Player, "The player's rank is " .. CurrRank)
end
return true
end
-- Change the player's rank:
local NewRank = a_Split[3]
if not(cRankManager:RankExists(NewRank)) then
SendMessage(a_Player, "The specified rank does not exist!")
return true
end
cRankManager:SetPlayerRank(PlayerUUID, PlayerName, NewRank)
-- Update all players in the game of the given name and let them know:
cRoot:Get():ForEachPlayer(
function(a_CBPlayer)
if (a_CBPlayer:GetName() == PlayerName) then
a_CBPlayer:SendMessageInfo("You were assigned the rank " .. NewRank .. " by " .. a_Player:GetName() .. ".")
a_CBPlayer:LoadRank()
end
end
)
return true
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