Иконка ресурса

FREE MChat : 0.0.1 0.0.1

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Configuration;
using Oxide.Core.Database;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using System;
using System.Collections.Generic;
using System.Linq;
using Oxide.Core.SQLite.Libraries;
using System.Text.RegularExpressions;
using UnityEngine;
using Oxide.Game.Rust.Cui;
using System.Collections;
using Newtonsoft.Json.Linq; 
using ConVar;

namespace Oxide.Plugins
{
    [Info("Chat", "Mystery", "0.0.1")]
    class MChat : RustPlugin
    {
		
		private class Configuration  
        {
			[JsonProperty("Список доступных типов префикса")]
			public List<string> Types = new List<string>();
            [JsonProperty("Список цензуры и исключений")]
            public Dictionary<string, List<string>> Censures = new Dictionary<string, List<string>>(); 
			[JsonProperty("Оповещать о подключении с префиксом")]
            public bool WelcomePrefix = true; 
			[JsonProperty(PropertyName = "Chat Icon (SteamID64)")]
            public ulong ChatIcon = 76561199032370579; 
			
			public static Configuration Generate() 
            {
               return new Configuration 
                {
					Types = new List<string>
                    {
                        "-",  
                        "[]",
                        "|" 
                    }
				};
            }
        }
		private static Configuration Settings;
		
		protected override void LoadConfig() 
        {
            base.LoadConfig();
            try
            {
                Settings = Config.ReadObject<Configuration>();
            }
            catch
            {
                PrintWarning($"Error reading config, creating one new config!");
                LoadDefaultConfig();
            }

            SaveConfig();
        }
		

        protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
        protected override void SaveConfig()        => Config.WriteObject(Settings);
		
		
		private Dictionary<ulong, PlayerChat> ChatData = new Dictionary<ulong, PlayerChat>();
		private class PlayerChat
        {
			[JsonProperty("Name")]
            public string DisplayName;
			[JsonProperty("SteamID")]
            public ulong SteamID;
			[JsonProperty("Name Color")]
            public string NameColor;
			[JsonProperty("g Color")] 
            public string gColor;
			
            [JsonProperty("Наименование префикса")] 
            public string Name;
            [JsonProperty("Цвет префикса")]
            public string Color;
            [JsonProperty("Размер префикса")] 
            public string Size;
            [JsonProperty("Скобки префикса")]
            public string Hooks;
        }
		
		void OnPlayerConnected(BasePlayer player)
		{
			if (!ChatData.ContainsKey(player.userID))
			{
				PlayerChat NewUser = new PlayerChat()
                {
                    DisplayName = player.displayName,
					SteamID = player.userID,
                    Name = "-",
                    Hooks = "-", 
                    Size = "<size=12>",
                    Color = "#FF8040FF",
					NameColor = "#FF8040FF",
					gColor = "#FF8040FF"
                    
				};
				ChatData.Add(player.userID, NewUser);
				OnServerSave();	
			}
            
            string apiUrl = "http://ip-api.com/json/";
			string text = $"<size=12>Player {PrepareNickForConnect(player)} Connected!</size>";
            foreach (var check in BasePlayer.activePlayerList.ToList())
            { 
			    Message(check, text);
            }
            
        } 
		private void Message(BasePlayer player, string message)
        {
            Player.Message(player, message, Settings.ChatIcon);
        }
		void OnServerSave()
        {
            Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject($"{Name}/{Title}", ChatData);
		}
		
		string CColor = $"MChat.color";
		string CPref = $"MChat.prefix";
		string CPrefText = $"MChat.textprefix";
		
		
		
		
		void OnServerInitialized() 
		{
			
			permission.RegisterPermission(CColor, this);
			permission.RegisterPermission(CPref, this);
			permission.RegisterPermission(CPrefText, this);
			if (Interface.Oxide.DataFileSystem.ExistsDatafile($"{Name}/{Title}"))
                ChatData = Oxide.Core.Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, PlayerChat>>($"{Name}/{Title}");
			foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
				OnPlayerConnected(player);
			}
		}
		private string PrepareNickForConnect(BasePlayer player)
        {
            var settings = ChatData[player.userID];

            string prefixPrepare = "continue";
            switch (settings.Hooks) 
            {
                case "[]": prefixPrepare = $"[<color={settings.Color}>{settings.Name}</color>]";
                    break;
                case "-": prefixPrepare = $"<color={settings.Color}>{settings.Name}</color>";
                    break;
                case "|": prefixPrepare = $"<color={settings.Color}>{settings.Name}</color> |";
                    break;
            }

            if (settings.Name == "-")
                prefixPrepare = "";
            
            string format = "continue";
            switch (settings.Hooks)
            {
                case "[]": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{player.displayName}</color>";
                    break;
                case "-": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{player.displayName}</color>";
                    break;
                case "|": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{player.displayName}</color>";
                    break;
            }
            
            return format; 
        }
		void OnPlayerCorpse(BasePlayer player, BaseCorpse corpse)
        {
            if (!ChatData.ContainsKey(player.userID)) return;

            var obj = corpse.GetComponent<PlayerCorpse>();
            if (obj == null) return;
            obj._playerName = PrepareNick(player);
        }
        private string PrepareNick(BasePlayer player)
        {
            var settings = ChatData[player.userID];

            string prefixPrepare = "continue";
            switch (settings.Hooks) 
            {
                case "[]": prefixPrepare = $"[<color={settings.Color}>{settings.Name}</color>]";
                    break;
                case "-": prefixPrepare = $"<color={settings.Color}>{settings.Name}</color>";
                    break;
                case "|": prefixPrepare = $"<color={settings.Color}>{settings.Name}</color> |";
                    break;
            }

            if (settings.Name == "-")
                prefixPrepare = "";

            string name = player.displayName.Length > 26 ? player.displayName.Substring(0, 26) : player.displayName;

            string format = "continue";
            switch (settings.Hooks)
            {
                case "[]": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{name}</color>";
                    break;
                case "-": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{name}</color>";
                    break;
                case "|": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{name}</color>";
                    break;
            }
            
            return format; 
        }
		
		private string PrepareMessage(BasePlayer player, string message, bool team = false) 
        {
            var settings = ChatData[player.userID];

            string prefixPrepare = "continue";
            switch (settings.Hooks)
            {
                case "[]": prefixPrepare = $"{settings.Size}[<color={settings.Color}>{settings.Name}</color>]</size>";
                    break;
                case "-": prefixPrepare = $"{settings.Size}<color={settings.Color}>{settings.Name}</color></size>";
                    break;
                case "|": prefixPrepare = $"{settings.Size}<color={settings.Color}>{settings.Name}</color></size> |";
                    break;
            } 
 
            if (settings.Name == "-") 
                prefixPrepare = "";    
            
            string format = "continue";
            switch (settings.Hooks)
            {
                case "[]": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{player.displayName}</color>: {message}";
                    break;
                case "-": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{player.displayName}</color>: {message}";
                    break;
                case "|": format = $"<color={settings.gColor}>{prefixPrepare}</color> <color={settings.NameColor}>{player.displayName}</color>: {message}";
                    break;
            }

            if (team) format = "<color=#ADFF2F>[TEAM]</color> " + format;
            
            return format;
        }
		
		private string Censure(string message)
        {
            foreach (var mat in Settings.Censures)
            {
                if (message.ToLower().Contains(mat.Key))
                {
                    bool shouldReplace = true;
                    foreach (var ist in mat.Value)
                    {
                        if (message.Contains(ist))
                        {
                            shouldReplace = false;
                            break;
                        }
                    }

                    if (shouldReplace) message = message.Replace(mat.Key, $"\n<color=#FF8000FF>{ConVar.Server.hostname}</color>\n<color=#FF0080FF>connect {ConVar.Server.ip}:{ConVar.Server.port}</color>", StringComparison.CurrentCultureIgnoreCase);
                }
            }

            return message; 
        }
		
		private object OnPlayerChat(BasePlayer player, string message, ConVar.Chat.ChatChannel channel)
		{
			while (message.Contains("size"))
                message = message.Replace("size", "");
			if (channel == ConVar.Chat.ChatChannel.Global) 
			{
				string realMessage = PrepareMessage(player, Censure(message)); 
				foreach (var check in BasePlayer.activePlayerList.ToList())
                {
                    var settings = ChatData[check.userID];
                    //if (settings.IgnoreList.ContainsKey(player.userID) || !settings.Chatters.Chat)
                       // continue;
                    
                     
                    check.SendConsoleCommand("chat.add", 0, player.userID, realMessage);
                    check.SendConsoleCommand($"echo [<color=white>ЧАТ</color>] {realMessage}");
                }
				return false;
			}
			else
			{
				return false;
			}
			return null;
		}

        private string SettingsLayer = "UI_SettingsLayer";
        [ChatCommand("chat")]
        private void CmdChatCommandSecret(BasePlayer player, string command, string[] args) => InitializeInterface(player);
		void InitializeInterface(BasePlayer player)
		{
			var db = ChatData[player.userID];
			CuiElementContainer container = new CuiElementContainer();
			CuiHelper.DestroyUi(player, "Chat");
			CuiHelper.DestroyUi(player, "Pref");
			CuiHelper.DestroyUi(player, "TextPref");
			CuiHelper.DestroyUi(player, "Color");
			container.Add(new CuiPanel
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1"},
                    Image =
                    {  
                        Color = "0 0 0 0",
                    },
                    CursorEnabled = true 
                }, SettingsLayer + ".R", "Chat");
			container.Add(new CuiPanel
                {
                    RectTransform = {AnchorMin = "0 0.9", AnchorMax = "1 1"},
                    Image =
                    {  
                        Color = "0.89 0.81 0.70 0.6",
                    },
                    CursorEnabled = true 
                }, "Chat", "Nick");
			container.Add(new CuiPanel
                {
                    RectTransform = {AnchorMin = "0 0.6", AnchorMax = "1 0.85"},
                    Image =
                    {  
                        Color = "0.89 0.81 0.70 0.4",
                    },
                    CursorEnabled = true 
                }, "Chat", "TextPref");
			container.Add(new CuiPanel
                {
                    RectTransform = {AnchorMin = "0 0.3", AnchorMax = "1 0.55"},
                    Image =
                    {  
                        Color = "0.89 0.81 0.70 0.4",
                    },
                    CursorEnabled = true 
                }, "Chat", "Pref");
			container.Add(new CuiPanel
                {
                    RectTransform = {AnchorMin = "0 0", AnchorMax = "1 0.25"},
                    Image =
                    {  
                        Color = "0.89 0.81 0.70 0.4",
                    },
                    CursorEnabled = true 
                }, "Chat", "Color");
				
				
				
				
			container.Add(new CuiElement
            {
				Parent = "Nick",
                Components =
                {
                    new CuiTextComponent {Color = "0.00 1.00 0.25 0.2", Text = $"{PrepareNick(player)}", Align = TextAnchor.MiddleCenter, FontSize = 20},
                    new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
                    new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                }
            });	
			
			container.Add(new CuiElement
            {
				Parent = "TextPref",
                Components =
                {
                    new CuiTextComponent {Color = "1 1 1 0.5", Text = $"TEXT PREFIX", Align = TextAnchor.MiddleCenter, FontSize = 20},
                    new CuiRectTransformComponent { AnchorMin = "0 0.4", AnchorMax = "1 1" },
                    new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                }
            });	
			
			if(permission.UserHasPermission(player.UserIDString, CPrefText))
			{
				container.Add(new CuiElement
                    {
                        Parent = "TextPref",
                        Name = "TextPref" + ".Input",
                        Components =
                        {
                            new CuiImageComponent { Color = "0.89 0.81 0.70 0.6"},
                            new CuiRectTransformComponent { AnchorMin = "0.1 0.1", AnchorMax = "0.35 0.5" },
                            new CuiOutlineComponent{Distance = "1 1", Color = "1.00 0.50 0.50 0"}
                        }
                    });

                    container.Add(new CuiElement
                    {
                        Parent = "TextPref" + ".Input",
                        Name = "TextPref" + ".Input.Current",
                        Components =
                        {
                            new CuiInputFieldComponent { FontSize = 16, Align = TextAnchor.MiddleCenter, Command = "uiChat textprefix", Text = $"{db.Size}<color={db.Color}>{db.Name}</color></size>"},
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
							new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                        }
                    });
				container.Add(new CuiElement
                    {
                        Parent = "TextPref",
                        Name = "TextPref" + ".Input1",
                        Components =
                        {
                            new CuiImageComponent { Color = "0.89 0.81 0.70 0.6"},
                            new CuiRectTransformComponent { AnchorMin = "0.4 0.1", AnchorMax = "0.65 0.5" },
                            new CuiOutlineComponent{Distance = "1 1", Color = "1.00 0.50 0.50 0"}
                        }
                    });
 
                    container.Add(new CuiElement
                    {
                        Parent = "TextPref" + ".Input1",
                        Name = "TextPref" + ".Input.Current1",
                        Components =
                        {
                            new CuiInputFieldComponent { FontSize = 16, Align = TextAnchor.MiddleCenter, Command = "uiChat textprefixc", Text = $"<color={db.Color}>{db.Color}</color>"},
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
							new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                        }
                    });
				container.Add(new CuiElement
                    {
                        Parent = "TextPref",
                        Name = "TextPref" + ".Input11",
                        Components =
                        {
                            new CuiImageComponent { Color = "0.89 0.81 0.70 0.6"},
                            new CuiRectTransformComponent { AnchorMin = "0.7 0.1", AnchorMax = "0.9 0.5" },
                            new CuiOutlineComponent{Distance = "1 1", Color = "1.00 0.50 0.50 0"}
                        }
                    });
 
                    container.Add(new CuiElement
                    {
                        Parent = "TextPref" + ".Input11",
                        Name = "TextPref" + ".Input.Current11",
                        Components =
                        {
                            new CuiInputFieldComponent { FontSize = 16, Align = TextAnchor.MiddleCenter, Command = "uiChat textprefixs", Text = $"{db.Size}"},
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
							new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                        }
                    });
				
			}
			
			container.Add(new CuiElement
            {
				Parent = "Pref",
                Components =
                {
                    new CuiTextComponent {Color = "1 1 1 0.5", Text = $"PREFIX", Align = TextAnchor.MiddleCenter, FontSize = 20},
                    new CuiRectTransformComponent { AnchorMin = "0 0.4", AnchorMax = "1 1" },
                    new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                }
            });	
			
			if(permission.UserHasPermission(player.UserIDString, CPref))
			{
				float width = 0.2f, height = 0.4f, startxBox = 0.1f, startyBox = 0.5f - height, xmin = startxBox, ymin = startyBox;
				foreach (var check in Settings.Types)
				{
					
					
					container.Add(new CuiButton
                    {
                        RectTransform = { AnchorMin = $"{xmin} {ymin}", AnchorMax = $"{xmin + width * 0.9} {ymin + height * 1}" },
                        Button = { Color = "0.89 0.81 0.70 0.6", Command = $"uiChat prefix {check}" },
                        Text = { Text = $"<color={db.gColor}>{check}</color>", Font = "robotocondensed-bold.ttf", FontSize = 22, Align = TextAnchor.MiddleCenter, Color = "1.00 0.53 0.53 0.5"}
                    }, "Pref");
					xmin += width;
                    if (xmin + width >= 1)
                    {
                        xmin = startxBox;
                        ymin -= height;
                    }
				}
				container.Add(new CuiElement
                    {
                        Parent = "Pref",
                        Name = "Pref" + ".Input",
                        Components =
                        {
                            new CuiImageComponent { Color = "0.89 0.81 0.70 0.6"},
                            new CuiRectTransformComponent { AnchorMin = "0.75 0.1", AnchorMax = "0.92 0.5" },
                            new CuiOutlineComponent{Distance = "1 1", Color = "1.00 0.50 0.50 0"}
                        }
                    });

                    container.Add(new CuiElement
                    {
                        Parent = "Pref" + ".Input",
                        Name = "Pref" + ".Input.Current",
                        Components =
                        {
                            new CuiInputFieldComponent { FontSize = 16, Align = TextAnchor.MiddleCenter, Command = "uiChat prefixc", Text = $"<color={db.gColor}>{db.gColor}</color>", Color = "1.00 0.53 0.53 0.5"},
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
							new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                        }
                    });
					
		    
			}
			container.Add(new CuiElement
            {
				Parent = "Color",
                Components =
                {
                    new CuiTextComponent {Color = "1 1 1 0.5", Text = $"NICKNAME COLOR", Align = TextAnchor.MiddleLeft, FontSize = 20},
                    new CuiRectTransformComponent { AnchorMin = "0.02 0", AnchorMax = "0.3 1" },
                    new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                }
            });	
			
			if(permission.UserHasPermission(player.UserIDString, CColor))
			{
				container.Add(new CuiElement
                    {
                        Parent = "Color",
                        Name = "Color" + ".Input",
                        Components =
                        {
                            new CuiImageComponent { Color = "0.89 0.81 0.70 0.6"},
                            new CuiRectTransformComponent { AnchorMin = "0.4 0.14", AnchorMax = "0.8 0.86" },
                            new CuiOutlineComponent{Distance = "1 1", Color = "1.00 0.50 0.50 0"}
                        }
                    });

                    container.Add(new CuiElement
                    {
                        Parent = "Color" + ".Input",
                        Name = "Color" + ".Input.Current",
                        Components =
                        {
                            new CuiInputFieldComponent { FontSize = 16, Align = TextAnchor.MiddleCenter, Command = "uiChat ncolor", Text = $"<color={db.NameColor}>{db.NameColor}</color>"},
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
							new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                        }
                    });
			}
			CuiHelper.AddUi(player, container);
			
		}
		[ConsoleCommand("uiChat")] 
        private void CmdConsoleHandler(ConsoleSystem.Arg args)
        {
            var player = args.Player();
            var db = ChatData[player.userID];
			if (player != null && args.HasArgs(1))
            {
                if (args.Args[0] == "prefix") 
                {
					db.Hooks = args.Args[1];
                    InitializeInterface(player); 
					OnServerSave();
                    //ProfileUI(player, ulong.Parse(args.Args[1]), int.Parse(args.Args[2]));
                }
				if (args.Args[0] == "prefixc")
                {
					db.gColor = args.Args[1];
                    InitializeInterface(player); 
					OnServerSave();
                    //ProfileUI(player, ulong.Parse(args.Args[1]), int.Parse(args.Args[2]));
                }
                if (args.Args[0] == "textprefix")
                {
                    db.Name = args.Args[1];
                    InitializeInterface(player); 
					OnServerSave();
                }
                if (args.Args[0] == "textprefixc")
                {
                    db.Color = args.Args[1];
                    InitializeInterface(player); 
					OnServerSave();
                }
				if (args.Args[0] == "textprefixs")
                {
                    db.Size = args.Args[1];
                    InitializeInterface(player); 
					OnServerSave();
                }
				if (args.Args[0] == "ncolor")
                {
                    db.NameColor = args.Args[1];
                    InitializeInterface(player); 
					OnServerSave();
                }
                
            }
		}
		[PluginReference] Plugin ImageLibrary;
		
		
		
		        /*container.Add(new CuiElement
                    {
                        Parent = "DSP",
                        Name = "DSP" + ".Input",
                        Components =
                        {
                            new CuiImageComponent { Color = "0.16 0.34 0.49 0"},
                            new CuiRectTransformComponent { AnchorMin = "0.12 0.14", AnchorMax = "0.92 0.86" },
                           // new CuiOutlineComponent{Distance = "5.5 5.5", Color = "0.5 1 1 1"}
                        }
                    });

                    container.Add(new CuiElement
                    {
                        Parent = "DSP" + ".Input",
                        Name = "DSP" + ".Input.Current",
                        Components =
                        {
                            new CuiInputFieldComponent { FontSize = 16, Align = TextAnchor.MiddleCenter, Command = "DIS", Text = "CODE", Color = "1.00 0.53 0.53 0.5"},
                            new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" },
							new CuiOutlineComponent { Color = "0 0 0 1", Distance = "1 1" }
                        }
                    });
		*/
	}
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху