Skip to content

Commit d6a33f9

Browse files
committed
added true-color coding (same as conssole logs) to command responses
1 parent cde29dd commit d6a33f9

6 files changed

Lines changed: 231 additions & 137 deletions

File tree

LabExtended/Commands/CommandManager.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
using LabExtended.Commands.Attributes;
1111
using LabExtended.Commands.Interfaces;
1212
using LabExtended.Commands.Parameters;
13+
1314
using LabExtended.Commands.Tokens.Parsing;
15+
using LabExtended.Commands.Tokens.Methods;
1416

1517
using LabExtended.API;
16-
using LabExtended.Commands.Tokens.Methods;
1718
using LabExtended.Core;
1819
using LabExtended.Extensions;
1920

@@ -214,7 +215,7 @@ private static void OnCommand(CommandExecutingEventArgs ev)
214215
{
215216
var response = CommandResponseFormatter.FormatLikelyCommands(likelyCommands,
216217
ev.CommandName + " " + string.Join(" ", ev.Arguments));
217-
218+
218219
ev.IsAllowed = false;
219220
ev.WriteError(response, "magenta");
220221

@@ -249,7 +250,7 @@ private static void OnCommand(CommandExecutingEventArgs ev)
249250
if (command.DefaultOverload is null)
250251
{
251252
var response = CommandResponseFormatter.FormatUnknownOverloadFailure(command);
252-
253+
253254
ev.WriteError(response, "red");
254255

255256
ServerEvents.OnCommandExecuted(new(ev.Sender, ev.CommandType, null, ev.Arguments, false, response));
@@ -366,7 +367,7 @@ private static void OnCommand(CommandExecutingEventArgs ev)
366367
ApiLog.Error("Command Manager", $"An error occured while executing command:\n{ex.ToColoredString()}");
367368

368369
ev.IsAllowed = false;
369-
ev.Sender.Respond(ex.Message, false);
370+
ev.Sender.Respond(ex.ToString(), false);
370371

371372
ServerEvents.OnCommandExecuted(new(ev.Sender, ev.CommandType, ev.Command, ev.Arguments, false, ex.Message));
372373
}

LabExtended/Commands/Custom/Attachments/AttachmentsCommand.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,8 @@ public void Clear(ushort firearmSerial)
6363
/// </summary>
6464
[CommandOverload("disable", "Disables a list of attachments on a firearm.", null)]
6565
public void Disable(
66-
[CommandParameter(Name = "Serial", Description = "The serial number of the firearm.")]
67-
ushort firearmSerial,
68-
69-
[CommandParameter(Name = "Attachments", Description = "List of attachments to disable.")]
70-
List<AttachmentName> attachments)
66+
[CommandParameter(Name = "Serial", Description = "The serial number of the firearm.")] ushort firearmSerial,
67+
[CommandParameter(Name = "Attachments", Description = "List of attachments to disable.")] List<AttachmentName> attachments)
7168
{
7269
if (!InventoryExtensions.ServerTryGetItemWithSerial(firearmSerial, out var item)
7370
|| item is not Firearm firearm || firearm == null)

LabExtended/Commands/Custom/CustomAmmo/CustomAmmoCommand.cs

Lines changed: 37 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using LabExtended.Commands.Attributes;
44
using LabExtended.Commands.Interfaces;
5+
using LabExtended.Commands.Utilities;
56

67
namespace LabExtended.Commands.Custom.CustomAmmo;
78

@@ -15,89 +16,65 @@ namespace LabExtended.Commands.Custom.CustomAmmo;
1516
[Command("customammo", "Custom Ammo management.", "cammo")]
1617
public class CustomAmmoCommand : CommandBase, IServerSideCommand
1718
{
18-
/// <summary>
19-
/// Displays the amount of custom ammo of a specified type in a player's inventory.
20-
/// </summary>
21-
/// <param name="ammoId">The identifier of the custom ammo type to query. Cannot be null or empty.</param>
22-
/// <param name="target">The player whose inventory will be checked. If null, the command sender is used.</param>
2319
[CommandOverload("get", "Gets the amount of custom ammo in a player's inventory.", null)]
24-
public void GetCommand(
20+
private void GetCommand(
2521
[CommandParameter("ID", "ID of the ammo.")] string ammoId,
26-
[CommandParameter("Target", "The target player.")] ExPlayer? target = null)
22+
[CommandParameter("Targets", "The target players.")] List<ExPlayer> players)
2723
{
28-
var player = target ?? Sender;
29-
var amount = player.Ammo.GetCustomAmmo(ammoId);
30-
31-
Ok($"Player \"{player.Nickname}\" ({player.ClearUserId}) has \"{amount}\" of ammo \"{ammoId}\".");
24+
this.ForEachExecute(players, player =>
25+
{
26+
var amount = player.Ammo.GetCustomAmmo(ammoId);
27+
return $"&6{ammoId}x&r of &6{ammoId}&r";
28+
});
3229
}
3330

34-
/// <summary>
35-
/// Sets the specified amount of custom ammunition for a player.
36-
/// </summary>
37-
/// <param name="ammoId">The identifier of the custom ammo type to set. Cannot be null or empty.</param>
38-
/// <param name="amount">The amount of ammo to set. Must be zero or greater.</param>
39-
/// <param name="target">The player whose ammo will be set. If null, the command sender is used.</param>
4031
[CommandOverload("set", "Sets a specific amount of custom ammo in a player's inventory.", null)]
41-
public void SetCommand(
32+
private void SetCommand(
4233
[CommandParameter("ID", "ID of the ammo.")] string ammoId,
4334
[CommandParameter("Amount", "Amount to set.")] int amount,
44-
[CommandParameter("Target", "The target player.")] ExPlayer? target = null)
35+
[CommandParameter("Targets", "The target players.")] List<ExPlayer> players)
4536
{
46-
var player = target ?? Sender;
47-
48-
player.Ammo.SetCustomAmmo(ammoId, amount);
49-
50-
Ok($"Set ammo \"{ammoId}\" of player \"{player.Nickname}\" ({player.ClearUserId}) to \"{amount}\".");
37+
this.ForEachExecute(players, player =>
38+
{
39+
player.Ammo.SetCustomAmmo(ammoId, amount);
40+
return $"&3{ammoId}&r set to &3{amount}&r";
41+
});
5142
}
5243

53-
/// <summary>
54-
/// Adds a specified amount of custom ammo to a player's inventory.
55-
/// </summary>
56-
/// <param name="ammoId">The identifier of the custom ammo type to add. Cannot be null or empty.</param>
57-
/// <param name="amount">The number of ammo units to add. Must be greater than zero.</param>
58-
/// <param name="target">The player who will receive the ammo. If null, the command sender is used.</param>
5944
[CommandOverload("add", "Adds a specific amount of custom ammo to a player's inventory.", null)]
60-
public void AddCommand(
45+
private void AddCommand(
6146
[CommandParameter("ID", "ID of the ammo.")] string ammoId,
6247
[CommandParameter("Amount", "Amount to add.")] int amount,
63-
[CommandParameter("Target", "The target player.")] ExPlayer? target = null)
48+
[CommandParameter("Targets", "The target players.")] List<ExPlayer> players)
6449
{
65-
var player = target ?? Sender;
66-
var current = player.Ammo.AddCustomAmmo(ammoId, amount);
67-
68-
Ok($"Added \"{amount}\" of ammo \"{ammoId}\" to player \"{player.Nickname}\" ({player.ClearUserId}), new amount: \"{current}\".");
50+
this.ForEachExecute(players, player =>
51+
{
52+
var newAmmo = player.Ammo.AddCustomAmmo(ammoId, amount);
53+
return $"added &3{amount}&r of &3{ammoId}&r, now: &3{newAmmo}&r";
54+
});
6955
}
7056

71-
/// <summary>
72-
/// Removes a specified amount of custom ammunition from a player's inventory.
73-
/// </summary>
74-
/// <param name="ammoId">The identifier of the custom ammo type to remove. Cannot be null or empty.</param>
75-
/// <param name="amount">The number of ammo units to remove. Must be greater than zero.</param>
76-
/// <param name="target">The player from whose inventory the ammo will be removed. If null, the command sender is used.</param>
77-
[CommandOverload("Remove", "Removes a specific amount of custom ammo from a player's inventory.", null)]
78-
public void RemoveCommand(
57+
[CommandOverload("remove", "Removes a specific amount of custom ammo from a player's inventory.", null)]
58+
private void RemoveCommand(
7959
[CommandParameter("ID", "ID of the ammo.")] string ammoId,
8060
[CommandParameter("Amount", "Amount to remove.")] int amount,
81-
[CommandParameter("Target", "The target player.")] ExPlayer? target = null)
61+
[CommandParameter("Targets", "The target players.")] List<ExPlayer> players)
8262
{
83-
var player = target ?? Sender;
84-
var current = player.Ammo.RemoveCustomAmmo(ammoId, amount);
85-
86-
Ok($"Removed \"{amount}\" of ammo \"{ammoId}\" from player \"{player.Nickname}\" ({player.ClearUserId}), new amount: \"{current}\".");
63+
this.ForEachExecute(players, player =>
64+
{
65+
var newAmmo = player.Ammo.RemoveCustomAmmo(ammoId, amount);
66+
return $"removed &3{amount}&r of &3{ammoId}&r, now: &3{newAmmo}&r";
67+
});
8768
}
8869

89-
/// <summary>
90-
/// Removes all custom ammo from the specified player's inventory.
91-
/// </summary>
92-
/// <param name="target">The player whose custom ammo inventory will be cleared. If null, the command sender's inventory is cleared.</param>
9370
[CommandOverload("clear", "Removes all custom ammo from a player's inventory.", null)]
94-
public void ClearCommand(
95-
[CommandParameter("Target", "The target player.")] ExPlayer? target = null)
71+
private void ClearCommand(
72+
[CommandParameter("Targets", "The target players.")] List<ExPlayer> players)
9673
{
97-
var player = target ?? Sender;
98-
99-
player.Ammo.ClearCustomAmmo();
100-
101-
Ok($"Cleared Custom Ammo inventory of \"{player.Nickname}\" ({player.ClearUserId}).");
74+
this.ForEachExecute(players, player =>
75+
{
76+
player.Ammo.ClearCustomAmmo();
77+
return "&6all custom ammo cleared&r";
78+
});
10279
}
10380
}

0 commit comments

Comments
 (0)