Enables game modes addons first (#1368)

This commit is contained in:
tastybento 2020-05-26 01:04:53 -07:00 committed by GitHub
parent fdb4df3d93
commit 502aaa87a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -173,8 +173,11 @@ public class AddonsManager {
*/ */
public void enableAddons() { public void enableAddons() {
if (getLoadedAddons().isEmpty()) return; if (getLoadedAddons().isEmpty()) return;
plugin.log("Enabling addons..."); plugin.log("Enabling game mode addons...");
getLoadedAddons().forEach(this::enableAddon); // Enable GameModes first, then other addons
getLoadedAddons().stream().filter(GameModeAddon.class::isInstance).forEach(this::enableAddon);
plugin.log("Enabling other addons...");
getLoadedAddons().stream().filter(g -> !(g instanceof GameModeAddon)).forEach(this::enableAddon);
// Set perms for enabled addons // Set perms for enabled addons
this.getEnabledAddons().forEach(this::setPerms); this.getEnabledAddons().forEach(this::setPerms);
plugin.log("Addons successfully enabled."); plugin.log("Addons successfully enabled.");
@ -217,6 +220,7 @@ public class AddonsManager {
* @param addon addon * @param addon addon
*/ */
private void enableAddon(Addon addon) { private void enableAddon(Addon addon) {
plugin.log("Enabling " + addon.getDescription().getName() + "...");
try { try {
// If this is a GameModeAddon create the worlds, register it and load the blueprints // If this is a GameModeAddon create the worlds, register it and load the blueprints
if (addon instanceof GameModeAddon) { if (addon instanceof GameModeAddon) {
@ -241,7 +245,6 @@ public class AddonsManager {
} }
new AddonEvent().builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build(); new AddonEvent().builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build();
addon.setState(Addon.State.ENABLED); addon.setState(Addon.State.ENABLED);
plugin.log("Enabling " + addon.getDescription().getName() + "...");
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) { } catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
// Looks like the addon is incompatible, because it tries to refer to missing classes... // Looks like the addon is incompatible, because it tries to refer to missing classes...
handleAddonIncompatibility(addon); handleAddonIncompatibility(addon);