-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathCommandKits.cs
More file actions
87 lines (74 loc) · 2.3 KB
/
CommandKits.cs
File metadata and controls
87 lines (74 loc) · 2.3 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
using Rocket.API;
using Rocket.API.Serialisation;
using Rocket.Core.Logging;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System;
using System.Collections.Generic;
using System.Linq;
namespace fr34kyn01535.Kits
{
public class CommandKits : IRocketCommand
{
public string Help
{
get { return "Shows you available kits"; }
}
public string Name
{
get { return "kits"; }
}
public string Syntax
{
get { return ""; }
}
public bool RunFromConsole
{
get { return false; }
}
public List<string> Aliases
{
get { return new List<string>(); }
}
public AllowedCaller AllowedCaller
{
get { return Rocket.API.AllowedCaller.Player; }
}
public List<string> Permissions
{
get
{
return new List<string>() { "kits.kits" };
}
}
public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer player = (UnturnedPlayer)caller;
List<string> availableKits = new List<string>();
List<Kit> kits = Kits.Instance.Configuration.Instance.Kits;
// Gets all caller's permissions
List<Permission> callerPerms = caller.GetPermissions().Distinct(new PermissionComparer()).ToList();
foreach (var item in kits)
{
// Adds the kit if it's permission is contained in the caller's permission list
if (callerPerms.Exists(x => x.Name == $"kit.{item.Name.ToLower()}"))
availableKits.Add(item.Name);
}
UnturnedChat.Say(caller, Kits.Instance.Translations.Instance.Translate("command_kits", String.Join(", ",availableKits.ToArray())));
}
}
/// <summary>
/// Provides the comparison method for Rocket's Permission
/// </summary>
internal class PermissionComparer : IEqualityComparer<Permission>
{
public bool Equals(Permission x, Permission y)
{
return x.Name == y.Name && x.Cooldown == y.Cooldown;
}
public int GetHashCode(Permission obj)
{
return obj.GetHashCode();
}
}
}