2025-07-03 22:05:38 +02:00

66 lines
3.1 KiB
C#

using CommandSystem;
using LabApi.Features.Wrappers;
namespace CustomClasses;
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class SetCClassCommand : ICommand
{
public string Command => "setcclass";
public string[] Aliases => ["scc"];
public string Description => "Forces a player to become a specific custom class";
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
var args = arguments.Array!;
if (arguments.Count < 2)
{
response = "Usage: setcclass <playerName> <className>";
return false;
}
// Find the last argument as the class name
var className = args[arguments.Offset + arguments.Count - 1].ToLower();
// Join all arguments except the last one to get the full player name
var playerName = string.Join(" ", args.Skip(arguments.Offset).Take(arguments.Count - 1));
var player = Player.ReadyList.FirstOrDefault(x => x.Nickname == playerName || x.UserId == playerName);
if (player == null)
{
response = $"Player {playerName} not found";
return false;
}
var customClasses = CustomClasses.Instance;
var manager = new CustomClassManager();
var success = className switch
{
"janitor" => manager.ForceSpawn(player, customClasses.JanitorConfig, typeof(JanitorConfig), null),
"subject" or "researchsubject" => manager.ForceSpawn(player, customClasses.ResearchSubjectConfig, typeof(ResearchSubjectConfig), null),
"headguard" => manager.ForceSpawn(player, customClasses.HeadGuardConfig, typeof(HeadGuardConfig), null),
"medic" => manager.ForceSpawn(player, customClasses.MedicConfig, typeof(MedicConfig), null),
"gambler" => manager.ForceSpawn(player, customClasses.GamblerConfig, typeof(GamblerConfig), null),
"shadowstepper" => manager.ForceSpawn(player, customClasses.ShadowStepperConfig, typeof(ShadowStepperConfig), null),
"demolitionist" => manager.ForceSpawn(player, customClasses.MtfDemolitionistConfig, typeof(MtfDemolitionistConfig), null),
"scout" => manager.ForceSpawn(player, customClasses.ScoutConfig, typeof(ScoutConfig), null),
"explosivemaster" => manager.ForceSpawn(player, customClasses.ExplosiveMasterConfig, typeof(ExplosiveMasterConfig), null),
"flashmaster" => manager.ForceSpawn(player, customClasses.FlashMasterConfig, typeof(FlashMasterConfig), null),
"serpentshand" => manager.ForceSpawn(player, customClasses.SerpentsHandConfig, typeof(SerpentsHandConfig),
() =>
{
SerpentsHandManager.PreSpawn(player);
}),
_ => false
};
if (!success)
{
response = $"Failed to set {playerName} to {className}. Make sure the player has the correct base role for the custom class.";
return false;
}
response = $"Successfully set {playerName} to {className}";
return true;
}
}