forked from Plugin4UGit/Channels
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Channels.cs
109 lines (103 loc) · 3.86 KB
/
Channels.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
using Rocket.API;
using Rocket.API.Collections;
using Rocket.Core.Commands;
using Rocket.Core.Plugins;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Events;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Steamworks;
using System;
using System.Collections.Generic;
namespace Channels
{
public class Main : RocketPlugin
{
int Times;
public List<ChannelPlayer> Channels = new List<ChannelPlayer>();
protected override void Load()
{
base.Load();
UnturnedPlayerEvents.OnPlayerChatted += UnturnedPlayerEvents_OnPlayerChatted;
Rocket.Core.Logging.Logger.Log("[Plugin4U] Channels Loaded!", ConsoleColor.Blue);
Rocket.Core.Logging.Logger.Log("Make sure to check out our website : Plugin4U.cf ", ConsoleColor.Magenta);
}
public override TranslationList DefaultTranslations
{
get
{
return new TranslationList()
{
{"globalchat", "You don't have global chat permission!"},
{"chat_switch", "You're now chatting in {0}."},
{"no_permission", "You don't have permission to chat here!" }
};
}
}
[RocketCommand("switchchannel", "", "", AllowedCaller.Player)]
[RocketCommandAlias("sw")]
public void Execute(IRocketPlayer caller, params string[] command)
{
UnturnedPlayer player = (UnturnedPlayer)caller;
foreach (var channel in Channels)
{
if (channel.id == player.CSteamID)
{
Channels.Remove(channel);
}
}
Channels.Add(new ChannelPlayer(player.CSteamID, command[0]));
UnturnedChat.Say(caller, Translate("chat_switch", command[0]));
}
private void UnturnedPlayerEvents_OnPlayerChatted(Rocket.Unturned.Player.UnturnedPlayer player, ref UnityEngine.Color color, string message, SDG.Unturned.EChatMode chatMode, ref bool cancel)
{
var result = GetChannel(player.CSteamID);
if(result != null && chatMode == 0 && player.HasPermission("channel." + result.Channel.ToLower()) && result.Channel.ToLower() != "global" && !message.StartsWith("/") && !message.StartsWith("@"))
{
cancel = true;
foreach(var steamplayer in Provider.clients)
{
UnturnedPlayer stm = UnturnedPlayer.FromSteamPlayer(steamplayer);
if (stm.HasPermission("channel." + result.Channel.ToLower()))
{
UnturnedChat.Say(steamplayer.playerID.steamID, "[" + result.Channel + "] " + player.CharacterName + " : " + message);
Times = 1;
}
}
}
if(result.Channel.ToLower() == "global" && chatMode == 0 && (!message.StartsWith("/") && !message.StartsWith("@")))
{
if (player.HasPermission("chat.global"))
{
ChatManager.instance.askChat(player.CSteamID, 0, message);
Times = 1;
}
}
if(Times == 0)
{
UnturnedChat.Say(player, Translate("no_permission"));
}
}
public ChannelPlayer GetChannel(CSteamID id)
{
foreach(var channel in Channels)
{
if(channel.id == id)
{
return channel;
}
}
return new ChannelPlayer(id, "global");
}
}
public class ChannelPlayer
{
public CSteamID id;
public string Channel;
public ChannelPlayer(CSteamID id , string Channel)
{
this.id = id;
this.Channel = Channel;
}
}
}