-
Notifications
You must be signed in to change notification settings - Fork 1
/
BaseClusteringPlugin.cs
186 lines (167 loc) · 7.61 KB
/
BaseClusteringPlugin.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using HarmonyLib;
using JetBrains.Annotations;
using Pustalorc.Plugins.BaseClustering.API.BaseClusters;
using Pustalorc.Plugins.BaseClustering.API.Buildables;
using Pustalorc.Plugins.BaseClustering.API.Delegates;
using Pustalorc.Plugins.BaseClustering.API.Utilities;
using Pustalorc.Plugins.BaseClustering.Config;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using SDG.Unturned;
namespace Pustalorc.Plugins.BaseClustering;
/// <summary>
/// Main class for the Base Clustering Plugin. Handles instances of both <see cref="BuildableDirectory"/> and <see cref="BaseClusterDirectory"/>.
/// </summary>
public sealed class BaseClusteringPlugin : RocketPlugin<BaseClusteringPluginConfiguration>
{
/// <summary>
/// A singleton accessor for the plugin.
/// </summary>
public static BaseClusteringPlugin? Instance { get; private set; }
/// <summary>
/// This event is only raised when the plugin has fully loaded.
/// <br/>
/// To be exact, the plugin instantiates everything first on <see cref="BaseClusteringPlugin.Load()"/> and then has the instances correctly initialize once the level has loaded completely.
/// </summary>
[UsedImplicitly]
public static event VoidDelegate? OnPluginFullyLoaded;
/// <summary>
/// Harmony instance that the plugin utilizes.
/// </summary>
private static Harmony? _harmony;
/// <summary>
/// The main instance of type <see cref="BuildableDirectory"/>.
/// </summary>
public BuildableDirectory? BuildableDirectory { get; private set; }
/// <summary>
/// The main instance of type <see cref="BaseClusterDirectory"/>.
/// </summary>
public BaseClusterDirectory? BaseClusterDirectory { get; private set; }
/// <summary>
/// Gets the default translations that the plugin uses.
/// </summary>
public override TranslationList DefaultTranslations => new()
{
{
"command_fail_clustering_disabled",
"This command is disabled as the base clustering feature is disabled."
},
{
"clusters_regen_warning",
"WARNING! This operation can take a long amount of time! The more buildables in the map the longer it will take! Please see console for when this operation is completed."
},
{ "not_available", "N/A" },
{ "cannot_be_executed_from_console", "That command cannot be executed from console with those arguments." },
{
"build_count",
"There are a total of {0} builds. Specific Item: {1}, Radius: {2}, Player: {3}, Planted Barricades Included: {4}, Filter by Barricades: {5}, Filter by Structures: {6}"
},
{ "cluster_count", "There are a total of {0} clusters. Specific Item: {1}, Radius: {2}, Player: {3}" },
{
"not_looking_buildable", "You are not looking at a structure/barricade, so you cannot get any info."
},
{
"cannot_teleport_no_builds",
"Cannot teleport anywhere, no buildables found with the following filters. Specific Item: {0}, Player: {1}, Planted Barricades Included: {2}, Filter by Barricades: {3}, Filter by Structures: {4}"
},
{
"cannot_teleport_builds_too_close",
"Cannot teleport anywhere, all buildables with the specified filters are too close. Specific Item: {0}, Player: {1}, Planted Barricades Included: {2}, Filter by Barricades: {3}, Filter by Structures: {4}"
},
{
"cannot_teleport_no_clusters",
"Cannot teleport anywhere, no clusters found with the following filters. Player: {0}"
},
{ "top_builder_format", "At number {0}, {1} with {2} buildables!" },
{ "top_cluster_format", "At number {0}, {1} with {2} clusters!" },
{ "not_enough_args", "You need more arguments to use this command." },
{ "action_cancelled", "The wreck action was cancelled." },
{ "no_action_queued", "There is no wreck action queued." },
{ "cannot_wreck_no_clusters", "There are no clusters selected, so nothing can be wrecked." },
{
"wrecked_clusters",
"Wrecked {0} clusters. Specific Item: {1}, Radius: {2}, Player: {3}"
},
{
"wreck_clusters_action_queued",
"Queued a wreck clusters action for {3} clusters. Confirm with /wc confirm. Player: {0}, Specific Item: {1}, Radius: {2}."
},
{
"wreck_clusters_action_queued_new",
"Discarded previous queued action and queued a new wreck clusters action for {3} clusters. Confirm with /wc confirm. Player: {0}, Specific Item: {1}, Radius: {2}."
},
{ "cannot_wreck_no_builds", "There are no buildables selected, so nothing can be wrecked." },
{
"wrecked",
"Wrecked {0} buildables. Specific Item: {1}, Radius: {2}, Player: {3}, Planted Barricades Included: {4}, Filter by Barricades: {5}, Filter by Structures: {6}"
},
{
"wreck_action_queued",
"Queued a wreck action for {6} buildables. Confirm with /w confirm. Specific Item: {0}, Radius: {1}, Player: {2}, Planted Barricades Included: {3}, Filter by Barricades: {4}, Filter by Structures: {5}"
},
{
"wreck_action_queued_new",
"Discarded previous queued action and queued a new wreck action for {6} buildables. Confirm with /w confirm. Specific Item: {0}, Radius: {1}, Player: {2}, Planted Barricades Included: {3}, Filter by Barricades: {4}, Filter by Structures: {5}"
},
{
"no_vehicle_found",
"Couldn't find a vehicle in the direction you're looking, or you are too far away from one. Maximum distance is 10 units."
},
{
"vehicle_dead",
"The vehicle you are looking at is destroyed and cannot be wrecked. Please look at a vehicle that isn't destroyed."
},
{
"vehicle_no_plant",
"The vehicle appears to have no assigned barricades to it, please make sure that it has barricades before asking to wreck them."
},
{ "vehicle_wreck", "Wrecked buildables from {0} [{1}]. Instance ID: {2}, Owner: {3}" }
};
/// <summary>
/// Loads and initializes the plugin.
/// </summary>
protected override void Load()
{
if (_harmony == null)
{
_harmony = new Harmony("com.pustalorc.baseClustering");
_harmony.PatchAll();
}
BuildableDirectory = new BuildableDirectory(Configuration.Instance);
if (Configuration.Instance.EnableClustering)
BaseClusterDirectory = new BaseClusterDirectory(this, Configuration.Instance, BuildableDirectory);
if (Level.isLoaded)
OnLevelLoaded(0);
else
Level.onLevelLoaded += OnLevelLoaded;
Provider.onCommenceShutdown += SaveManager.save;
Instance = this;
Logging.PluginLoaded(this);
}
/// <summary>
/// Unloads and de-initializes the plugin.
/// </summary>
protected override void Unload()
{
Instance = null;
Provider.onCommenceShutdown -= SaveManager.save;
Level.onLevelLoaded -= OnLevelLoaded;
if (BaseClusterDirectory != null)
{
BaseClusterDirectory.Unload();
BaseClusterDirectory = null;
}
if (BuildableDirectory != null)
{
BuildableDirectory.Unload();
BuildableDirectory = null;
}
Logging.PluginUnloaded(this);
}
private void OnLevelLoaded(int level)
{
BuildableDirectory?.LevelLoaded();
BaseClusterDirectory?.LevelLoaded();
OnPluginFullyLoaded?.Invoke();
}
}