Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions AdminTools/Commands/Jail.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommandSystem;
using CommandSystem;
using Exiled.API.Enums;
using Exiled.API.Extensions;
using Exiled.API.Features;
Expand All @@ -20,7 +20,18 @@ public class Jail : ICommand, IUsageProvider

public string Description { get; } = "Jails or unjails a user";

public string[] Usage { get; } = new string[] { "%player%", "[IsJail]"};
public string[] Usage { get; } = new string[] { "%player%", "[IsJail]" };

public Jail()
{
// Check if the command already exists in the RemoteAdminCommandHandler
var existing = CommandHandler.Base.Commands.FirstOrDefault(x => x.Name.Equals(Command, StringComparison.OrdinalIgnoreCase));
if (existing != null)
{
Log.Warn($"Jail command already exists as '{existing.Name}', skipping registration.");
throw new InvalidOperationException("Jail command already registered."); // prevents double registration
}
}

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Expand All @@ -42,14 +53,13 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
response = $"Player not found: {arguments.At(0)}";
return false;
}

bool? isJail = null;
if (bool.TryParse(arguments.ElementAtOrDefault(1), out bool result))
isJail = result;

foreach (Player ply in players)
{

if (isJail is true)
DoJail(ply);
else if (isJail is false)
Expand All @@ -65,6 +75,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
response = $"Jail command has run successfully.\n{Extensions.LogPlayers(players)}";
return true;
}

public static void DoJail(Player player, bool skipadd = false)
{
if (Main.JailedPlayers.ContainsKey(player.UserId))
Expand Down