leadercraft/Leadercraft/LeadercraftPlugin.cs

81 lines
No EOL
2.4 KiB
C#

using System.Reflection;
using IllusionPlugin;
using GamecraftModdingAPI.Utility;
using Leadercraft.Scoring;
using Leadercraft.Server;
namespace Leadercraft
{
public class LeadercraftPlugin : IEnhancedPlugin // the Illusion Plugin Architecture (IPA) will ignore classes that don't implement IPlugin'
{
public static float LoopDelay = 0.1f;
public override string Name { get; } = Assembly.GetExecutingAssembly().GetName().Name; // mod name
public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // mod & assembly version
internal static LeadercraftApi Api = null;
private static string tokenUrl =
#if DEBUG
"http://192.168.122.229:1337/token";
#else
"https://leadercraft.exmods.org/s/token";
#endif
private static string criteriaUrl =
#if DEBUG
"http://192.168.122.229:7048/criteria";
#else
"https://leadercraft.exmods.org/c/criteria";
#endif
public static void BuildApi()
{
if (Api == null)
{
if (!Tools.IsSteamAvailable)
{
Logging.MetaLog("Steam is unavailable :(");
return;
}
Api = new LeadercraftApi(Tools.UserId, tokenUrl, criteriaUrl);
GamecraftModdingAPI.Utility.Logging.MetaLog("Leadercraft API initialized");
}
}
// called when Gamecraft shuts down
public override void OnApplicationQuit()
{
// Shutdown this mod
GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown");
// Shutdown the Gamecraft modding API last
GamecraftModdingAPI.Main.Shutdown();
}
// called when Gamecraft starts up
public override void OnApplicationStart()
{
// Initialize the Gamecraft modding API first
GamecraftModdingAPI.Main.Init();
// check out the modding API docs here: https://mod.exmods.org/
// Initialize this mod
GamecraftModdingAPI.App.Game.Simulate += (_, __) => State.StartPlayingGame();
GamecraftModdingAPI.App.Game.Edit += (_, __) => State.StopPlayingGame();
GamecraftModdingAPI.App.Game.Enter += (_, __) => State.EnterGame();
GamecraftModdingAPI.App.Game.Exit += (_, __) => State.ExitGame();
GamecraftModdingAPI.Utility.Logging.MetaLog($"{Name} has started up");
// Debug mode
//Debug();
}
public static void Debug()
{
tokenUrl = "http://192.168.122.229:1337/token";
criteriaUrl = "http://192.168.122.229:7048/criteria";
}
}
}