-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandSystem.cs
More file actions
46 lines (46 loc) · 1.28 KB
/
CommandSystem.cs
File metadata and controls
46 lines (46 loc) · 1.28 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
using System;
public class CommandSystem
{
public readonly Dictionary<string, ICommand> commands;
public CommandSystem(Server server){
commands = new Dictionary<string, ICommand>(){
{"!ban",new Ban(server)},
{"!unban",new Unban(server)},
{"!kick",new Kick(server)},
{"!mute",new Mute(server)},
{"!unmute",new Unmute(server)},
{"!info",new Info(server)},
{"!setrole", new SetRole(server)},
{"!vote", new Vote(server, this)},
{"!help", new Help(server, this)},
{"!coinflip", new Coinflip()},
{"!setrangedmode", new SetRangedMode()},
{"!performance", new Performance()},
};
}
public ICommand GetCommand(string commandCode){
if(commands.ContainsKey(commandCode.ToLower())){
return commands[commandCode.ToLower()];
}
GameWindow.Log($"Command '{commandCode}' cannot be found");
return null;
}
public void ExecuteCommand(Player executer, List<string> args){
SterilizeArgs(args);
ICommand command = GetCommand(args[0]);
if(command != null){
List<string> commandArgs = new List<string>(args);
commandArgs.RemoveRange(0,1);
command.Execute(executer,commandArgs);
}
}
public void SterilizeArgs(List<string> args){
//remove blank args
for(int i = 0; i < args.Count; i++){
if(args[i].Length == 0){
args.RemoveAt(i);
i--;
}
}
}
}