-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from MrDave1999/feat/command-not-found-message
feat: send custom error message when player enters an unknown command
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace CTF.Application.Players; | ||
|
||
public class PlayerCommandTextSystem( | ||
IPlayerCommandService playerCommandService, | ||
IServiceProvider serviceProvider) : ISystem | ||
{ | ||
/// <summary> | ||
/// This callback is called when a player enters a command into the client chat window. | ||
/// Commands are anything that start with a forward slash, e.g. /help. | ||
/// </summary> | ||
/// <param name="player"> | ||
/// The player that entered a command. | ||
/// </param> | ||
/// <param name="text"> | ||
/// The command that was entered (including the forward slash). | ||
/// </param> | ||
/// <returns> | ||
/// <c>true</c> if the command was processed, otherwise <c>false</c>; If the command was not found both in | ||
/// filterscripts and in gamemode, the player will be received a message: 'SERVER: Unknown command'. | ||
/// </returns> | ||
[Event] | ||
public bool OnPlayerCommandText(Player player, string text) | ||
{ | ||
bool invokeResult = playerCommandService.Invoke(serviceProvider, player, text); | ||
if (!invokeResult) | ||
player.SendClientMessage(Color.Red, Messages.CommandNotFound); | ||
|
||
return true; | ||
} | ||
} |