fix(client): only periodically update
This commit is contained in:
parent
805b8ac861
commit
4f8b05084d
|
@ -0,0 +1,4 @@
|
|||
name: Player Map
|
||||
author: Anna
|
||||
punchline: Crowdsourced location maps
|
||||
description: Crowdsourced location maps
|
|
@ -1,4 +1,5 @@
|
|||
using System.Net.Http.Headers;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http.Headers;
|
||||
using Dalamud.Game.ClientState.Objects.Enums;
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.IoC;
|
||||
|
@ -10,6 +11,9 @@ using Newtonsoft.Json.Serialization;
|
|||
namespace PlayerMap;
|
||||
|
||||
public class Plugin : IDalamudPlugin {
|
||||
[PluginService]
|
||||
internal static IPluginLog Log { get; private set; }
|
||||
|
||||
[PluginService]
|
||||
internal IFramework Framework { get; init; }
|
||||
|
||||
|
@ -20,9 +24,11 @@ public class Plugin : IDalamudPlugin {
|
|||
internal IClientState ClientState { get; init; }
|
||||
|
||||
private HttpClient Http { get; } = new();
|
||||
private Stopwatch Stopwatch { get; } = new();
|
||||
|
||||
public Plugin() {
|
||||
this.Framework!.Update += this.FrameworkUpdate;
|
||||
this.Stopwatch.Start();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
@ -30,6 +36,12 @@ public class Plugin : IDalamudPlugin {
|
|||
}
|
||||
|
||||
private void FrameworkUpdate(IFramework framework) {
|
||||
if (this.Stopwatch.Elapsed < TimeSpan.FromSeconds(5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.Stopwatch.Restart();
|
||||
|
||||
var territory = this.ClientState.TerritoryType;
|
||||
var players = this.ObjectTable
|
||||
.Where(obj => obj.ObjectKind == ObjectKind.Player && obj is PlayerCharacter)
|
||||
|
@ -43,7 +55,7 @@ public class Plugin : IDalamudPlugin {
|
|||
pos.Y,
|
||||
pos.Z,
|
||||
player.Rotation,
|
||||
player.Customize,
|
||||
player.Customize.ToList(),
|
||||
player.Level,
|
||||
player.ClassJob.Id,
|
||||
player.CompanyTag.TextValue,
|
||||
|
@ -74,7 +86,9 @@ public class Plugin : IDalamudPlugin {
|
|||
},
|
||||
};
|
||||
|
||||
await this.Http.SendAsync(req);
|
||||
var resp = await this.Http.SendAsync(req);
|
||||
var output = await resp.Content.ReadAsStringAsync();
|
||||
Log.Info(output);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +108,7 @@ internal struct PlayerInfo(
|
|||
float y,
|
||||
float z,
|
||||
float w,
|
||||
byte[] customize,
|
||||
List<byte> customize,
|
||||
byte level,
|
||||
uint job,
|
||||
string freeCompany,
|
||||
|
@ -107,7 +121,7 @@ internal struct PlayerInfo(
|
|||
public readonly float Y = y;
|
||||
public readonly float Z = z;
|
||||
public readonly float W = w;
|
||||
public readonly byte[] Customize = customize;
|
||||
public readonly List<byte> Customize = customize;
|
||||
public readonly byte Level = level;
|
||||
public readonly uint Job = job;
|
||||
public readonly string FreeCompany = freeCompany;
|
||||
|
|
Loading…
Reference in New Issue