Skip to content
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

[Exiled::Events] Command execution events #44

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions EXILED/Exiled.Events/EventArgs/Server/ExecutedCommandEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="ExecutedCommandEventArgs.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 CommandSystem;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;

/// <summary>
/// Contains all information after command being executed.
/// </summary>
public class ExecutedCommandEventArgs : IPlayerEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ExecutedCommandEventArgs"/> class.
/// </summary>
/// <param name="player"><inheritdoc cref="Player"/></param>
/// <param name="command"><inheritdoc cref="Command"/></param>
/// <param name="arguments"><inheritdoc cref="Arguments"/></param>">
/// <param name="response"><inheritdoc cref="Response"/></param>
public ExecutedCommandEventArgs(Player player, ICommand command, IEnumerable<string> arguments, string response)
{
Player = player;
Command = command;
Response = response;
Arguments = arguments;
}

/// <inheritdoc/>
public Player Player { get; }

/// <summary>
/// Gets the executed command.
/// </summary>
public ICommand Command { get; }

/// <summary>
/// Gets the arguments of the executed command.
/// </summary>
public IEnumerable<string> Arguments { get; }

/// <summary>
/// Gets the response of the executed command.
/// </summary>
public string Response { get; }
}
}
54 changes: 54 additions & 0 deletions EXILED/Exiled.Events/EventArgs/Server/ExecutingCommandEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -----------------------------------------------------------------------
// <copyright file="ExecutingCommandEventArgs.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;
using System.Collections.Generic;

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

/// <summary>
/// Contains all information before command being executed.
/// </summary>
public class ExecutingCommandEventArgs : IPlayerEvent, IDeniableEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="ExecutingCommandEventArgs"/> class.
/// </summary>
/// <param name="player"><inheritdoc cref="Player"/></param>
/// <param name="command"><inheritdoc cref="Command"/></param>
/// <param name="arguments"><inheritdoc cref="Arguments"/></param>
/// <param name="isAllowed"><inheritdoc cref="IsAllowed"/></param>
public ExecutingCommandEventArgs(Player player, ICommand command, ArraySegment<string> arguments, bool isAllowed = true)
{
Player = player;
Command = command;
Arguments = arguments;
IsAllowed = isAllowed;
}

/// <inheritdoc/>
public Player Player { get; }

/// <inheritdoc/>
public bool IsAllowed { get; set; }

/// <summary>
/// Gets a command that is going to be executed.
/// </summary>
/// <remarks>Can be <see langword="null"/>.</remarks>
public ICommand Command { get; internal set; }

/// <summary>
/// Gets a collection of arguments for this command.
/// </summary>
public IEnumerable<string> Arguments { get; }
}
}
22 changes: 22 additions & 0 deletions EXILED/Exiled.Events/Handlers/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public static class Server
/// </summary>
public static Event ReloadedPermissions { get; set; } = new();

/// <summary>
/// Invoked before command being executed.
/// </summary>
public static Event<ExecutingCommandEventArgs> ExecutingCommand { get; set; } = new();

/// <summary>
/// Invoked after command being executed.
/// </summary>
public static Event<ExecutedCommandEventArgs> ExecutedCommand { get; set; } = new();

/// <summary>
/// Invoked before player is being unbanned.
/// </summary>
Expand Down Expand Up @@ -221,6 +231,18 @@ public static class Server
/// <param name="ev">The <see cref="SelectingRespawnTeamEventArgs"/> instance.</param>
public static void OnSelectingRespawnTeam(SelectingRespawnTeamEventArgs ev) => SelectingRespawnTeam.InvokeSafely(ev);

/// <summary>
/// Called before command being executed.
/// </summary>
/// <param name="ev">The <see cref="ExecutingCommandEventArgs"/> instance.</param>
public static void OnExecutingCommand(ExecutingCommandEventArgs ev) => ExecutingCommand.InvokeSafely(ev);

/// <summary>
/// Called after command being executed.
/// </summary>
/// <param name="ev">The <see cref="ExecutedCommandEventArgs"/> instance.</param>
public static void OnExecutedCommand(ExecutedCommandEventArgs ev) => ExecutedCommand.InvokeSafely(ev);

/// <summary>
/// Called before player is being unbanned.
/// </summary>
Expand Down
Loading
Loading