diff --git a/Exiled.CustomModules/API/Commands/CustomTeams/Parent.cs b/Exiled.CustomModules/API/Commands/CustomTeams/Parent.cs new file mode 100644 index 0000000000..f2acbbda93 --- /dev/null +++ b/Exiled.CustomModules/API/Commands/CustomTeams/Parent.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.CustomModules.API.Commands.CustomTeams +{ + using System; + + using CommandSystem; + + /// + /// The main parent command for custom teams. + /// + [CommandHandler(typeof(RemoteAdminCommandHandler))] + [CommandHandler(typeof(GameConsoleCommandHandler))] + internal sealed class Parent : ParentCommand + { + /// + /// Initializes a new instance of the class. + /// + public Parent() + { + LoadGeneratedCommands(); + } + + /// + public override string Command { get; } = "teams"; + + /// + public override string[] Aliases { get; } = { "tms" }; + + /// + public override string Description { get; } = string.Empty; + + /// + public override void LoadGeneratedCommands() + { + RegisterCommand(Spawn.Instance); + } + + /// + protected override bool ExecuteParent(ArraySegment arguments, ICommandSender sender, out string response) + { + response = "Invalid subcommand! Available: "; + return false; + } + } +} \ No newline at end of file diff --git a/Exiled.CustomModules/API/Commands/CustomTeams/Spawn.cs b/Exiled.CustomModules/API/Commands/CustomTeams/Spawn.cs new file mode 100644 index 0000000000..b49113f1a3 --- /dev/null +++ b/Exiled.CustomModules/API/Commands/CustomTeams/Spawn.cs @@ -0,0 +1,84 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Exiled Team. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace Exiled.CustomModules.API.Commands.CustomTeams +{ + using System; + using System.Linq; + + using CommandSystem; + using Exiled.API.Features; + using Exiled.CustomModules.API.Features.CustomRoles; + using Exiled.Permissions.Extensions; + using PlayerRoles; + + /// + /// The command to spawn a custom team. + /// + internal sealed class Spawn : ICommand + { + private Spawn() + { + } + + /// + /// Gets the instance. + /// + public static Spawn Instance { get; } = new(); + + /// + public string Command { get; } = "spawn"; + + /// + public string[] Aliases { get; } = { "s" }; + + /// + public string Description { get; } = "Spawns the specified custom team."; + + /// + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + try + { + if (!sender.CheckPermission("customteams.spawn")) + { + response = "Permission denied, customteams.spawn is required."; + return false; + } + + if (arguments.Count < 1) + { + response = "spawn "; + return false; + } + + if (!CustomTeam.TryGet(arguments.At(0), out CustomTeam team) && (!uint.TryParse(arguments.At(0), out uint id) || !CustomTeam.TryGet(id, out team)) && team is null) + { + response = $"Custom Team {arguments.At(0)} not found!"; + return false; + } + + if (!Player.Get(Team.Dead).Any()) + { + response = "There are no dead players to spawn the custom team."; + return false; + } + + team.Respawn(true); + + response = $"Custom Team {team.Name} has been spawned."; + return true; + } + catch (Exception ex) + { + Log.Error(ex); + response = "An error occurred when executing the command, check server console for more details."; + return false; + } + } + } +} \ No newline at end of file