-
Notifications
You must be signed in to change notification settings - Fork 2
/
Core.cs
56 lines (45 loc) · 1.79 KB
/
Core.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using KindredArenas.Services;
using ProjectM;
using Unity.Entities;
namespace KindredArenas;
internal static class Core
{
public static World Server { get; } = GetWorld("Server") ?? throw new System.Exception("There is no Server world (yet). Did you install a server mod on the client?");
public static EntityManager EntityManager { get; } = Server.EntityManager;
public static ServerGameSettingsSystem ServerGameSettingsSystem { get; private set; }
public static ManualLogSource Log { get; } = Plugin.PluginLog;
public static Services.PvpService PvpService { get; internal set; }
public static Services.PvpArenaService PvpArenaService { get; internal set; }
public static Services.PvpRegionsService PvpRegionsService { get; internal set; }
public static Services.ElysiumService ElysiumService { get; internal set; }
public static void LogException(System.Exception e, [CallerMemberName] string caller = null)
{
Core.Log.LogError($"Failure in {caller}\nMessage: {e.Message} Inner:{e.InnerException?.Message}\n\nStack: {e.StackTrace}\nInner Stack: {e.InnerException?.StackTrace}");
}
internal static void InitializeAfterLoaded()
{
if (_hasInitialized) return;
ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
PvpService = new();
PvpArenaService = new();
PvpRegionsService = new();
ElysiumService = new();
_hasInitialized = true;
Log.LogInfo($"{nameof(InitializeAfterLoaded)} completed");
}
private static bool _hasInitialized = false;
public static bool HasInitialized => _hasInitialized;
private static World GetWorld(string name)
{
foreach (var world in World.s_AllWorlds)
{
if (world.Name == name)
{
return world;
}
}
return null;
}
}