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

Commit

Permalink
Renamed Spawned event to ChangedRole event (#2778)
Browse files Browse the repository at this point in the history
* Renamed Spawned event to ChangedRole event

* fix file header.
Monaldcry7788 authored Aug 31, 2024

Verified

This commit was signed with the committer’s verified signature.
mp911de Mark Paluch
1 parent de89528 commit e0385b2
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="SpawnedEventArgs.cs" company="Exiled Team">
// <copyright file="ChangedRoleEventArgs.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
@@ -16,16 +16,16 @@ namespace Exiled.Events.EventArgs.Player
using PlayerRoles;

/// <summary>
/// Contains all information after spawning a player.
/// Contains all information after changed a player's role.
/// </summary>
public class SpawnedEventArgs : IPlayerEvent
public class ChangedRoleEventArgs : IPlayerEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="SpawnedEventArgs" /> class.
/// Initializes a new instance of the <see cref="ChangedRoleEventArgs" /> class.
/// </summary>
/// <param name="player">the spawned player.</param>
/// <param name="oldRole">the spawned player's old <see cref="PlayerRoleBase">role</see>.</param>
public SpawnedEventArgs(Player player, PlayerRoleBase oldRole)
public ChangedRoleEventArgs(Player player, PlayerRoleBase oldRole)
{
Player = player;
OldRole = Role.Create(oldRole);
10 changes: 5 additions & 5 deletions Exiled.Events/Handlers/Player.cs
Original file line number Diff line number Diff line change
@@ -294,9 +294,9 @@ public class Player
public static Event<SpawningEventArgs> Spawning { get; set; } = new();

/// <summary>
/// Invoked after a <see cref="API.Features.Player"/> has spawned.
/// Invoked after a <see cref="API.Features.Player"/> has changed role.
/// </summary>
public static Event<SpawnedEventArgs> Spawned { get; set; } = new();
public static Event<ChangedRoleEventArgs> ChangedRole { get; set; } = new();

/// <summary>
/// Invoked after a <see cref="API.Features.Player"/> held <see cref="API.Features.Items.Item"/> changes.
@@ -823,10 +823,10 @@ public class Player
public static void OnSpawning(SpawningEventArgs ev) => Spawning.InvokeSafely(ev);

/// <summary>
/// Called after a <see cref="API.Features.Player"/> has spawned.
/// Called after a <see cref="API.Features.Player"/> has changed role.
/// </summary>
/// <param name="ev">The <see cref="SpawnedEventArgs"/> instance.</param>
public static void OnSpawned(SpawnedEventArgs ev) => Spawned.InvokeSafely(ev);
/// <param name="ev">The <see cref="ChangedRoleEventArgs"/> instance.</param>
public static void OnChangedRole(ChangedRoleEventArgs ev) => ChangedRole.InvokeSafely(ev);

/// <summary>
/// Called after a <see cref="API.Features.Player"/> held item changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="ChangingRoleAndSpawned.cs" company="Exiled Team">
// <copyright file="ChangingRoleAndChangedRole.cs" company="Exiled Team">
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
@@ -36,7 +36,7 @@ namespace Exiled.Events.Patches.Events.Player
/// Adds the <see cref="Player.ChangingRole" /> event.
/// </summary>
[HarmonyPatch(typeof(PlayerRoleManager), nameof(PlayerRoleManager.InitializeNewRole))]
internal static class ChangingRoleAndSpawned
internal static class ChangingRoleAndChangedRole
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
@@ -126,7 +126,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingRoleEventArgs), nameof(ChangingRoleEventArgs.NewRole))),
new(OpCodes.Ldloc_S, changingRoleEventArgs.LocalIndex),
new(OpCodes.Callvirt, PropertyGetter(typeof(ChangingRoleEventArgs), nameof(ChangingRoleEventArgs.Player))),
new(OpCodes.Call, Method(typeof(ChangingRoleAndSpawned), nameof(UpdatePlayerRole))),
new(OpCodes.Call, Method(typeof(ChangingRoleAndChangedRole), nameof(UpdatePlayerRole))),

new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel),
});
@@ -176,7 +176,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Ldloc_S, changingRoleEventArgs.LocalIndex),

// ChangingRole.ChangeInventory(changingRoleEventArgs, oldRoleType);
new(OpCodes.Call, Method(typeof(ChangingRoleAndSpawned), nameof(ChangeInventory))),
new(OpCodes.Call, Method(typeof(ChangingRoleAndChangedRole), nameof(ChangeInventory))),
});

newInstructions.InsertRange(
@@ -194,11 +194,11 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
// OldRole
new(OpCodes.Ldloc_0),

// SpawnedEventArgs spawnedEventArgs = new(Player, OldRole)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(SpawnedEventArgs))[0]),
// ChangedRoleEventArgs changedRoleEventArgs = new(Player, OldRole)
new(OpCodes.Newobj, GetDeclaredConstructors(typeof(ChangedRoleEventArgs))[0]),

// Handlers.Player.OnSpawned(spawnedEventArgs)
new(OpCodes.Call, Method(typeof(Player), nameof(Player.OnSpawned))),
// Handlers.Player.OnChangedRole(changedRoleEventArgs)
new(OpCodes.Call, Method(typeof(Player), nameof(Player.OnChangedRole))),
});

newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
@@ -277,7 +277,7 @@ private static void ChangeInventory(ChangingRoleEventArgs ev)
}
catch (Exception exception)
{
Log.Error($"{nameof(ChangingRoleAndSpawned)}.{nameof(ChangeInventory)}: {exception}");
Log.Error($"{nameof(ChangingRoleAndChangedRole)}.{nameof(ChangeInventory)}: {exception}");
}
}
}

0 comments on commit e0385b2

Please sign in to comment.