42
42
import net .william278 .husktowns .database .Database ;
43
43
import net .william278 .husktowns .events .BukkitEventDispatcher ;
44
44
import net .william278 .husktowns .hook .*;
45
- import net .william278 .husktowns .hook .WorldGuardHook ;
45
+ import net .william278 .husktowns .hook .map .BlueMapHook ;
46
+ import net .william278 .husktowns .hook .map .DynmapHook ;
47
+ import net .william278 .husktowns .hook .map .Pl3xMapHook ;
46
48
import net .william278 .husktowns .listener .BukkitListener ;
47
49
import net .william278 .husktowns .manager .Manager ;
48
50
import net .william278 .husktowns .network .Broker ;
@@ -125,8 +127,8 @@ public class BukkitHuskTowns extends JavaPlugin implements HuskTowns, BukkitTask
125
127
@ Nullable
126
128
@ Getter (AccessLevel .NONE )
127
129
private Advancement advancements ;
128
-
129
- WorldGuardHook worldGuardHook ;
130
+ @ Setter
131
+ private HookManager hookManager ;
130
132
131
133
@ TestOnly
132
134
@ SuppressWarnings ("unused" )
@@ -136,62 +138,69 @@ private BukkitHuskTowns(@NotNull JavaPluginLoader loader, @NotNull PluginDescrip
136
138
}
137
139
138
140
@ Override
139
- public void onEnable () {
140
- // Initialize PaperLib and Adventure
141
- this .paperLib = new MorePaperLib (this );
142
- this .audiences = BukkitAudiences .create (this );
143
-
141
+ public void onLoad () {
144
142
// Load configuration and subsystems
145
143
this .loadConfig ();
146
144
if (this .settings .getGeneral ().isDoAdvancements ()) {
147
145
loadAdvancements ();
148
146
}
149
147
150
- // Prepare the database and networking system
151
- this .database = this .loadDatabase ();
152
- if (!database .hasLoaded ()) {
153
- log (Level .SEVERE , "Failed to load database! Please check your credentials! Disabling plugin..." );
154
- Bukkit .getPluginManager ().disablePlugin (this );
155
- return ;
156
- }
157
-
158
- // Load manager and broker
159
- this .manager = new Manager (this );
160
- this .broker = this .loadBroker ();
161
-
162
148
// Register hooks
149
+ this .hookManager = new BukkitHookManager (this );
163
150
final PluginManager plugins = Bukkit .getPluginManager ();
164
151
if (settings .getGeneral ().isEconomyHook ()) {
165
152
if (plugins .getPlugin ("Vault" ) != null ) {
166
- this .registerHook (new VaultEconomyHook (this ));
153
+ hookManager .registerHook (new VaultEconomyHook (this ));
167
154
}
168
155
}
169
156
if (settings .getGeneral ().getWebMapHook ().isEnabled ()) {
170
157
if (plugins .getPlugin ("BlueMap" ) != null ) {
171
- this .registerHook (new BlueMapHook (this ));
158
+ hookManager .registerHook (new BlueMapHook (this ));
172
159
} else if (plugins .getPlugin ("dynmap" ) != null ) {
173
- this .registerHook (new DynmapHook (this ));
160
+ hookManager .registerHook (new DynmapHook (this ));
174
161
} else if (plugins .getPlugin ("Pl3xMap" ) != null ) {
175
- this .registerHook (new Pl3xMapHook (this ));
162
+ hookManager .registerHook (new Pl3xMapHook (this ));
176
163
}
177
164
}
178
165
if (settings .getGeneral ().isLuckpermsContextsHook () && plugins .getPlugin ("LuckPerms" ) != null ) {
179
- this .registerHook (new LuckPermsHook (this ));
166
+ hookManager .registerHook (new LuckPermsHook (this ));
180
167
}
181
168
if (settings .getGeneral ().isPlaceholderapiHook () && plugins .getPlugin ("PlaceholderAPI" ) != null ) {
182
- this .registerHook (new PlaceholderAPIHook (this ));
169
+ hookManager .registerHook (new PlaceholderAPIHook (this ));
183
170
}
184
171
if (settings .getGeneral ().isHuskhomesHook () && plugins .getPlugin ("HuskHomes" ) != null ) {
185
- this .registerHook (new HuskHomesHook (this ));
172
+ hookManager .registerHook (new HuskHomesHook (this ));
186
173
}
187
174
if (settings .getGeneral ().isPlanHook () && plugins .getPlugin ("Plan" ) != null ) {
188
- this .registerHook (new PlanHook (this ));
175
+ hookManager .registerHook (new PlanHook (this ));
189
176
}
190
177
if (settings .getGeneral ().isWorldGuardHook () && plugins .getPlugin ("WorldGuard" ) != null ) {
191
- worldGuardHook = new BukkitWorldGuardHook (this );
192
- this .registerHook (worldGuardHook );
178
+ hookManager .registerHook (new BukkitWorldGuardHook (this ));
193
179
}
194
180
181
+ hookManager .registerOnLoad ();
182
+ }
183
+
184
+ @ Override
185
+ public void onEnable () {
186
+ // Initialize PaperLib and Adventure
187
+ this .paperLib = new MorePaperLib (this );
188
+ this .audiences = BukkitAudiences .create (this );
189
+
190
+ // Prepare the database and networking system
191
+ this .database = this .loadDatabase ();
192
+ if (!database .hasLoaded ()) {
193
+ log (Level .SEVERE , "Failed to load database! Please check your credentials! Disabling plugin..." );
194
+ Bukkit .getPluginManager ().disablePlugin (this );
195
+ return ;
196
+ }
197
+
198
+ // Load manager and broker
199
+ this .manager = new Manager (this );
200
+ this .broker = this .loadBroker ();
201
+
202
+ hookManager .registerOnEnable ();
203
+
195
204
// Load towns and claim worlds
196
205
this .loadData ();
197
206
@@ -208,6 +217,8 @@ public void onEnable() {
208
217
initializeMetrics ();
209
218
log (Level .INFO , "Enabled HuskTowns v" + getVersion ());
210
219
checkForUpdates ();
220
+
221
+ runAsyncDelayed (hookManager ::registerDelayed , 20L );
211
222
}
212
223
213
224
@ Override
@@ -243,8 +254,8 @@ public Optional<Broker> getMessageBroker() {
243
254
}
244
255
245
256
@ Override
246
- public WorldGuardHook getWorldGuardHook () {
247
- return worldGuardHook ;
257
+ public @ NotNull HookManager getHookManager () {
258
+ return hookManager ;
248
259
}
249
260
250
261
@ Override
@@ -364,7 +375,7 @@ private void initializeMetrics() {
364
375
metrics .addCustomChart (new SimplePie ("using_map" ,
365
376
() -> getMapHook ().isPresent () ? "true" : "false" ));
366
377
getMapHook ().ifPresent (hook -> metrics .addCustomChart (new SimplePie ("map_type" ,
367
- () -> hook .getName ().toLowerCase ())));
378
+ () -> hook .getHookInfo (). id ().toLowerCase ())));
368
379
getMessageBroker ().ifPresent (broker -> metrics .addCustomChart (new SimplePie ("messenger_type" ,
369
380
() -> settings .getCrossServer ().getBrokerType ().name ().toLowerCase ())));
370
381
} catch (Exception e ) {
0 commit comments