using Newtonsoft.Json; using Oxide.Core; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; using System; using System.Collections.Generic; using System.IO; using System.Linq; using UnityEngine; using System.Text; using System.Text.RegularExpressions; using System.Timers; using System.Security; namespace Oxide.Plugins { [Info("EasyRules", "Lockdown", "1.0.1")] [Description("Server rules with style!")] public class EasyRules : CovalencePlugin { #region Configuration private PluginConfig config; class PluginConfig { [JsonProperty(PropertyName = "Chat Icon - SteamID64")] public ulong ChatIcon = 0; [JsonProperty(PropertyName = "Use Chat Prefix - True/False")] public bool ShowChatPrefix = true; [JsonProperty(PropertyName = "Chat Prefix")] public string ChatPrefix = "Rules"; [JsonProperty(PropertyName = "Chat Prefix Color")] public string ChatPrefixColor = "#D65757"; [JsonProperty(PropertyName = "Chat Message")] public string ChatMessage = "1. No Racism\n2. No Advertising\n3. No Cheat's or Macro's\n4. No Teaming\n5. Don't be a prick"; } protected override void LoadConfig() { base.LoadConfig(); try { config = Config.ReadObject(); if (config == null) throw new Exception(); } catch { LoadDefaultConfig(); } SaveConfig(); } protected override void LoadDefaultConfig() { string configPath = $"{Interface.Oxide.ConfigDirectory}{Path.DirectorySeparatorChar}{Name}.json"; LogWarning($"Could not load a valid configuration file, creating a new configuration file at {configPath}"); config = new PluginConfig(); } protected override void SaveConfig() => Config.WriteObject(config); #endregion #region Commands void OnPlayerConnected(BasePlayer player) { ulong ChatIcon = config.ChatIcon; if (config.ShowChatPrefix) { string text = $"{config.ChatPrefix}:\n{config.ChatMessage}"; player.SendConsoleCommand("chat.add", 2, ChatIcon, text); SaveConfig(); } else { string text = $"{config.ChatMessage}"; player.SendConsoleCommand("chat.add", 2, ChatIcon, text); SaveConfig(); } } [Command("rules")] void RulesCommand(IPlayer player, string command, string[] args) { BasePlayer basePlayer = player.Object as BasePlayer; if (basePlayer == null) { return; } ulong ChatIcon = config.ChatIcon; if (config.ShowChatPrefix) { string text = $"{config.ChatPrefix}:\n{config.ChatMessage}"; basePlayer.SendConsoleCommand("chat.add", 2, ChatIcon, text); SaveConfig(); } else { string text = $"{config.ChatMessage}"; basePlayer.SendConsoleCommand("chat.add", 2, ChatIcon, text); SaveConfig(); } } [Command("prefix"), Permission("easyrules.admin")] private void CommandPrefix(IPlayer player, string command, string[] args) { if (args.Length > 0) { ulong ChatIcon = config.ChatIcon; config.ChatPrefix = args[0]; string text = $"{config.ChatPrefix}: Successfully Changed Prefix To {config.ChatPrefix}"; (player.Object as BasePlayer).SendConsoleCommand("chat.add", 2, ChatIcon, text); SaveConfig(); } else { if (args.Length == 0) { player.Reply($"Usage:{Environment.NewLine}/prefix (name)"); return; } } } #endregion } }