Skip to content

Commit

Permalink
V1.0.1 update
Browse files Browse the repository at this point in the history
  • Loading branch information
XingYeNotFish authored Jul 29, 2024
1 parent a9bcca9 commit 35cd0ff
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 20 deletions.
186 changes: 186 additions & 0 deletions Server Maid/Command.cs
Original file line number Diff line number Diff line change
@@ -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<string> arguments, ICommandSender sender,
out string response)
{
var playerSender = Player.Get(sender);
if (playerSender == null)
{
response = "Players don't exist!";
return false;
}
response = "<b><color=yellow>stopclean</color>\n\nDeactivate servermaid for this round.\n<color=yellow>restartclean</color>\n\nRe-enable servermaid for this round.\n<color=yellow>forceclean</color>\n\nImmediate implementation of a clean.</b>";
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<string> 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, $"<b><size=25>[<color=#EEEE00>Server Maid</color>]Admin <color=#54FF9F>{p.Nickname}</color> has turned off auto-cleanup for this round</size></b>");
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<string> 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, $"<b><size=25>[<color=#EEEE00>Server Maid</color>]Admin <color=#54FF9F>{p.Nickname}</color> has restart auto-cleanup for this round</size></b>");
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<string> 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, $"<b><size=25>[<color=#EEEE00>Server Maid</color>]Admin <color=#54FF9F>{p.Nickname}</color> has run forceclean command. \nCleaning {itemnum} items and {ragdollnum} ragdolls this time!</size></b>");
response = "Success!";
return true;
}
}
}
9 changes: 9 additions & 0 deletions Server Maid/CommandTranslations.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
26 changes: 17 additions & 9 deletions Server Maid/Maid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -32,14 +33,21 @@ public static void End(RoundEndedEventArgs e)
public static IEnumerator<float> MaidSystem()
{

yield return Timing.WaitForSeconds(config.Cleaning_interval);
yield return Timing.WaitForSeconds(Config.CleaningInterval);
for (; ; )
{
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;
Expand All @@ -56,14 +64,14 @@ public static IEnumerator<float> 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);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions Server Maid/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ public class Plugin : Plugin<XYlikeconfig>
{
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<Plugin> LazyInstance = new Lazy<Plugin>(() => 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;
Expand All @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions Server Maid/Server Maid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{6B577E13-73E2-45FB-BAD8-19E93F31F5B6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Auto_Clear</RootNamespace>
<AssemblyName>Auto Clear</AssemblyName>
<RootNamespace>Server_Maid</RootNamespace>
<AssemblyName>Server Maid</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -105,6 +105,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Command.cs" />
<Compile Include="CommandTranslations.cs" />
<Compile Include="Maid.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
14 changes: 8 additions & 6 deletions Server Maid/XYlikeconfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@

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;

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; } = "[<color=#EEEE00>Server Maid</color>]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; } = "[<color=#EEEE00>Server Maid</color>]Cleanup successful! Cleaning {0} items and {1} ragdolls this time!";
public string BroadcastMessages { get; set; } = "<b><size=25>[<color=#EEEE00>Server Maid</color>]Cleanup successful! Cleaning {0} items and {1} ragdolls this time!</size></b>";
}
}

0 comments on commit 35cd0ff

Please sign in to comment.