TeleportConsumer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using Dalamud.Logging;
  3. using Dalamud.Plugin.Ipc;
  4. namespace HuntBuddy.Ipc
  5. {
  6. public class TeleportConsumer
  7. {
  8. private bool isAvailable;
  9. private long timeSinceLastCheck;
  10. public bool IsAvailable
  11. {
  12. get
  13. {
  14. if (this.timeSinceLastCheck + 5000 > Environment.TickCount64)
  15. {
  16. return this.isAvailable;
  17. }
  18. try
  19. {
  20. this.consumerMessageSetting.InvokeFunc();
  21. this.isAvailable = true;
  22. this.timeSinceLastCheck = Environment.TickCount64;
  23. }
  24. catch
  25. {
  26. this.isAvailable = false;
  27. }
  28. return this.isAvailable;
  29. }
  30. }
  31. private ICallGateSubscriber<bool> consumerMessageSetting = null!;
  32. private ICallGateSubscriber<uint, byte, bool> consumerTeleport = null!;
  33. private void Subscribe()
  34. {
  35. try
  36. {
  37. this.consumerTeleport = Plugin.PluginInterface.GetIpcSubscriber<uint, byte, bool>("Teleport");
  38. this.consumerMessageSetting = Plugin.PluginInterface.GetIpcSubscriber<bool>("Teleport.ChatMessage");
  39. }
  40. catch (Exception ex)
  41. {
  42. PluginLog.LogDebug($"Failed to subscribe to Teleporter\nReason: {ex}");
  43. }
  44. }
  45. public TeleportConsumer() => this.Subscribe();
  46. public bool Teleport(uint aetheryteId)
  47. {
  48. try
  49. {
  50. return this.consumerTeleport.InvokeFunc(aetheryteId, 0);
  51. }
  52. catch
  53. {
  54. Plugin.Chat.PrintError("Teleporter plugin is not responding");
  55. return false;
  56. }
  57. }
  58. }
  59. }