Skip to content

Commit

Permalink
Merge pull request #269 from MrDave1999/feat/command-not-found-message
Browse files Browse the repository at this point in the history
feat: send custom error message when player enters an unknown command
  • Loading branch information
MrDave1999 authored Dec 28, 2024
2 parents deeec0f + 34cae15 commit 72eed1e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="SampSharp.Entities" Version="0.10.1" />
<PackageVersion Include="SampSharp.Streamer.Entities" Version="0.10.0" />
<PackageVersion Include="SampSharp.CTF.Entities" Version="0.10.10" />
<PackageVersion Include="SampSharp.CTF.Entities" Version="0.10.11" />
<PackageVersion Include="SampSharp.CTF.Streamer.Entities" Version="0.10.1" />
<PackageVersion Include="SmartFormat" Version="3.5.1" />
<PackageVersion Include="MySqlConnector" Version="2.3.7" />
Expand Down
9 changes: 9 additions & 0 deletions src/Application/Common/Resources/Messages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Application/Common/Resources/Messages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<data name="CommandLockMapLoading" xml:space="preserve">
<value>You cannot execute commands while the map is loading</value>
</data>
<data name="CommandNotFound" xml:space="preserve">
<value>Command not found. To see all available commands, use /cmds</value>
</data>
<data name="ConsecutiveKills" xml:space="preserve">
<value>{PlayerName} has had {Kills} consecutive kills without dying</value>
</data>
Expand Down
30 changes: 30 additions & 0 deletions src/Application/Players/PlayerCommandTextSystem.cs
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;
}
}

0 comments on commit 72eed1e

Please sign in to comment.