-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.cs
More file actions
89 lines (76 loc) · 2.43 KB
/
Loader.cs
File metadata and controls
89 lines (76 loc) · 2.43 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// -----------------------------------------------------------------------
// <copyright file="Loader.cs" company="Redforce04">
// Copyright (c) Redforce04. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------
// ReSharper disable InconsistentNaming
namespace BananaLibrary;
using API.Features;
using HarmonyLib;
using MEC;
/// <summary>
/// Contains the Initializer that is used to enable the features of this framework.
/// </summary>
// ReSharper disable once UnusedType.Global
public static class Loader
{
private static bool initialized;
/// <summary>
/// Gets or sets the primary <see cref="Harmony"/> Instance used to patch methods.
/// </summary>
/// <remarks>
/// This Library uses the updated HarmonyX library rather than Lib.Harmony. It may conflict with other harmony installs.
/// </remarks>
internal static Harmony? Harmony { get; set; }
/// <summary>
/// Initializes the features of this framework.
/// </summary>
public static void Initialize()
{
if (initialized)
{
return;
}
initialized = true;
LoadHarmony();
BananaPlugin.LoadBananaPlugins();
BananaServer.LoadBananaServers();
LabApi.Events.Handlers.ServerEvents.WaitingForPlayers += BananaRole.LoadBananaRoles;
PermissionsProvider.LoadPermissionProvider();
BananaFeature.LoadBananaFeatures();
Timing.CallDelayed(.5f, BananaFeature.EnableFeatures);
}
/// <summary>
/// Unloads all BananaPlugin Items.
/// </summary>
public static void Unload()
{
if (!initialized)
{
return;
}
initialized = false;
// Todo make an unloading system.
UnloadHarmony();
LabApi.Events.Handlers.ServerEvents.WaitingForPlayers -= BananaRole.LoadBananaRoles;
BananaServer.UnloadBananaServers();
PermissionsProvider.UnloadPermissionProvider();
BananaRole.UnloadBananaRoles();
BananaFeature.UnloadBananaFeatures();
}
private static void OnWaitingForPlayer()
{
BananaRole.LoadBananaRoles();
}
private static void LoadHarmony()
{
Harmony = new Harmony("BananaLibrary");
Harmony.PatchAll();
}
private static void UnloadHarmony()
{
Harmony.UnpatchAll();
Harmony = null;
}
}