-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
SuperiorSkyblockPlugin.java
751 lines (632 loc) · 29.6 KB
/
SuperiorSkyblockPlugin.java
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
package com.bgsoftware.superiorskyblock;
import com.bgsoftware.common.reflection.ReflectMethod;
import com.bgsoftware.common.updater.Updater;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblock;
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
import com.bgsoftware.superiorskyblock.api.handlers.MenusManager;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.island.SortingType;
import com.bgsoftware.superiorskyblock.api.modules.ModuleLoadTime;
import com.bgsoftware.superiorskyblock.api.objects.Pair;
import com.bgsoftware.superiorskyblock.api.scripts.IScriptEngine;
import com.bgsoftware.superiorskyblock.api.world.event.WorldEventsManager;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.commands.CommandsManagerImpl;
import com.bgsoftware.superiorskyblock.commands.admin.AdminCommandsMap;
import com.bgsoftware.superiorskyblock.commands.player.PlayerCommandsMap;
import com.bgsoftware.superiorskyblock.config.SettingsManagerImpl;
import com.bgsoftware.superiorskyblock.core.ServerVersion;
import com.bgsoftware.superiorskyblock.core.Singleton;
import com.bgsoftware.superiorskyblock.core.database.DataManager;
import com.bgsoftware.superiorskyblock.core.engine.EnginesFactory;
import com.bgsoftware.superiorskyblock.core.engine.NashornEngineDownloader;
import com.bgsoftware.superiorskyblock.core.errors.ManagerLoadException;
import com.bgsoftware.superiorskyblock.core.events.EventsBus;
import com.bgsoftware.superiorskyblock.core.factory.FactoriesManagerImpl;
import com.bgsoftware.superiorskyblock.core.io.JarFiles;
import com.bgsoftware.superiorskyblock.core.itemstack.GlowEnchantment;
import com.bgsoftware.superiorskyblock.core.itemstack.ItemSkulls;
import com.bgsoftware.superiorskyblock.core.key.KeysManagerImpl;
import com.bgsoftware.superiorskyblock.core.logging.Log;
import com.bgsoftware.superiorskyblock.core.menu.MenusManagerImpl;
import com.bgsoftware.superiorskyblock.core.messages.Message;
import com.bgsoftware.superiorskyblock.core.stackedblocks.StackedBlocksManagerImpl;
import com.bgsoftware.superiorskyblock.core.stackedblocks.container.DefaultStackedBlocksContainer;
import com.bgsoftware.superiorskyblock.core.task.CalcTask;
import com.bgsoftware.superiorskyblock.core.task.ShutdownTask;
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor;
import com.bgsoftware.superiorskyblock.core.values.BlockValuesManagerImpl;
import com.bgsoftware.superiorskyblock.core.values.container.BlockLevelsContainer;
import com.bgsoftware.superiorskyblock.core.values.container.BlockWorthValuesContainer;
import com.bgsoftware.superiorskyblock.core.values.container.GeneralBlockValuesContainer;
import com.bgsoftware.superiorskyblock.external.ProvidersManagerImpl;
import com.bgsoftware.superiorskyblock.island.GridManagerImpl;
import com.bgsoftware.superiorskyblock.island.container.DefaultIslandsContainer;
import com.bgsoftware.superiorskyblock.island.flag.IslandFlags;
import com.bgsoftware.superiorskyblock.island.preview.DefaultIslandPreviews;
import com.bgsoftware.superiorskyblock.island.privilege.IslandPrivileges;
import com.bgsoftware.superiorskyblock.island.purge.DefaultIslandsPurger;
import com.bgsoftware.superiorskyblock.island.role.RolesManagerImpl;
import com.bgsoftware.superiorskyblock.island.role.container.DefaultRolesContainer;
import com.bgsoftware.superiorskyblock.island.top.SortingComparators;
import com.bgsoftware.superiorskyblock.island.top.SortingTypes;
import com.bgsoftware.superiorskyblock.island.upgrade.UpgradesManagerImpl;
import com.bgsoftware.superiorskyblock.island.upgrade.container.DefaultUpgradesContainer;
import com.bgsoftware.superiorskyblock.island.upgrade.loaders.PlaceholdersUpgradeCostLoader;
import com.bgsoftware.superiorskyblock.island.upgrade.loaders.VaultUpgradeCostLoader;
import com.bgsoftware.superiorskyblock.listener.BukkitListeners;
import com.bgsoftware.superiorskyblock.listener.ChunksListener;
import com.bgsoftware.superiorskyblock.mission.MissionsManagerImpl;
import com.bgsoftware.superiorskyblock.mission.container.DefaultMissionsContainer;
import com.bgsoftware.superiorskyblock.module.ModulesManagerImpl;
import com.bgsoftware.superiorskyblock.module.container.DefaultModulesContainer;
import com.bgsoftware.superiorskyblock.nms.NMSAlgorithms;
import com.bgsoftware.superiorskyblock.nms.NMSChunks;
import com.bgsoftware.superiorskyblock.nms.NMSDragonFight;
import com.bgsoftware.superiorskyblock.nms.NMSDragonFightImpl;
import com.bgsoftware.superiorskyblock.nms.NMSEntities;
import com.bgsoftware.superiorskyblock.nms.NMSHolograms;
import com.bgsoftware.superiorskyblock.nms.NMSPlayers;
import com.bgsoftware.superiorskyblock.nms.NMSTags;
import com.bgsoftware.superiorskyblock.nms.NMSWorld;
import com.bgsoftware.superiorskyblock.player.PlayersManagerImpl;
import com.bgsoftware.superiorskyblock.player.container.DefaultPlayersContainer;
import com.bgsoftware.superiorskyblock.player.respawn.RespawnActions;
import com.bgsoftware.superiorskyblock.service.ServicesHandler;
import com.bgsoftware.superiorskyblock.service.bossbar.BossBarsServiceImpl;
import com.bgsoftware.superiorskyblock.service.dragon.DragonBattleServiceImpl;
import com.bgsoftware.superiorskyblock.service.hologram.HologramsServiceImpl;
import com.bgsoftware.superiorskyblock.service.message.MessagesServiceImpl;
import com.bgsoftware.superiorskyblock.service.placeholders.PlaceholdersServiceImpl;
import com.bgsoftware.superiorskyblock.world.chunk.ChunksProvider;
import com.bgsoftware.superiorskyblock.world.schematic.SchematicsManagerImpl;
import com.bgsoftware.superiorskyblock.world.schematic.container.DefaultSchematicsContainer;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.UnsafeValues;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable;
import java.io.File;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
public class SuperiorSkyblockPlugin extends JavaPlugin implements SuperiorSkyblock {
private static SuperiorSkyblockPlugin plugin;
private final Updater updater = new Updater(this, "superiorskyblock2");
private final DataManager dataHandler = new DataManager(this);
private final FactoriesManagerImpl factoriesHandler = new FactoriesManagerImpl();
private final GridManagerImpl gridHandler = new GridManagerImpl(this,
new DefaultIslandsPurger(), new DefaultIslandPreviews());
private final StackedBlocksManagerImpl stackedBlocksHandler = new StackedBlocksManagerImpl(this,
new DefaultStackedBlocksContainer());
private final BlockValuesManagerImpl blockValuesHandler = new BlockValuesManagerImpl(this,
new BlockWorthValuesContainer(), new BlockLevelsContainer(),
new GeneralBlockValuesContainer(), new GeneralBlockValuesContainer());
private final SchematicsManagerImpl schematicsHandler = new SchematicsManagerImpl(this,
new DefaultSchematicsContainer());
private final PlayersManagerImpl playersHandler = new PlayersManagerImpl(this);
private final RolesManagerImpl rolesHandler = new RolesManagerImpl(this,
new DefaultRolesContainer());
private final MissionsManagerImpl missionsHandler = new MissionsManagerImpl(this,
new DefaultMissionsContainer());
private final MenusManagerImpl menusHandler = new MenusManagerImpl(this);
private final KeysManagerImpl keysHandler = new KeysManagerImpl(this);
private final ProvidersManagerImpl providersHandler = new ProvidersManagerImpl(this);
private final UpgradesManagerImpl upgradesHandler = new UpgradesManagerImpl(this,
new DefaultUpgradesContainer());
private final CommandsManagerImpl commandsHandler = new CommandsManagerImpl(this,
new PlayerCommandsMap(this), new AdminCommandsMap(this));
private final ModulesManagerImpl modulesHandler = new ModulesManagerImpl(this,
new DefaultModulesContainer(this));
private final ServicesHandler servicesHandler = new ServicesHandler(this);
// The only handler that is initialized is this one, therefore it's not final.
// This is to prevent it's fields to be non-finals.
private SettingsManagerImpl settingsHandler = null;
private IScriptEngine scriptEngine = EnginesFactory.createDefaultEngine();
private final EventsBus eventsBus = new EventsBus(this);
private final BukkitListeners bukkitListeners = new BukkitListeners(this);
private String nmsPackageVersion;
private NMSAlgorithms nmsAlgorithms;
private NMSChunks nmsChunks;
private NMSDragonFight nmsDragonFight;
private NMSEntities nmsEntities;
private NMSHolograms nmsHolograms;
private NMSPlayers nmsPlayers;
private NMSTags nmsTags;
private NMSWorld nmsWorld;
private ChunkGenerator worldGenerator = null;
private boolean shouldEnable = true;
// public static void log(String message) {
// message = Formatters.COLOR_FORMATTER.format(message);
// if (message.contains(ChatColor.COLOR_CHAR + ""))
// Bukkit.getConsoleSender().sendMessage(ChatColor.getLastColors(message.substring(0, 2)) + "[" + plugin.getDescription().getName() + "] " + message);
// else
// plugin.getLogger().info(message);
// }
public static SuperiorSkyblockPlugin getPlugin() {
return plugin;
}
@Override
public void onLoad() {
plugin = this;
new Metrics(this, 4119);
bukkitListeners.registerListenerFailureFilter();
try {
SuperiorSkyblockAPI.setPluginInstance(this);
} catch (UnsupportedOperationException error) {
Log.error("The API instance was already initialized. This can be caused by a reload or another plugin initializing it.");
shouldEnable = false;
}
if (!loadNMSAdapter()) {
shouldEnable = false;
}
Runtime.getRuntime().addShutdownHook(new ShutdownTask(this));
IslandPrivileges.registerPrivileges();
SortingTypes.registerSortingTypes();
IslandFlags.registerFlags();
RespawnActions.registerActions();
try {
SortingComparators.initializeTopIslandMembersSorting();
} catch (IllegalArgumentException error) {
shouldEnable = false;
Log.error("The TopIslandMembersSorting was already initialized. This can be caused by a reload or another plugin initializing it.");
}
this.servicesHandler.registerPlaceholdersService(new PlaceholdersServiceImpl());
this.servicesHandler.registerHologramsService(new HologramsServiceImpl(this));
this.servicesHandler.registerEnderDragonService(new DragonBattleServiceImpl(this));
this.servicesHandler.registerBossBarsService(new BossBarsServiceImpl(this));
this.servicesHandler.registerMessagesService(new MessagesServiceImpl());
}
@Override
public void onEnable() {
try {
if (SuperiorSkyblockAPI.getSuperiorSkyblock() == null) {
shouldEnable = false;
ManagerLoadException.handle(new ManagerLoadException("The API instance was not initialized properly. Contact Ome_R regarding this!",
ManagerLoadException.ErrorLevel.SERVER_SHUTDOWN));
return;
}
if (!shouldEnable) {
Bukkit.shutdown();
return;
}
BukkitExecutor.init(this);
loadUpgradeCostLoaders();
GlowEnchantment.registerGlowEnchantment();
try {
settingsHandler = new SettingsManagerImpl(this);
} catch (ManagerLoadException ex) {
if (!ManagerLoadException.handle(ex)) {
shouldEnable = false;
return;
}
}
modulesHandler.loadData();
EventsBus.PluginInitializeResult eventResult = eventsBus.callPluginInitializeEvent(this);
this.playersHandler.setPlayersContainer(Optional.ofNullable(eventResult.getPlayersContainer()).orElse(new DefaultPlayersContainer()));
this.gridHandler.setIslandsContainer(Optional.ofNullable(eventResult.getIslandsContainer()).orElse(new DefaultIslandsContainer(this)));
modulesHandler.enableModules(ModuleLoadTime.BEFORE_WORLD_CREATION);
try {
providersHandler.getWorldsProvider().prepareWorlds();
} catch (RuntimeException ex) {
shouldEnable = false;
ManagerLoadException handlerError = new ManagerLoadException(ex, ManagerLoadException.ErrorLevel.SERVER_SHUTDOWN);
Log.error(handlerError, "An error occurred while preparing worlds:");
Bukkit.shutdown();
return;
}
try {
reloadPlugin(true);
} catch (ManagerLoadException error) {
ManagerLoadException.handle(error);
shouldEnable = false;
return;
}
try {
bukkitListeners.register();
} catch (RuntimeException ex) {
shouldEnable = false;
ManagerLoadException handlerError = new ManagerLoadException("Cannot load plugin due to a missing event: " + ex.getMessage() + " - contact @Ome_R!",
ManagerLoadException.ErrorLevel.CONTINUE);
Log.error(handlerError, "An error occurred while registering listeners:");
Bukkit.shutdown();
return;
}
modulesHandler.enableModules(ModuleLoadTime.AFTER_HANDLERS_LOADING);
if (updater.isOutdated()) {
Log.info("");
Log.info("A new version is available (v", updater.getLatestVersion(), ")!");
Log.info("Version's description: \"", updater.getVersionDescription(), "\"");
Log.info("");
}
ChunksProvider.start();
// Calculate the maximum amount of islands that fit into the world.
if (calculateMaxPossibleIslands() < 1000) {
Log.warn("It seems like you configured your max-world-size in server.properties to be a small number (",
nmsAlgorithms.getMaxWorldSize(), ").");
Log.warn("This can lead to weird behaviors when new islands are generated beyond this limit.");
Log.warn("Increase the value to for better experience (Default: 29999984)");
}
BukkitExecutor.sync(() -> {
for (Player player : Bukkit.getOnlinePlayers()) {
SuperiorPlayer superiorPlayer = playersHandler.getSuperiorPlayer(player);
superiorPlayer.updateLastTimeStatus();
Island island = gridHandler.getIslandAt(superiorPlayer.getLocation());
Island playerIsland = superiorPlayer.getIsland();
if (superiorPlayer.hasIslandFlyEnabled()) {
if (island != null && island.hasPermission(superiorPlayer, IslandPrivileges.FLY)) {
player.setAllowFlight(true);
player.setFlying(true);
} else {
superiorPlayer.toggleIslandFly();
}
}
if (playerIsland != null)
playerIsland.setCurrentlyActive();
if (island != null)
island.setPlayerInside(superiorPlayer, true);
}
}, 1L);
eventsBus.callPluginInitializedEvent(this);
} catch (Throwable error) {
shouldEnable = false;
Log.error(error, "An unexpected error occurred while enabling the plugin:");
Bukkit.shutdown();
}
}
@Override
public void onDisable() {
BukkitExecutor.prepareDisable();
if (!shouldEnable)
return;
ChunksProvider.stop();
try {
dataHandler.saveDatabase(false);
gridHandler.disablePlugin();
for (Island island : gridHandler.getIslandsToPurge())
island.disbandIsland();
playersHandler.savePlayers();
gridHandler.saveIslands();
stackedBlocksHandler.saveStackedBlocks();
modulesHandler.getModules().forEach(modulesHandler::unregisterModule);
// Shutdown task is running from another thread, causing closing of inventories to cause errors.
// This check should prevent it.
if (Bukkit.isPrimaryThread()) {
Bukkit.getOnlinePlayers().forEach(player -> {
SuperiorPlayer superiorPlayer = playersHandler.getSuperiorPlayer(player);
player.closeInventory();
superiorPlayer.updateWorldBorder(null);
if (superiorPlayer.hasIslandFlyEnabled()) {
player.setAllowFlight(false);
player.setFlying(false);
}
});
}
} catch (Exception error) {
Log.error(error, "An unexpected error occurred while disabling the plugin:");
} finally {
Log.info("Shutting down calculation task...");
CalcTask.cancelTask();
if (nmsChunks != null)
nmsChunks.shutdown();
Log.info("Shutting down executor");
BukkitExecutor.close();
Log.info("Closing database. This may hang the server. Do not shut it down, or data may get lost.");
dataHandler.closeConnection();
}
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return getGenerator();
}
public Updater getUpdater() {
return updater;
}
public ClassLoader getPluginClassLoader() {
return super.getClassLoader();
}
@SuppressWarnings("deprecation")
private boolean loadNMSAdapter() {
if (ServerVersion.isLessThan(ServerVersion.v1_17)) {
nmsPackageVersion = getServer().getClass().getPackage().getName().split("\\.")[3];
} else {
ReflectMethod<Integer> getDataVersion = new ReflectMethod<>(UnsafeValues.class, "getDataVersion");
int dataVersion = getDataVersion.invoke(Bukkit.getUnsafe());
List<Pair<Integer, String>> versions = Arrays.asList(
new Pair<>(2729, null),
new Pair<>(2730, "v117"),
new Pair<>(2865, "v1181"),
new Pair<>(2975, "v1182"),
new Pair<>(3105, "v119"),
new Pair<>(3117, "v1191"),
new Pair<>(3120, "v1192")
);
for (Pair<Integer, String> versionData : versions) {
if (dataVersion <= versionData.getKey()) {
nmsPackageVersion = versionData.getValue();
break;
}
}
if (nmsPackageVersion == null) {
Log.error("Data version: ", dataVersion);
}
}
if (nmsPackageVersion != null) {
try {
nmsAlgorithms = loadNMSClass("NMSAlgorithmsImpl", nmsPackageVersion);
nmsChunks = loadNMSClass("NMSChunksImpl", nmsPackageVersion);
nmsEntities = loadNMSClass("NMSEntitiesImpl", nmsPackageVersion);
nmsHolograms = loadNMSClass("NMSHologramsImpl", nmsPackageVersion);
nmsPlayers = loadNMSClass("NMSPlayersImpl", nmsPackageVersion);
nmsTags = loadNMSClass("NMSTagsImpl", nmsPackageVersion);
nmsWorld = loadNMSClass("NMSWorldImpl", nmsPackageVersion);
return true;
} catch (Exception error) {
Log.error(error, "An unexpected error occurred while loading nms support:");
}
}
new ManagerLoadException(
"The plugin doesn't support your minecraft version.\n" +
"Please try a different version.",
ManagerLoadException.ErrorLevel.SERVER_SHUTDOWN).printStackTrace();
return false;
}
private <T> T loadNMSClass(String className, String version) throws Exception {
Class<?> nmsClass = Class.forName(String.format("com.bgsoftware.superiorskyblock.nms.%s.%s", version, className));
try {
Constructor<?> constructor = nmsClass.getConstructor(SuperiorSkyblockPlugin.class);
// noinspection unchecked
return (T) constructor.newInstance(this);
} catch (NoSuchMethodException error) {
// noinspection unchecked
return (T) nmsClass.newInstance();
}
}
public ChunkGenerator getGenerator() {
if (worldGenerator == null) {
loadGeneratorFromFile();
if (worldGenerator == null) {
worldGenerator = nmsWorld.createGenerator(plugin);
}
}
return worldGenerator;
}
@SuppressWarnings("ResultOfMethodCallIgnored")
private void loadGeneratorFromFile() {
File generatorFolder = new File(plugin.getDataFolder(), "world-generator");
if (!generatorFolder.isDirectory()) {
generatorFolder.delete();
}
if (!generatorFolder.exists()) {
generatorFolder.mkdirs();
} else {
try {
File[] generatorsFilesList = generatorFolder.listFiles();
if (generatorsFilesList != null) {
for (File file : generatorsFilesList) {
//noinspection deprecation
Class<?> generatorClass = JarFiles.getClass(file.toURL(), ChunkGenerator.class, getClassLoader());
if (generatorClass != null) {
for (Constructor<?> constructor : generatorClass.getConstructors()) {
if (constructor.getParameterCount() == 0) {
worldGenerator = (ChunkGenerator) generatorClass.newInstance();
return;
} else if (constructor.getParameterTypes()[0].equals(JavaPlugin.class) ||
constructor.getParameterTypes()[0].equals(SuperiorSkyblock.class)) {
worldGenerator = (ChunkGenerator) constructor.newInstance(this);
return;
}
}
}
}
}
} catch (Exception error) {
Log.error(error, "An unexpected error occurred while loading the generator:");
}
}
}
private boolean checkScriptEngine() {
return testScriptEngine() || (NashornEngineDownloader.downloadEngine(this) && testScriptEngine());
}
private boolean testScriptEngine() {
try {
scriptEngine.eval("1+1");
return true;
} catch (Exception ex) {
return false;
}
}
public void reloadPlugin(boolean loadGrid) throws ManagerLoadException {
ItemSkulls.readTextures(this);
if (!loadGrid) {
settingsHandler = new SettingsManagerImpl(this);
} else {
commandsHandler.loadData();
modulesHandler.enableModules(ModuleLoadTime.NORMAL);
}
if (!checkScriptEngine()) {
throw new ManagerLoadException(
"It seems like the script engine of the plugin is corrupted.\n" +
"This may occur by one of the following reasons:\n" +
"1. You have a module/plugin that sets a custom script that doesn't work well.\n" +
"2. You're using Java 16 without installing an external module engine.\n" +
"If that's the case, check out the following link:\n" +
"https://github.com/BG-Software-LLC/SuperiorSkyblock2-NashornEngine",
ManagerLoadException.ErrorLevel.SERVER_SHUTDOWN);
}
blockValuesHandler.loadData();
upgradesHandler.loadData();
rolesHandler.loadData();
Message.reload();
if (loadGrid) {
playersHandler.loadData();
gridHandler.loadData();
} else {
BukkitExecutor.sync(gridHandler::updateSpawn, 1L);
gridHandler.syncUpgrades();
}
schematicsHandler.loadData();
providersHandler.loadData();
menusHandler.loadData();
missionsHandler.loadData();
if (loadGrid) {
dataHandler.loadData();
stackedBlocksHandler.loadData();
plugin.getGrid().setForceSort(true);
SortingType.values().forEach(gridHandler::sortIslands);
modulesHandler.loadModulesData(this);
modulesHandler.enableModules(ModuleLoadTime.AFTER_MODULE_DATA_LOAD);
} else {
modulesHandler.reloadModules(this);
}
BukkitExecutor.sync(() -> {
for (Player player : Bukkit.getOnlinePlayers()) {
SuperiorPlayer superiorPlayer = playersHandler.getSuperiorPlayer(player);
Island island = gridHandler.getIslandAt(player.getLocation());
superiorPlayer.updateWorldBorder(island);
if (island != null)
island.applyEffects(superiorPlayer);
}
});
CalcTask.startTask();
}
@Override
public GridManagerImpl getGrid() {
return gridHandler;
}
@Override
public StackedBlocksManagerImpl getStackedBlocks() {
return stackedBlocksHandler;
}
@Override
public BlockValuesManagerImpl getBlockValues() {
return blockValuesHandler;
}
@Override
public SchematicsManagerImpl getSchematics() {
return schematicsHandler;
}
@Override
public PlayersManagerImpl getPlayers() {
return playersHandler;
}
@Override
public RolesManagerImpl getRoles() {
return rolesHandler;
}
@Override
public MissionsManagerImpl getMissions() {
return missionsHandler;
}
@Override
public MenusManagerImpl getMenus() {
return menusHandler;
}
@Override
public KeysManagerImpl getKeys() {
return keysHandler;
}
@Override
public ProvidersManagerImpl getProviders() {
return providersHandler;
}
@Override
public UpgradesManagerImpl getUpgrades() {
return upgradesHandler;
}
@Override
public CommandsManagerImpl getCommands() {
return commandsHandler;
}
@Override
public SettingsManagerImpl getSettings() {
return settingsHandler;
}
@Override
public FactoriesManagerImpl getFactory() {
return factoriesHandler;
}
@Override
public ModulesManagerImpl getModules() {
return modulesHandler;
}
@Override
public IScriptEngine getScriptEngine() {
return scriptEngine;
}
@Override
public void setScriptEngine(@Nullable IScriptEngine scriptEngine) {
this.scriptEngine = scriptEngine == null ? EnginesFactory.createDefaultEngine() : scriptEngine;
}
@Override
@Deprecated
public WorldEventsManager getWorldEventsManager() {
return getListener(ChunksListener.class).get().getWorldEventsManager();
}
@Override
@Deprecated
public void setWorldEventsManager(@Nullable WorldEventsManager worldEventsManager) {
getListener(ChunksListener.class).get().setWorldEventsManager(worldEventsManager);
}
public EventsBus getEventsBus() {
return eventsBus;
}
public ServicesHandler getServices() {
return servicesHandler;
}
public void setSettings(SettingsManagerImpl settingsHandler) {
this.settingsHandler = settingsHandler;
}
public NMSAlgorithms getNMSAlgorithms() {
return nmsAlgorithms;
}
public NMSChunks getNMSChunks() {
return nmsChunks;
}
public NMSDragonFight getNMSDragonFight() {
if (nmsDragonFight == null) {
try {
nmsDragonFight = settingsHandler.getWorlds().getEnd().isDragonFight() ?
loadNMSClass("NMSDragonFightImpl", nmsPackageVersion) : new NMSDragonFightImpl();
} catch (Exception error) {
nmsDragonFight = new NMSDragonFightImpl();
}
}
return nmsDragonFight;
}
public NMSEntities getNMSEntities() {
return nmsEntities;
}
public NMSHolograms getNMSHolograms() {
return nmsHolograms;
}
public NMSPlayers getNMSPlayers() {
return nmsPlayers;
}
public NMSTags getNMSTags() {
return nmsTags;
}
public NMSWorld getNMSWorld() {
return nmsWorld;
}
public <E extends Listener> Singleton<E> getListener(Class<E> listenerClass) {
return bukkitListeners.getListener(listenerClass);
}
public String getFileName() {
return getFile().getName();
}
private void loadUpgradeCostLoaders() {
upgradesHandler.registerUpgradeCostLoader("money", new VaultUpgradeCostLoader());
upgradesHandler.registerUpgradeCostLoader("placeholders", new PlaceholdersUpgradeCostLoader());
}
private long calculateMaxPossibleIslands() {
int islandDistance = settingsHandler.getMaxIslandSize() * 3;
long worldDistance = nmsAlgorithms.getMaxWorldSize() * 2L;
long islandsPerSide = worldDistance / islandDistance;
return islandsPerSide * islandsPerSide;
}
}