Skip to content
This repository has been archived by the owner on Jan 19, 2025. It is now read-only.

Commit

Permalink
Starting Custom Teams
Browse files Browse the repository at this point in the history
  • Loading branch information
xNexusACS committed Sep 13, 2024
1 parent 8e8131d commit 36f8c65
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Exiled.CustomModules/API/Commands/CustomTeams/Parent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// -----------------------------------------------------------------------
// <copyright file="Parent.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.CustomModules.API.Commands.CustomTeams
{
using System;

using CommandSystem;

/// <summary>
/// The main parent command for custom teams.
/// </summary>
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal sealed class Parent : ParentCommand
{
/// <summary>
/// Initializes a new instance of the <see cref="Parent"/> class.
/// </summary>
public Parent()
{
LoadGeneratedCommands();
}

/// <inheritdoc/>
public override string Command { get; } = "teams";

/// <inheritdoc/>
public override string[] Aliases { get; } = { "tms" };

/// <inheritdoc/>
public override string Description { get; } = string.Empty;

/// <inheritdoc/>
public override void LoadGeneratedCommands()
{
RegisterCommand(Spawn.Instance);
}

/// <inheritdoc/>
protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "Invalid subcommand! Available: ";
return false;
}
}
}
84 changes: 84 additions & 0 deletions Exiled.CustomModules/API/Commands/CustomTeams/Spawn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// -----------------------------------------------------------------------
// <copyright file="Spawn.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

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;

/// <summary>
/// The command to spawn a custom team.
/// </summary>
internal sealed class Spawn : ICommand
{
private Spawn()
{
}

/// <summary>
/// Gets the <see cref="Spawn"/> instance.
/// </summary>
public static Spawn Instance { get; } = new();

/// <inheritdoc/>
public string Command { get; } = "spawn";

/// <inheritdoc/>
public string[] Aliases { get; } = { "s" };

/// <inheritdoc/>
public string Description { get; } = "Spawns the specified custom team.";

/// <inheritdoc/>
public bool Execute(ArraySegment<string> 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 <Custom Team ID>";
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;
}
}
}
}

0 comments on commit 36f8c65

Please sign in to comment.