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