forked from sharkbound/WebsiteCommand
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWebsiteCommandProvider.cs
54 lines (45 loc) · 1.43 KB
/
WebsiteCommandProvider.cs
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
using System.Collections.Generic;
using System.Linq;
using Rocket.API;
using Rocket.API.Commands;
using Rocket.API.Plugins;
namespace WebsiteCommand
{
public class WebsiteCommandProvider : ICommandProvider
{
private readonly IPluginManager _pluginManager;
public WebsiteCommandProvider(IPluginManager pluginManager)
{
_pluginManager = pluginManager;
}
public string ServiceName => "WebsiteCommands";
public ILifecycleObject GetOwner(ICommand command)
{
return _pluginManager.GetPlugin("WebsiteCommands");
}
public void Init()
{
}
public void Rebuild()
{
_commands.Clear();
}
private readonly List<ICommand> _commands = new List<ICommand>();
public IEnumerable<ICommand> Commands
{
get
{
var owner = (WebsiteCommandsPlugin) GetOwner(null);
if(!owner.IsAlive)
return new List<ICommand>();
foreach (var cmd in owner.ConfigurationInstance.WebsiteCommands)
{
if(_commands.Any(c => c.Name.Equals(cmd.CommandName)))
continue;
_commands.Add(new RocketWebsiteCommand(cmd.CommandName, cmd.Description, cmd.Url, cmd.Permission));
}
return _commands;
}
}
}
}