2021-11-23 17:26:33 -06:00
|
|
|
|
using System.Linq;
|
2018-02-10 00:26:38 -06:00
|
|
|
|
using System.Threading.Tasks;
|
2018-04-10 01:38:18 -05:00
|
|
|
|
using SharedLibraryCore;
|
2018-05-05 15:36:26 -05:00
|
|
|
|
using System.Collections.Generic;
|
2018-11-27 18:31:48 -06:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
2020-01-31 20:15:07 -06:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2021-11-23 17:26:33 -06:00
|
|
|
|
using EFClient = Data.Models.Client.EFClient;
|
2018-05-05 15:36:26 -05:00
|
|
|
|
|
2018-04-08 16:50:58 -05:00
|
|
|
|
namespace IW4MAdmin.Plugins.Stats.Commands
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
2021-11-23 17:26:33 -06:00
|
|
|
|
public class TopStats : Command
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
2021-03-22 11:09:25 -05:00
|
|
|
|
public static async Task<List<string>> GetTopStats(Server s, ITranslationLookup translationLookup)
|
2018-02-10 00:26:38 -06:00
|
|
|
|
{
|
2021-11-23 17:26:33 -06:00
|
|
|
|
var serverId = StatManager.GetIdForServer(s);
|
2020-01-31 20:15:07 -06:00
|
|
|
|
var topStatsText = new List<string>()
|
2018-05-05 15:36:26 -05:00
|
|
|
|
{
|
2021-11-23 17:26:33 -06:00
|
|
|
|
$"(Color::Accent)--{translationLookup["PLUGINS_STATS_COMMANDS_TOP_TEXT"]}--"
|
2018-05-05 15:36:26 -05:00
|
|
|
|
};
|
2018-02-10 00:26:38 -06:00
|
|
|
|
|
2021-03-22 11:09:25 -05:00
|
|
|
|
var stats = await Plugin.Manager.GetTopStats(0, 5, serverId);
|
2021-11-23 17:26:33 -06:00
|
|
|
|
var statsList = stats.Select((stats, index) =>
|
|
|
|
|
translationLookup["COMMANDS_TOPSTATS_RESULT"]
|
|
|
|
|
.FormatExt(index + 1, stats.Name, stats.KDR, stats.Performance));
|
2018-05-15 23:57:37 -05:00
|
|
|
|
|
2020-11-27 21:52:52 -06:00
|
|
|
|
topStatsText.AddRange(statsList);
|
2018-05-05 15:36:26 -05:00
|
|
|
|
|
2021-11-23 17:26:33 -06:00
|
|
|
|
// no one qualified
|
2018-05-07 23:58:46 -05:00
|
|
|
|
if (topStatsText.Count == 1)
|
2018-05-05 15:36:26 -05:00
|
|
|
|
{
|
|
|
|
|
topStatsText = new List<string>()
|
2018-04-10 01:38:18 -05:00
|
|
|
|
{
|
2020-01-31 20:15:07 -06:00
|
|
|
|
translationLookup["PLUGINS_STATS_TEXT_NOQUALIFY"]
|
2018-05-05 15:36:26 -05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return topStatsText;
|
|
|
|
|
}
|
2018-04-10 01:38:18 -05:00
|
|
|
|
|
2021-11-23 17:26:33 -06:00
|
|
|
|
private new readonly CommandConfiguration _config;
|
2020-08-01 09:58:23 -05:00
|
|
|
|
|
2021-11-23 17:26:33 -06:00
|
|
|
|
public TopStats(CommandConfiguration config, ITranslationLookup translationLookup) : base(config,
|
|
|
|
|
translationLookup)
|
2020-01-31 20:15:07 -06:00
|
|
|
|
{
|
|
|
|
|
Name = "topstats";
|
|
|
|
|
Description = translationLookup["PLUGINS_STATS_COMMANDS_TOP_DESC"];
|
|
|
|
|
Alias = "ts";
|
|
|
|
|
Permission = EFClient.Permission.User;
|
|
|
|
|
RequiresTarget = false;
|
2020-08-01 09:58:23 -05:00
|
|
|
|
|
|
|
|
|
_config = config;
|
2020-01-31 20:15:07 -06:00
|
|
|
|
}
|
2018-05-05 15:36:26 -05:00
|
|
|
|
|
2022-03-23 12:09:40 -05:00
|
|
|
|
public override async Task ExecuteAsync(GameEvent gameEvent)
|
2018-05-05 15:36:26 -05:00
|
|
|
|
{
|
2022-03-23 12:09:40 -05:00
|
|
|
|
var topStats = await GetTopStats(gameEvent.Owner, _translationLookup);
|
|
|
|
|
if (!gameEvent.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix))
|
2018-05-05 15:36:26 -05:00
|
|
|
|
{
|
2022-03-23 12:09:40 -05:00
|
|
|
|
await gameEvent.Origin.TellAsync(topStats, gameEvent.Owner.Manager.CancellationToken);
|
2018-05-05 15:36:26 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (var stat in topStats)
|
2018-09-23 19:45:54 -05:00
|
|
|
|
{
|
2022-03-23 12:09:40 -05:00
|
|
|
|
await gameEvent.Owner.Broadcast(stat).WaitAsync(Utilities.DefaultCommandTimeout,
|
|
|
|
|
gameEvent.Owner.Manager.CancellationToken);
|
2018-09-23 19:45:54 -05:00
|
|
|
|
}
|
2018-02-10 00:26:38 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-23 12:09:40 -05:00
|
|
|
|
}
|