forked from Exiled-Official/EXILED
-
Notifications
You must be signed in to change notification settings - Fork 110
[Exiled::Events] Unbanning and Unbanned events
#68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
EXILED/Exiled.Events/EventArgs/Server/UnbannedEventArgs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="UnbannedEventArgs.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 | ||
| { | ||
| /// <summary> | ||
| /// Contains all information after a player gets unbanned. | ||
| /// </summary> | ||
| public class UnbannedEventArgs | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UnbannedEventArgs"/> class. | ||
| /// </summary> | ||
| /// <param name="details"><inheritdoc cref="BanDetails"/></param> | ||
| /// <param name="banType"><inheritdoc cref="BanType"/></param> | ||
| public UnbannedEventArgs(string details, BanHandler.BanType banType) | ||
| { | ||
| BanDetails = BanHandler.ProcessBanItem(details, banType); | ||
| BanType = banType; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the ban details. | ||
| /// </summary> | ||
| public BanDetails BanDetails { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the ban type. | ||
| /// </summary> | ||
| public BanHandler.BanType BanType { get; } | ||
| } | ||
| } |
43 changes: 43 additions & 0 deletions
43
EXILED/Exiled.Events/EventArgs/Server/UnbanningEventArgs.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="UnbanningEventArgs.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 Exiled.Events.EventArgs.Interfaces; | ||
|
|
||
| /// <summary> | ||
| /// Contains all information before player is unbanned. | ||
| /// </summary> | ||
| public class UnbanningEventArgs : IDeniableEvent | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UnbanningEventArgs"/> class. | ||
| /// </summary> | ||
| /// <param name="banDetails"><inheritdoc cref="BanDetails"/></param> | ||
| /// <param name="banType"><inheritdoc cref="BanType"/></param> | ||
| /// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param> | ||
| public UnbanningEventArgs(string banDetails, BanHandler.BanType banType, bool isAllowed = true) | ||
| { | ||
| BanDetails = BanHandler.ProcessBanItem(banDetails, banType); | ||
| BanType = banType; | ||
| IsAllowed = isAllowed; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the ban details. | ||
| /// </summary> | ||
| public BanDetails BanDetails { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the ban type. | ||
| /// </summary> | ||
| public BanHandler.BanType BanType { get; } | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool IsAllowed { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // ----------------------------------------------------------------------- | ||
| // <copyright file="Unban.cs" company="Exiled Team"> | ||
| // Copyright (c) Exiled Team. All rights reserved. | ||
| // Licensed under the CC BY-SA 3.0 license. | ||
| // </copyright> | ||
| // ----------------------------------------------------------------------- | ||
|
|
||
| namespace Exiled.Events.Patches.Events.Server | ||
| { | ||
| using System.Collections.Generic; | ||
| using System.Reflection.Emit; | ||
|
|
||
| using Exiled.API.Features.Pools; | ||
| using Exiled.Events.Attributes; | ||
| using Exiled.Events.EventArgs.Server; | ||
| using HarmonyLib; | ||
|
|
||
| using static HarmonyLib.AccessTools; | ||
|
|
||
| /// <summary> | ||
| /// Patches <see cref="BanHandler.RemoveBan"/> | ||
| /// to add <see cref="Handlers.Server.Unbanning"/> and <see cref="Handlers.Server.Unbanned"/> events. | ||
| /// </summary> | ||
| [HarmonyPatch(typeof(BanHandler), nameof(BanHandler.RemoveBan))] | ||
| [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.Unbanning))] | ||
| [EventPatch(typeof(Handlers.Server), nameof(Handlers.Server.Unbanned))] | ||
| internal class Unban | ||
| { | ||
| private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) | ||
| { | ||
| List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions); | ||
|
|
||
| LocalBuilder ev = generator.DeclareLocal(typeof(UnbanningEventArgs)); | ||
|
|
||
| Label continueLabel = generator.DefineLabel(); | ||
|
|
||
| newInstructions.InsertRange(0, new CodeInstruction[] | ||
| { | ||
| // id | ||
| new(OpCodes.Ldarg_0), | ||
|
|
||
| // type | ||
| new(OpCodes.Ldarg_1), | ||
|
|
||
| // true | ||
| new(OpCodes.Ldc_I4_1), | ||
|
|
||
| // UnbanningEventArgs ev = new(string, BanHandler.BanType, true); | ||
| new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UnbanningEventArgs))[0]), | ||
| new(OpCodes.Dup), | ||
| new(OpCodes.Dup), | ||
| new(OpCodes.Stloc_S, ev.LocalIndex), | ||
|
|
||
| // Handlers.Server.OnUnbanning(ev); | ||
| new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server.OnUnbanning))), | ||
|
|
||
| // if (!ev.IsAllowed) | ||
| // return; | ||
| new(OpCodes.Callvirt, PropertyGetter(typeof(UnbanningEventArgs), nameof(UnbanningEventArgs.IsAllowed))), | ||
| new(OpCodes.Brtrue_S, continueLabel), | ||
|
|
||
| new(OpCodes.Ret), | ||
|
|
||
| // id = ev.BanDetails.ToString(); | ||
| new(OpCodes.Ldloc_S, ev.LocalIndex), | ||
| new(OpCodes.Callvirt, PropertyGetter(typeof(UnbanningEventArgs), nameof(UnbanningEventArgs.BanDetails))), | ||
| new(OpCodes.Call, Method(typeof(BanDetails), nameof(BanDetails.ToString))), | ||
| new(OpCodes.Starg_S, 1), | ||
| }); | ||
|
|
||
| newInstructions.InsertRange(newInstructions.Count - 1, new CodeInstruction[] | ||
| { | ||
| // id | ||
| new(OpCodes.Ldarg_0), | ||
|
|
||
| // type | ||
| new(OpCodes.Ldarg_1), | ||
|
|
||
| // UnbannedEventArgs ev2 = new(string, BanHandler.BanType); | ||
| new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UnbannedEventArgs))[0]), | ||
|
|
||
| // Handlers.Server.OnUnbanned(ev2); | ||
| new(OpCodes.Call, Method(typeof(Handlers.Server), nameof(Handlers.Server.OnUnbanned))), | ||
| }); | ||
|
|
||
| for (int z = 0; z < newInstructions.Count; z++) | ||
| yield return newInstructions[z]; | ||
|
|
||
| ListPool<CodeInstruction>.Pool.Return(newInstructions); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.