-
Notifications
You must be signed in to change notification settings - Fork 1
/
MaxskillsButWithoutOverkill.cs
72 lines (60 loc) · 2.28 KB
/
MaxskillsButWithoutOverkill.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Rocket.API;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using Rocket.Core.Logging;
using Rocket.Unturned.Player;
using System.Reflection;
using Rocket.Unturned.Skills;
using UnityEngine;
using Rocket.Unturned.Events;
using Rocket.Unturned;
using Logger = Rocket.Core.Logging.Logger;
namespace MaxskillsButWithoutOverkill
{
public class MaxskillsButWithoutOverkill : RocketPlugin<MaxskillsButWithoutOverkillConfiguration>
{
public static MaxskillsButWithoutOverkill instance;
private FieldInfo[] skills;
private ConstructorInfo skillCtor;
protected override void Load()
{
instance = this;
Logger.Log("Loading MaxskillsButWithoutOverkill. Skills that will not be maxskilled:\n");
foreach (string s in Configuration.Instance.ignoreTheseSkills)
Logger.Log("\t" + s + "\n");
skills = typeof(UnturnedSkill).GetFields(BindingFlags.Static | BindingFlags.Public);
skillCtor = typeof(UnturnedSkill).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null,
new Type[] { typeof(byte), typeof(byte) }, null);
if (Configuration.Instance.enableMaxskillsByDefault)
{
UnturnedPlayerEvents.OnPlayerRevive += OnRevive;
U.Events.OnPlayerConnected += OnConnect;
}
}
protected override void Unload()
{
if (Configuration.Instance.enableMaxskillsByDefault)
{
UnturnedPlayerEvents.OnPlayerRevive -= OnRevive;
U.Events.OnPlayerConnected -= OnConnect;
}
}
private void OnRevive(UnturnedPlayer p, Vector3 pos, byte a) => GrantSkills(p);
private void OnConnect(UnturnedPlayer p) => GrantSkills(p);
public void GrantSkills(UnturnedPlayer p)
{
p.MaxSkills();
foreach (FieldInfo x in skills)
if (Configuration.Instance.ignoreTheseSkills.Contains(x.Name))
{
UnturnedSkill s = (UnturnedSkill)x.GetValue(null);
p.SetSkillLevel(s, 0);
}
}
}
}