Skip to content

Commit

Permalink
Porting EXILED9 RespawnedTeam event. by.VALERA771 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
YongAn404 authored Aug 2, 2024
1 parent 5a519a4 commit 81c3652
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
43 changes: 43 additions & 0 deletions EXILED/Exiled.Events/EventArgs/Server/RespawnedTeamEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// -----------------------------------------------------------------------
// <copyright file="RespawnedTeamEventArgs.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.EventArgs.Server
{
using System.Collections.Generic;
using System.Linq;

using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;
using Respawning;

/// <summary>
/// Contains all information after team spawns.
/// </summary>
public class RespawnedTeamEventArgs : IExiledEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="RespawnedTeamEventArgs"/> class.
/// </summary>
/// <param name="hubs"><inheritdoc cref="Players"/></param>
/// <param name="team"><inheritdoc cref="Team"/></param>
public RespawnedTeamEventArgs(SpawnableTeamType team, IEnumerable<ReferenceHub> hubs)
{
Players = hubs.Select(Player.Get);
Team = team;
}

/// <summary>
/// Gets the list of spawned players.
/// </summary>
public IEnumerable<Player> Players { get; }

/// <summary>
/// Gets the spawned team.
/// </summary>
public SpawnableTeamType Team { get; }
}
}
5 changes: 3 additions & 2 deletions EXILED/Exiled.Events/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Exiled.Events
using PlayerRoles.Ragdolls;
using PlayerRoles.RoleAssign;
using PluginAPI.Events;
using Respawning;
using UnityEngine.SceneManagement;

/// <summary>
Expand Down Expand Up @@ -70,7 +71,7 @@ public override void OnEnabled()
Handlers.Map.ChangedIntoGrenade += Handlers.Internal.ExplodingGrenade.OnChangedIntoGrenade;

CharacterClassManager.OnRoundStarted += Handlers.Server.OnRoundStarted;

RespawnManager.ServerOnRespawned += Handlers.Server.OnRespawnedTeam;
InventorySystem.InventoryExtensions.OnItemAdded += Handlers.Player.OnItemAdded;
InventorySystem.InventoryExtensions.OnItemRemoved += Handlers.Player.OnItemRemoved;

Expand Down Expand Up @@ -105,7 +106,7 @@ public override void OnDisabled()

InventorySystem.InventoryExtensions.OnItemAdded -= Handlers.Player.OnItemAdded;
InventorySystem.InventoryExtensions.OnItemRemoved -= Handlers.Player.OnItemRemoved;

RespawnManager.ServerOnRespawned -= Handlers.Server.OnRespawnedTeam;
RagdollManager.OnRagdollSpawned -= Handlers.Internal.RagdollList.OnSpawnedRagdoll;
RagdollManager.OnRagdollRemoved -= Handlers.Internal.RagdollList.OnRemovedRagdoll;
ItemPickupBase.OnPickupAdded -= Handlers.Internal.PickupEvent.OnSpawnedPickup;
Expand Down
15 changes: 15 additions & 0 deletions EXILED/Exiled.Events/Handlers/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace Exiled.Events.Handlers
{
using System.Collections.Generic;

using Respawning;
#pragma warning disable SA1623 // Property summary documentation should match accessors

using Exiled.Events.EventArgs.Player;
Expand Down Expand Up @@ -53,6 +56,11 @@ public static class Server
/// </summary>
public static Event<RespawningTeamEventArgs> RespawningTeam { get; set; } = new();

/// <summary>
/// Invoked after team spawns.
/// </summary>
public static Event<RespawnedTeamEventArgs> RespawnedTeam { get; set; } = new();

/// <summary>
/// Invoked before adding an unit name.
/// </summary>
Expand Down Expand Up @@ -142,6 +150,13 @@ public static class Server
/// <param name="ev">The <see cref="RespawningTeamEventArgs"/> instance.</param>
public static void OnRespawningTeam(RespawningTeamEventArgs ev) => RespawningTeam.InvokeSafely(ev);

/// <summary>
/// Called after team spawns.
/// </summary>
/// <param name="teamType"><inheritdoc cref="RespawnedTeamEventArgs.Team"/></param>
/// <param name="hubs"><inheritdoc cref="RespawnedTeamEventArgs.Players"/></param>
public static void OnRespawnedTeam(SpawnableTeamType teamType, List<ReferenceHub> hubs) => RespawnedTeam.InvokeSafely(new RespawnedTeamEventArgs(teamType, hubs));

/// <summary>
/// Called before adding an unit name.
/// </summary>
Expand Down

0 comments on commit 81c3652

Please sign in to comment.