-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
New two hooks PrePlayerCommand and PostPlayerCommand #2960
Open
AgaSpace
wants to merge
11
commits into
Pryaxis:general-devel
Choose a base branch
from
AgaSpace:commandhooks
base: general-devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ffed36c
Added hooks
AgaSpace 380f823
Added a `Run` overload to `Command`.
AgaSpace 7a3b2e0
Update changelog.md
AgaSpace a656a1c
Added authorship
AgaSpace 1ef96f9
Marked the `PlayerCommand` hook as obsolete.
AgaSpace fb53bb9
Merge branch 'general-devel' into commandhooks
AgaSpace 21422f2
Update TShockAPI/Hooks/PlayerHooks.cs
AgaSpace b40f0e6
Update TShockAPI/Hooks/PlayerHooks.cs
AgaSpace db40d50
Updated the message
AgaSpace 7237193
Made `PostPlayerCommandEventArgs` inherited from `HandledEventArgs`.
AgaSpace 87fabd3
Removed the "obsolete" tag
AgaSpace 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
This file contains 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 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using TShockAPI.DB; | ||
|
@@ -119,6 +120,53 @@ public class PlayerCommandEventArgs : HandledEventArgs | |
public string CommandPrefix { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// EventArgs used for the <see cref="PlayerHooks.PrePlayerCommand"/> event. | ||
/// </summary> | ||
public class PrePlayerCommandEventArgs : HandledEventArgs | ||
{ | ||
/// <summary> | ||
/// The command entered by the player. | ||
/// </summary> | ||
public Command Command { get; } | ||
/// <summary> | ||
/// Command arguments. | ||
/// </summary> | ||
public CommandArgs Arguments { get; set; } | ||
|
||
public PrePlayerCommandEventArgs(Command command, CommandArgs args) | ||
{ | ||
Command = command; | ||
Arguments = args; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// EventArgs used for the <see cref="PlayerHooks.PostPlayerCommand"/> event. | ||
/// </summary> | ||
public class PostPlayerCommandEventArgs | ||
{ | ||
/// <summary> | ||
/// The command entered by the player. | ||
/// </summary> | ||
public Command Command { get; } | ||
/// <summary> | ||
/// Command arguments. | ||
/// </summary> | ||
public CommandArgs Arguments { get; } | ||
/// <summary> | ||
/// Is the command executed. | ||
/// </summary> | ||
public bool Handled { get; } | ||
|
||
public PostPlayerCommandEventArgs(Command command, CommandArgs arguments, bool handled) | ||
{ | ||
Command = command; | ||
Arguments = arguments; | ||
Handled = handled; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// EventArgs used for the <see cref="PlayerHooks.PlayerChat"/> event. | ||
/// </summary> | ||
|
@@ -341,8 +389,29 @@ public static class PlayerHooks | |
/// <summary> | ||
/// Fired by players when using a command. | ||
/// </summary> | ||
[Obsolete("There is an alternative to PlayerHooks.PrePlayerCommand")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The obsolete message says |
||
public static event PlayerCommandD PlayerCommand; | ||
Arthri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// The delegate of the <see cref="PrePlayerCommand"/> event. | ||
/// </summary> | ||
/// <param name="e">The EventArgs for this event.</param> | ||
public delegate void PrePlayerCommandD(PrePlayerCommandEventArgs e); | ||
/// <summary> | ||
/// Fired before the command is run. | ||
AgaSpace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public static event PrePlayerCommandD PrePlayerCommand; | ||
|
||
/// <summary> | ||
/// The delegate of the <see cref="PostPlayerCommand"/> event. | ||
/// </summary> | ||
/// <param name="e">The EventArgs for this event.</param> | ||
public delegate void PostPlayerCommandD(PostPlayerCommandEventArgs e); | ||
/// <summary> | ||
/// Fired after the command is run. | ||
AgaSpace marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// </summary> | ||
public static event PostPlayerCommandD PostPlayerCommand; | ||
|
||
/// <summary> | ||
/// The delegate of the <see cref="PlayerChat"/> event. | ||
/// </summary> | ||
|
@@ -449,6 +518,40 @@ public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdTe | |
return playerCommandEventArgs.Handled; | ||
} | ||
|
||
/// <summary> | ||
/// Fires the <see cref="PrePlayerCommand"/> event. | ||
/// </summary> | ||
/// <param name="cmd">Command to be executed</param> | ||
/// <param name="arguments">Command arguments</param> | ||
/// <returns>True if the event has been handled.</returns> | ||
public static bool OnPrePlayerCommand(Command cmd, ref CommandArgs arguments) | ||
{ | ||
if (PrePlayerCommand == null) | ||
return false; | ||
|
||
PrePlayerCommandEventArgs args = new PrePlayerCommandEventArgs(cmd, arguments); | ||
|
||
PrePlayerCommand(args); | ||
|
||
arguments = args.Arguments; | ||
return args.Handled; | ||
} | ||
|
||
/// <summary> | ||
/// Fires the <see cref="PostPlayerCommand"/> event. | ||
/// </summary> | ||
/// <param name="cmd">Executed command.</param> | ||
/// <param name="arguments">Command arguments.</param> | ||
/// <param name="handled">Is the command executed.</param> | ||
public static void OnPostPlayerCommand(Command cmd, CommandArgs arguments, bool handled) | ||
{ | ||
if (PostPlayerCommand == null) | ||
return; | ||
|
||
PostPlayerCommandEventArgs args = new PostPlayerCommandEventArgs(cmd, arguments, handled); | ||
PostPlayerCommand(args); | ||
} | ||
|
||
/// <summary> | ||
/// Fires the <see cref="PlayerPreLogin"/> event. | ||
/// </summary> | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this class should inherit from
HandledEventArgs
instead of redefiningHandled