-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
126 lines (100 loc) · 3.81 KB
/
Main.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
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
using Rocket.Core.Plugins;
using Rocket.Unturned.Chat;
using SDG.Unturned;
using Steamworks;
using Rocket.Unturned;
using Rocket.Unturned.Player;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace GroupCapper
{
public class Main : RocketPlugin<Config>
{
public static Main Instance;
private int _maxPlayers;
private bool _changePlayersGroup;
private Color _chatColor;
private bool _notfiyPlayer;
protected override void Load()
{
Instance = this;
//Dank ass ASCII and some other shit
Rocket.Core.Logging.Logger.LogError("\n _________ __ \n / _____/ ____ ____ _____/ |_ ___.__.\n \\_____ \\_/ ___\\/ _ \\ / _ \\ __< | |\n / \\ \\__( <_> ( <_> | | \\___ |\n/_______ /\\___ \\____/ \\____/|__| / ____|\n \\/ \\/ \\/ ");
Rocket.Core.Logging.Logger.Log("\n.___ \n| | ______\n| |/ ___/\n| |\\___ \\ \n|___/____ >\n \\/ ");
Rocket.Core.Logging.Logger.LogWarning("\n___. \n\\_ |__ _____ ____ \n | __ \\\\__ \\ _/ __ \\ \n | \\_\\ \\/ __ \\\\ ___/ \n |___ (____ /\\___ >\n \\/ \\/ \\/ ");
_maxPlayers = Instance.Configuration.Instance.maxGroupSize;
_changePlayersGroup = Instance.Configuration.Instance.changePlayerGroups;
_chatColor = UnturnedChat.GetColorFromName(Instance.Configuration.Instance.chatColor, Color.green);
_notfiyPlayer = Instance.Configuration.Instance.notifyPlayer;
U.Events.OnPlayerConnected += Join;
U.Events.OnPlayerDisconnected += Leave;
//If the plugin is reloaded, re add the player events
try
{
foreach (var steamPlayer in Provider.clients)
{
steamPlayer.player.quests.groupIDChanged += GroupChanged;
}
}
catch { }
}
protected override void Unload()
{
U.Events.OnPlayerDisconnected -= Leave;
U.Events.OnPlayerConnected -= Join;
//If the plugin is unloaded remove the events
try
{
foreach (var steamPlayer in Provider.clients)
{
steamPlayer.player.quests.groupIDChanged -= GroupChanged;
}
}
catch { }
}
public override Rocket.API.Collections.TranslationList DefaultTranslations
{
get
{
return new Rocket.API.Collections.TranslationList
{
{"reason", "You were moved out of your group"}
};
}
}
private void Join(UnturnedPlayer player)
{
player.Player.quests.groupIDChanged += GroupChanged;
CheckRemoveGroup(player);
}
private void Leave(UnturnedPlayer player)
{
player.Player.quests.groupIDChanged -= GroupChanged;
}
private void GroupChanged(PlayerQuests sender, CSteamID oldgroupid, CSteamID newgroupid)
{
if(newgroupid != CSteamID.Nil)
CheckRemoveGroup(UnturnedPlayer.FromPlayer(sender.player));
}
private void CheckRemoveGroup(UnturnedPlayer player)
{
if (GroupManager.getGroupInfo(player.Player.quests.groupID).members <= _maxPlayers) return;
player.Player.quests.channel.send("tellSetGroup", ESteamCall.ALL, ESteamPacket.UPDATE_RELIABLE_BUFFER,
new object[]
{
CSteamID.Nil,
(byte) 0
});
var mGroupInfo = typeof(PlayerQuests).GetField("inMainGroup",
BindingFlags.Instance | BindingFlags.NonPublic);
if (mGroupInfo != null)
mGroupInfo
.SetValue(player.Player.quests, false);
//Notifying the player
if (_notfiyPlayer)
UnturnedChat.Say(player, Translate("reason"), _chatColor);
}
}
}