From 44a3dabb7bb25e5506f8dff234fb89696ba2554f Mon Sep 17 00:00:00 2001 From: AlexMog Date: Sat, 20 Feb 2021 21:38:10 +0100 Subject: [PATCH] Added CharacterSpawn event --- Longship/Events/CharacterSpawnEvent.cs | 9 +++++++++ Longship/Longship.cs | 9 +++++++++ Longship/Longship.csproj | 2 ++ Longship/Patches/PatchListenToCharacterSpawn.cs | 14 ++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 Longship/Events/CharacterSpawnEvent.cs create mode 100644 Longship/Patches/PatchListenToCharacterSpawn.cs diff --git a/Longship/Events/CharacterSpawnEvent.cs b/Longship/Events/CharacterSpawnEvent.cs new file mode 100644 index 0000000..04ee18d --- /dev/null +++ b/Longship/Events/CharacterSpawnEvent.cs @@ -0,0 +1,9 @@ +namespace Longship.Events +{ + public class CharacterSpawnEvent : CharacterEvent + { + public CharacterSpawnEvent(Character character) : base(character) + { + } + } +} \ No newline at end of file diff --git a/Longship/Longship.cs b/Longship/Longship.cs index 5b3f696..4f4548d 100644 --- a/Longship/Longship.cs +++ b/Longship/Longship.cs @@ -11,6 +11,7 @@ public class Longship { public const string BuildTag = "0.0.1"; public static Longship Instance { get; private set; } + private static bool _debug = false; public PluginManager PluginManager { get; } public ConfigurationManager ConfigurationManager { get; } public CommandsManager CommandsManager { get; } @@ -41,6 +42,14 @@ public void Init() Log($"Ready."); } + public static void LogDebug(string message) + { + if (_debug) + { + System.Console.WriteLine($"[Longship][DEBUG] {message}"); + } + } + public static void Log(string message) { System.Console.WriteLine($"[Longship][INFO] {message}"); diff --git a/Longship/Longship.csproj b/Longship/Longship.csproj index 1cb13eb..6ee45ed 100644 --- a/Longship/Longship.csproj +++ b/Longship/Longship.csproj @@ -62,6 +62,7 @@ + @@ -71,6 +72,7 @@ + diff --git a/Longship/Patches/PatchListenToCharacterSpawn.cs b/Longship/Patches/PatchListenToCharacterSpawn.cs new file mode 100644 index 0000000..7babf19 --- /dev/null +++ b/Longship/Patches/PatchListenToCharacterSpawn.cs @@ -0,0 +1,14 @@ +using HarmonyLib; +using Longship.Events; + +namespace Longship.Patches +{ + [HarmonyPatch(typeof(Character), "Awake")] + public class PatchListenToCharacterSpawn + { + static void Postfix(Character __instance) + { + Longship.Instance.EventManager.DispatchEvent(new CharacterSpawnEvent(__instance)); + } + } +} \ No newline at end of file