-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugins.lua
196 lines (184 loc) · 5.92 KB
/
plugins.lua
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
-- plugins.lua
-- Implements the /plugins command.
function HandleConsolePlugins(a_Split, a_Player)
-- Parse the parameters for plugin statuses to display.
local IncludePluginStatus = {}
-- Map of status, or the "true" for plugins to show.
local idx = 2
while (a_Split[idx]) do
local param = a_Split[idx]
idx = idx + 1
if (param == "all") then
IncludePluginStatus[cPluginManager.psLoaded] = true
IncludePluginStatus[cPluginManager.psUnloaded] = true
IncludePluginStatus[cPluginManager.psError] = true
IncludePluginStatus[cPluginManager.psNotFound] = true
IncludePluginStatus[cPluginManager.psDisabled] = true
elseif (param == "loaded") then
IncludePluginStatus[cPluginManager.psLoaded] = true
elseif (param == "unloaded") then
IncludePluginStatus[cPluginManager.psUnloaded] = true
elseif ((param == "errored") or (param == "error") or (param == "errorred")) then
IncludePluginStatus[cPluginManager.psError] = true
elseif (param == "notfound") then
IncludePluginStatus[cPluginManager.psNotFound] = true
elseif (param == "disabled") then
IncludePluginStatus[cPluginManager.psDisabled] = true
end
end
if not(a_Split[2]) then
-- Show only psLoaded plugins...
IncludePluginStatus[cPluginManager.psLoaded] = true
end
-- Enumerate the plugins.
local PluginTable = {}
cPluginManager:Get():ForEachPlugin(
function (a_CBPlugin)
table.insert(PluginTable,
{
Name = a_CBPlugin:GetName(),
Folder = a_CBPlugin:GetFolderName(),
Status = a_CBPlugin:GetStatus(),
LoadError = a_CBPlugin:GetLoadError()
}
)
end
)
table.sort(PluginTable,
function (a_Plugin1, a_Plugin2)
return (string.lower(a_Plugin1.Folder) < string.lower(a_Plugin2.Folder))
end
)
-- Prepare a translation table for the status.
local StatusName =
{
[cPluginManager.psLoaded] = "Loaded ",
[cPluginManager.psUnloaded] = "Unloaded",
[cPluginManager.psError] = "Error ",
[cPluginManager.psNotFound] = "NotFound",
[cPluginManager.psDisabled] = "Disabled",
}
-- Generate the name and ratio.
local Out = {}
local HasAnyListed = false
table.insert(Out, "Plugins (")
table.insert(Out, cPluginManager:Get():GetNumLoadedPlugins())
table.insert(Out, "/")
table.insert(Out, #PluginTable)
table.insert(Out, "):")
-- Generate the list of plugins.
local OutPlugins = {}
local HasAnyListed = false
for _, plg in ipairs(PluginTable) do
if (IncludePluginStatus[plg.Status]) then
table.insert(OutPlugins, plg.Folder)
if (plg.Name ~= plg.Folder) then
table.insert(OutPlugins, " (API name ")
table.insert(OutPlugins, plg.Name)
table.insert(OutPlugins, ")")
end
-- if (plg.Status == cPluginManager.psError) then
-- table.insert(Out, " ERROR: ")
-- table.insert(Out, plg.LoadError or "<unknown>")
-- end
HasAnyListed = true
end
end
if not(HasAnyListed) then
table.insert(OutPlugins, "n/a")
end
-- Send output to player.
LOG(table.concat(Out) .. " " .. table.concat(OutPlugins, ", "))
return true
end
function HandlePluginsCommand(a_Split, a_Player)
-- Parse the parameters for plugin statuses to display.
local IncludePluginStatus = {}
-- Map of status, or the "true" for plugins to show.
local idx = 2
while (a_Split[idx]) do
local param = a_Split[idx]
idx = idx + 1
if (param == "all") then
IncludePluginStatus[cPluginManager.psLoaded] = true
IncludePluginStatus[cPluginManager.psUnloaded] = true
IncludePluginStatus[cPluginManager.psError] = true
IncludePluginStatus[cPluginManager.psNotFound] = true
IncludePluginStatus[cPluginManager.psDisabled] = true
elseif (param == "loaded") then
IncludePluginStatus[cPluginManager.psLoaded] = true
elseif (param == "unloaded") then
IncludePluginStatus[cPluginManager.psUnloaded] = true
elseif ((param == "errored") or (param == "error") or (param == "errorred")) then
IncludePluginStatus[cPluginManager.psError] = true
elseif (param == "notfound") then
IncludePluginStatus[cPluginManager.psNotFound] = true
elseif (param == "disabled") then
IncludePluginStatus[cPluginManager.psDisabled] = true
end
end
if not(a_Split[2]) then
-- Show only psLoaded plugins...
IncludePluginStatus[cPluginManager.psLoaded] = true
end
-- Enumerate the plugins.
local PluginTable = {}
cPluginManager:Get():ForEachPlugin(
function (a_CBPlugin)
table.insert(PluginTable,
{
Name = a_CBPlugin:GetName(),
Folder = a_CBPlugin:GetFolderName(),
Status = a_CBPlugin:GetStatus(),
LoadError = a_CBPlugin:GetLoadError()
}
)
end
)
table.sort(PluginTable,
function (a_Plugin1, a_Plugin2)
return (string.lower(a_Plugin1.Folder) < string.lower(a_Plugin2.Folder))
end
)
-- Prepare a translation table for the status.
local StatusName =
{
[cPluginManager.psLoaded] = "Loaded ",
[cPluginManager.psUnloaded] = "Unloaded",
[cPluginManager.psError] = "Error ",
[cPluginManager.psNotFound] = "NotFound",
[cPluginManager.psDisabled] = "Disabled",
}
-- Generate the name and ratio.
local Out = {}
local HasAnyListed = false
table.insert(Out, "Plugins (")
table.insert(Out, cPluginManager:Get():GetNumLoadedPlugins())
table.insert(Out, "/")
table.insert(Out, #PluginTable)
table.insert(Out, "):")
-- Generate the list of plugins.
local OutPlugins = {}
local HasAnyListed = false
for _, plg in ipairs(PluginTable) do
if (IncludePluginStatus[plg.Status]) then
table.insert(OutPlugins, plg.Folder)
if (plg.Name ~= plg.Folder) then
table.insert(OutPlugins, " (API name ")
table.insert(OutPlugins, plg.Name)
table.insert(OutPlugins, ")")
end
-- if (plg.Status == cPluginManager.psError) then
-- table.insert(Out, " ERROR: ")
-- table.insert(Out, plg.LoadError or "<unknown>")
-- end
HasAnyListed = true
end
end
if not(HasAnyListed) then
table.insert(OutPlugins, "n/a")
end
-- Send output to player.
SendMessage(a_Player, cChatColor.LightGray .. table.concat(Out) .. " " .. table.concat(OutPlugins, ", "))
return true
end