From 35cd0ffa7e670ccb1d25fcdbb2bc881cc06fc59d Mon Sep 17 00:00:00 2001 From: XingYeFish <154997195+XingYeNotFish@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:05:44 +0800 Subject: [PATCH] V1.0.1 update --- Server Maid/Command.cs | 186 +++++++++++++++++++++++++++++ Server Maid/CommandTranslations.cs | 9 ++ Server Maid/Maid.cs | 26 ++-- Server Maid/Plugin.cs | 7 +- Server Maid/Server Maid.csproj | 6 +- Server Maid/XYlikeconfig.cs | 14 ++- 6 files changed, 228 insertions(+), 20 deletions(-) create mode 100644 Server Maid/Command.cs create mode 100644 Server Maid/CommandTranslations.cs diff --git a/Server Maid/Command.cs b/Server Maid/Command.cs new file mode 100644 index 0000000..28ce120 --- /dev/null +++ b/Server Maid/Command.cs @@ -0,0 +1,186 @@ +using CommandSystem; +using Exiled.API.Extensions; +using Exiled.API.Features; +using Exiled.API.Features.Pickups; +using MEC; +using PlayerRoles; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server_Maid +{ + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class ServerMaidParent : ParentCommand + { + public ServerMaidParent() + { + LoadGeneratedCommands(); + } + + public override string Command => "servermaid"; + + public override string[] Aliases { get; } = { "maid" }; + + public override string Description => "ServerMaid's Parent Command"; + + public sealed override void LoadGeneratedCommands() + { + var commandTranslations = new CommandTranslations(); + + RegisterCommand(commandTranslations.StopClean); + RegisterCommand(commandTranslations.ReStartClean); + RegisterCommand(commandTranslations.ForceClean); + } + + protected override bool ExecuteParent(ArraySegment arguments, ICommandSender sender, + out string response) + { + var playerSender = Player.Get(sender); + if (playerSender == null) + { + response = "Players don't exist!"; + return false; + } + response = "stopclean\n\nDeactivate servermaid for this round.\nrestartclean\n\nRe-enable servermaid for this round.\nforceclean\n\nImmediate implementation of a clean."; + return true; + } + } + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class StopClean : ICommand + { + public string[] Aliases => new string[] { "stopclean" }; + public string Description => "Deactivate servermaid for this round."; + public string Command => "stopclean"; + private static XYlikeconfig Config => Plugin.Instance.Config; + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player p = Player.Get(sender); + if (arguments.Count != 0) + { + response = "Error!"; + return false; + } + if (p == null) + { + response = "Players don't exist!"; + return false; + } + if (!Config.IsCleaningModuleEnabled) + { + response = "Error! ServerMaid is not enabled at all!"; + return false; + } + + Timing.KillCoroutines(Maid.MaidSystem_Coroutine); + Map.Broadcast(8, $"[Server Maid]Admin {p.Nickname} has turned off auto-cleanup for this round"); + response = "Success!"; + return true; + } + } + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class ReStartClean : ICommand + { + public string[] Aliases => new string[] { "restartclean" }; + public string Description => "Re-enable servermaid for this round."; + public string Command => "restartclean"; + private static XYlikeconfig Config => Plugin.Instance.Config; + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player p = Player.Get(sender); + if (arguments.Count != 0) + { + response = "Error!"; + return false; + } + if (p == null) + { + response = "Players don't exist!"; + return false; + } + if (!Config.IsCleaningModuleEnabled) + { + response = "Error! ServerMaid is not enabled at all!"; + return false; + } + + if (Timing.IsRunning(Maid.MaidSystem_Coroutine)) + { + Timing.KillCoroutines(Maid.MaidSystem_Coroutine); + } + + Maid.MaidSystem_Coroutine = Timing.RunCoroutine(Maid.MaidSystem()); + Map.Broadcast(8, $"[Server Maid]Admin {p.Nickname} has restart auto-cleanup for this round"); + response = "Success!"; + return true; + } + } + [CommandHandler(typeof(RemoteAdminCommandHandler))] + public class ForceClean : ICommand + { + public string[] Aliases => new string[] { "forceclean" }; + public string Description => "Immediate implementation of a clean."; + public string Command => "forceclean"; + private static XYlikeconfig Config => Plugin.Instance.Config; + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + Player p = Player.Get(sender); + if (arguments.Count != 0) + { + response = "Error!"; + return false; + } + if (p == null) + { + response = "Players don't exist!"; + return false; + } + if (!Config.IsCleaningModuleEnabled) + { + response = "Error! ServerMaid is not enabled at all!"; + return false; + } + + int ragdollnum = 0; + int itemnum = 0; + + foreach (Ragdoll ragdoll in Ragdoll.List.ToHashSet()) + { + if (!Config.IsCleaning0492Ragdolls) + { + if (ragdoll.Role == RoleTypeId.Scp0492) + { + continue; + } + } + ragdoll.Destroy(); + int num = ragdollnum; + ragdollnum = num + 1; + } + + foreach (Pickup item in Pickup.List.ToHashSet()) + { + bool flag = !item.Type.IsScp() && !item.Type.IsKeycard() && !item.Type.IsMedical() && !item.Type.IsThrowable() && item.Type != ItemType.MicroHID && !item.Type.IsWeapon(true); + if (flag) + { + item.Destroy(); + int num = itemnum; + itemnum = num + 1; + } + } + + if (Timing.IsRunning(Maid.MaidSystem_Coroutine)) + { + Timing.KillCoroutines(Maid.MaidSystem_Coroutine); + } + + Maid.MaidSystem_Coroutine = Timing.RunCoroutine(Maid.MaidSystem()); + Log.Warn(string.Format(Config.ServerConsoleMessages, itemnum, ragdollnum)); + Map.Broadcast(10, $"[Server Maid]Admin {p.Nickname} has run forceclean command. \nCleaning {itemnum} items and {ragdollnum} ragdolls this time!"); + response = "Success!"; + return true; + } + } +} diff --git a/Server Maid/CommandTranslations.cs b/Server Maid/CommandTranslations.cs new file mode 100644 index 0000000..916fecd --- /dev/null +++ b/Server Maid/CommandTranslations.cs @@ -0,0 +1,9 @@ +namespace Server_Maid +{ + public class CommandTranslations + { + public StopClean StopClean { get; set; } = new StopClean(); + public ReStartClean ReStartClean { get; set; } = new ReStartClean(); + public ForceClean ForceClean { get; set; } = new ForceClean(); + } +} \ No newline at end of file diff --git a/Server Maid/Maid.cs b/Server Maid/Maid.cs index be0319a..1a2c578 100644 --- a/Server Maid/Maid.cs +++ b/Server Maid/Maid.cs @@ -5,25 +5,26 @@ using MEC; using System.Collections.Generic; using System.Linq; +using PlayerRoles; namespace Server_Maid { public class Maid { public static CoroutineHandle MaidSystem_Coroutine; - private static XYlikeconfig config => Plugin.Instance.Config; + private static XYlikeconfig Config => Plugin.Instance.Config; public static void Start() { - if (config.Is_cleaning_module_enabled) + if (Config.IsCleaningModuleEnabled) { MaidSystem_Coroutine = Timing.RunCoroutine(MaidSystem()); - Log.Warn(config.Cleaning_module_enabled_server_console_messages); + Log.Warn(Config.CleaningModuleEnabledServerConsoleMessages); } } public static void End(RoundEndedEventArgs e) { - if (config.Is_cleaning_module_enabled) + if (Config.IsCleaningModuleEnabled) { Timing.KillCoroutines(MaidSystem_Coroutine); } @@ -32,7 +33,7 @@ public static void End(RoundEndedEventArgs e) public static IEnumerator MaidSystem() { - yield return Timing.WaitForSeconds(config.Cleaning_interval); + yield return Timing.WaitForSeconds(Config.CleaningInterval); for (; ; ) { int ragdollnum = 0; @@ -40,6 +41,13 @@ public static IEnumerator MaidSystem() foreach (Ragdoll ragdoll in Ragdoll.List.ToHashSet()) { + if (!Config.IsCleaning0492Ragdolls) + { + if (ragdoll.Role == RoleTypeId.Scp0492) + { + continue; + } + } ragdoll.Destroy(); int num = ragdollnum; ragdollnum = num + 1; @@ -56,14 +64,14 @@ public static IEnumerator MaidSystem() } } - Log.Warn(string.Format(config.Server_console_messages, itemnum, ragdollnum)); + Log.Warn(string.Format(Config.ServerConsoleMessages, itemnum, ragdollnum)); - Timing.CallDelayed(5f, delegate () + Timing.CallDelayed(3f, delegate () { - Map.Broadcast(10, string.Format(config.Broadcast_messages, itemnum, ragdollnum), 0, true); + Map.Broadcast(10, string.Format(Config.BroadcastMessages, itemnum, ragdollnum), 0, true); }); - yield return Timing.WaitForSeconds(config.Cleaning_interval); + yield return Timing.WaitForSeconds(Config.CleaningInterval); } } } diff --git a/Server Maid/Plugin.cs b/Server Maid/Plugin.cs index 3bed75e..bff6efa 100644 --- a/Server Maid/Plugin.cs +++ b/Server Maid/Plugin.cs @@ -7,13 +7,13 @@ public class Plugin : Plugin { public override string Name { get; } = "Server Maid / 服务器女仆"; public override string Author { get; } = "XingYeNotFish"; - public override Version Version { get; } = new Version(1, 0, 0); + public override Version Version { get; } = new Version(1, 0, 1); - private static readonly Lazy LazyInstance = new Lazy(() => new Plugin()); - public static Plugin Instance => LazyInstance.Value; + public static Plugin Instance; public override void OnEnabled() { + Instance = this; base.OnEnabled(); Exiled.Events.Handlers.Server.RoundStarted += Maid.Start; Exiled.Events.Handlers.Server.RoundEnded += Maid.End; @@ -22,6 +22,7 @@ public override void OnEnabled() public override void OnDisabled() { + Instance = null; base.OnDisabled(); Exiled.Events.Handlers.Server.RoundStarted -= Maid.Start; Exiled.Events.Handlers.Server.RoundEnded += Maid.End; diff --git a/Server Maid/Server Maid.csproj b/Server Maid/Server Maid.csproj index f6676ad..5c5eae8 100644 --- a/Server Maid/Server Maid.csproj +++ b/Server Maid/Server Maid.csproj @@ -7,8 +7,8 @@ {6B577E13-73E2-45FB-BAD8-19E93F31F5B6} Library Properties - Auto_Clear - Auto Clear + Server_Maid + Server Maid v4.8 512 true @@ -105,6 +105,8 @@ + + diff --git a/Server Maid/XYlikeconfig.cs b/Server Maid/XYlikeconfig.cs index f8bd937..244f15c 100644 --- a/Server Maid/XYlikeconfig.cs +++ b/Server Maid/XYlikeconfig.cs @@ -3,7 +3,7 @@ namespace Server_Maid { - public sealed class XYlikeconfig : IConfig + public class XYlikeconfig : IConfig { [Description("Do you want to enable the plugin? / 是否开启此插件?")] public bool IsEnabled { get; set; } = true; @@ -11,16 +11,18 @@ public sealed class XYlikeconfig : IConfig public bool Debug { get; set; } = false; [Description("Cleaning module settings / 清理模块设置")] - public bool Is_cleaning_module_enabled { get; set; } = true; + public bool IsCleaningModuleEnabled { get; set; } = true; - public string Cleaning_module_enabled_server_console_messages { get; set; } = "Cleaning module has been enable in this round!"; + public bool IsCleaning0492Ragdolls { get; set; } = false; + + public string CleaningModuleEnabledServerConsoleMessages { get; set; } = "Cleaning module has been enable in this round!"; [Description("Cleaning interval time Unit: seconds/ 清理间隔时间 单位: 秒")] - public float Cleaning_interval { get; set; } = 300; + public float CleaningInterval { get; set; } = 300; [Description("Cleanup ended displaying content {0} represents the number of items cleared {1} is the player's ragdolls/ 清理结束显示内容 {0} 代表清理的物品数量 {1}为玩家尸体")] - public string Server_console_messages { get; set; } = "[Server Maid]Cleanup successful! Cleaning {0} items and {1} ragdolls this time!"; + public string ServerConsoleMessages { get; set; } = "Cleanup successful! Cleaning {0} items and {1} ragdolls this time!"; - public string Broadcast_messages { get; set; } = "[Server Maid]Cleanup successful! Cleaning {0} items and {1} ragdolls this time!"; + public string BroadcastMessages { get; set; } = "[Server Maid]Cleanup successful! Cleaning {0} items and {1} ragdolls this time!"; } } \ No newline at end of file