-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
89 lines (85 loc) · 4.52 KB
/
Plugin.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
using System;
using Rocket.Core.Plugins;
using Rocket.Unturned.Player;
using SDG.Unturned;
using UnityEngine;
namespace UCGS.RichChat
{
public class Plugin : RocketPlugin<Config>
{
public static Plugin Instance;
public static Config Config;
string PluginVersion = "1.0.0";
protected override void Load()
{
Instance = this;
Config = base.Configuration.Instance;
ChatManager.onChatted += ClientChatted;
Extensions.WriteConsole("Plugin loaded successfully.");
Extensions.WriteConsole("Plugin version : " + PluginVersion);
Extensions.WriteConsole("Groups loaded : " + Config.Groups.Count);
Extensions.WriteConsole("Author : Maximjetfs");
Extensions.WriteConsole("github.com/Maximjetfs1305");
}
protected override void Unload()
{
Instance = null;
Config = null;
ChatManager.onChatted -= ClientChatted;
Extensions.WriteConsole("Plugin unloaded.");
}
private void ClientChatted(SteamPlayer sendClient, EChatMode chatMode, ref Color color, ref bool isRich, string message, ref bool isVisible)
{
UnturnedPlayer client = UnturnedPlayer.FromSteamPlayer(sendClient);
if (message.StartsWith("/")) return;
if (client.ChekClientGroups(out Group group))
{
isVisible = false;
if (chatMode == EChatMode.GLOBAL)
{
foreach (SteamPlayer toClient in Provider.clients)
{
string ModePrefix = Config.ChatModePrefix ? "<color=" + Config.GlobalPrefixColor + ">" + Config.GlobalPrefix + "</color> " : "";
string PermissionTag = "<color=" + group.ColorTag + ">" + group.Tag + "</color> ";
string ClientName = "<color=" + group.ColorName + ">" + toClient.playerID.characterName + "</color> : ";
string Message = "<color=" + group.ColorText + ">" + message + "</color>";
toClient.ChatPrint(ModePrefix + PermissionTag + ClientName + Message, sendClient);
}
}
if (chatMode == EChatMode.LOCAL)
{
foreach (SteamPlayer toClient in Provider.clients)
{
if (!(toClient.player == null) && (toClient.player.transform.position - sendClient.player.transform.position).sqrMagnitude < 16384f)
{
string ModePrefix = Config.ChatModePrefix ? "<color=" + Config.GlobalPrefixColor + ">" + Config.GlobalPrefix + "</color> " : "";
string PermissionTag = "<color=" + group.ColorTag + ">" + group.Tag + "</color> ";
string ClientName = "<color=" + group.ColorName + ">" + toClient.playerID.characterName + "</color> : ";
string Message = "<color=" + group.ColorText + ">" + message + "</color>";
toClient.ChatPrint(ModePrefix + PermissionTag + ClientName + Message, sendClient);
}
}
}
if (chatMode == EChatMode.GROUP)
{
foreach (SteamPlayer toClient in Provider.clients)
{
if (!(toClient.player == null) && toClient.player.quests.isMemberOfSameGroupAs(sendClient.player))
{
string ModePrefix = Config.ChatModePrefix ? "<color=" + Config.GlobalPrefixColor + ">" + Config.GlobalPrefix + "</color> " : "";
string PermissionTag = "<color=" + group.ColorTag + ">" + group.Tag + "</color> ";
string ClientName = "<color=" + group.ColorName + ">" + toClient.playerID.characterName + "</color> : ";
string Message = "<color=" + group.ColorText + ">" + message + "</color>";
toClient.ChatPrint(ModePrefix + PermissionTag + ClientName + Message, sendClient);
}
}
}
}
else
{
Rocket.Core.Logging.Logger.Log("[RichChat] Client \" " + sendClient.playerID.steamID.ToString() + " \" has no chat settings.", ConsoleColor.Red);
return;
}
}
}
}