Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using CommandSystem;
using CommandSystem.Commands.RemoteAdmin;
using LabApi.Features.Wrappers;
using StatsSystem.Extensions;
using EventHandler = StatsSystem.Events.EventHandler;

namespace StatsSystem.Commands;

[CommandHandler(typeof(ClientCommandHandler))]
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class GetStat : ICommand
{
public string Command => "getstat";

public string[] Aliases { get; } = ["gs"];

public string Description => "Prints your stats.";
public string Description => "Prints a player's statistics.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Expand All @@ -26,7 +28,19 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}

var player = Player.Get(sender);


if (arguments.Count > 0)
{
var arg = arguments.At(0);
var targetPlayer = Player.Get(arg) ?? Player.GetByDisplayName(arg) ?? Player.GetByNickname(arg);
if (targetPlayer == null)
{
response = $"Target player '{arg}' not found.";
return false;
}
player = targetPlayer;
}

if (player == null)
{
response = "Player not found.";
Expand All @@ -36,7 +50,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
var stats = player.GetOrCreatePlayerStats();
if (stats == null)
{
response = "Your stats could not be found or created.";
response = "The player's stats could not be found or created.";
return false;
}

Expand All @@ -47,7 +61,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
EventHandler.PlayerJoinTimes[player.UserId] = DateTime.Now;
}

var statLines = new List<string> { "Basic stats:" };
var statLines = new List<string> { $"{player.Nickname}'s Stats:\nBasic stats:" };

statLines.AddRange(stats.Counters.OrderBy(k => k.Key).Select(kvp => $"- {kvp.Key}: {kvp.Value}"));
statLines.AddRange(stats.Durations.OrderBy(k => k.Key).Select(kvp => $"- {kvp.Key}: {FormatTime(kvp.Value)}"));
Expand Down
2 changes: 1 addition & 1 deletion StatsSystem/StatsSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="API\StatsSystem.cs"/>
<Compile Include="Commands\GetMyStat.cs"/>
<Compile Include="Commands\GetStat.cs" />
<Compile Include="Config.cs"/>
<Compile Include="Events\EventHandler.cs"/>
<Compile Include="Extensions\JsonExtension.cs"/>
Expand Down
2 changes: 1 addition & 1 deletion StatsSystem/StatsSystemPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class StatsSystemPlugin : Plugin<Config>
public override string Name => "StatsSystem";
public override string Description => "StatSystem";
public override string Author => "MedveMarci";
public override Version Version { get; } = new(1, 1, 3);
public override Version Version { get; } = new(1, 1, 4);
public override Version RequiredApiVersion => new(LabApiProperties.CompiledVersion);
public override bool IsTransparent => true;
public string githubRepo = "MedveMarci/StatsSystem";
Expand Down