IW4M-Admin/Plugins/LiveRadar/Plugin.cs

63 lines
1.8 KiB
C#
Raw Normal View History

2019-07-05 21:53:03 -04:00
using LiveRadar.Configuration;
using SharedLibraryCore;
using SharedLibraryCore.Configuration;
2019-06-30 14:37:59 -04:00
using SharedLibraryCore.Interfaces;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace LiveRadar
{
public class Plugin : IPlugin
{
public string Name => "Live Radar";
public float Version => (float)Utilities.GetVersionAsDouble();
public string Author => "RaidMax";
2019-07-05 21:53:03 -04:00
internal static BaseConfigurationHandler<LiveRadarConfiguration> Config;
2019-06-30 14:37:59 -04:00
public Task OnEventAsync(GameEvent E, Server S)
{
if (E.Type == GameEvent.EventType.Unknown)
{
if (E.Data?.StartsWith("LiveRadar") ?? false)
{
var radarUpdate = RadarEvent.Parse(E.Data);
2019-07-05 21:53:03 -04:00
var client = S.Manager.GetActiveClients().FirstOrDefault(_client => _client.NetworkId == radarUpdate.Guid);
if (client != null)
{
radarUpdate.Name = client.Name;
client.SetAdditionalProperty("LiveRadar", radarUpdate);
}
2019-06-30 14:37:59 -04:00
}
}
return Task.CompletedTask;
}
2019-07-05 21:53:03 -04:00
public async Task OnLoadAsync(IManager manager)
2019-06-30 14:37:59 -04:00
{
2019-07-05 21:53:03 -04:00
// load custom configuration
Config = new BaseConfigurationHandler<LiveRadarConfiguration>("LiveRadarConfiguration");
if (Config.Configuration() == null)
{
Config.Set((LiveRadarConfiguration)new LiveRadarConfiguration().Generate());
await Config.Save();
}
2019-06-30 14:37:59 -04:00
}
public Task OnTickAsync(Server S)
{
return Task.CompletedTask;
}
public Task OnUnloadAsync()
{
return Task.CompletedTask;
}
}
}