Follow the leader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

LeadercraftPlugin.cs 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System.Reflection;
  2. using IllusionPlugin;
  3. using GamecraftModdingAPI.Utility;
  4. using Leadercraft.Scoring;
  5. using Leadercraft.Server;
  6. namespace Leadercraft
  7. {
  8. public class LeadercraftPlugin : IPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
  9. {
  10. public static float LoopDelay = 0.1f;
  11. public string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // mod name
  12. public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // mod & assembly version
  13. internal static LeadercraftApi Api = null;
  14. private static string tokenUrl =
  15. #if DEBUG
  16. "http://192.168.122.229:1337/token";
  17. #else
  18. "https://leadercraft.exmods.org/s/token";
  19. #endif
  20. private static string criteriaUrl =
  21. #if DEBUG
  22. "http://192.168.122.229:7048/criteria";
  23. #else
  24. "https://leadercraft.exmods.org/c/criteria";
  25. #endif
  26. public static void BuildApi()
  27. {
  28. if (Api == null)
  29. {
  30. if (!Tools.IsSteamAvailable)
  31. {
  32. Logging.MetaLog("Steam is unavailable :(");
  33. return;
  34. }
  35. Api = new LeadercraftApi(Tools.UserId, tokenUrl, criteriaUrl);
  36. GamecraftModdingAPI.Utility.Logging.MetaLog("Leadercraft API initialized");
  37. }
  38. }
  39. // called when Gamecraft shuts down
  40. public void OnApplicationQuit()
  41. {
  42. // Shutdown this mod
  43. GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
  44. // Shutdown the Gamecraft modding API last
  45. GamecraftModdingAPI.Main.Shutdown();
  46. }
  47. // called when Gamecraft starts up
  48. public void OnApplicationStart()
  49. {
  50. // Initialize the Gamecraft modding API first
  51. GamecraftModdingAPI.Main.Init();
  52. // check out the modding API docs here: https://mod.exmods.org/
  53. // Initialize this mod
  54. GamecraftModdingAPI.App.Game.Simulate += (_, __) => State.StartPlayingGame();
  55. GamecraftModdingAPI.App.Game.Edit += (_, __) => State.StopPlayingGame();
  56. GamecraftModdingAPI.App.Game.Enter += (_, __) => State.EnterGame();
  57. GamecraftModdingAPI.App.Game.Exit += (_, __) => State.ExitGame();
  58. GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up");
  59. // Debug mode
  60. //Debug();
  61. }
  62. // unused methods
  63. public void OnFixedUpdate() { } // called once per physics update
  64. public void OnLevelWasInitialized(int level) { }// called after a level is initialized
  65. public void OnLevelWasLoaded(int level) { } // called after a level is loaded
  66. public void OnUpdate() { } // called once per rendered frame (frame update)
  67. public static void Debug()
  68. {
  69. tokenUrl = "http://192.168.122.229:1337/token";
  70. criteriaUrl = "http://192.168.122.229:7048/criteria";
  71. }
  72. }
  73. }