From 56c1baa8306e10002faf945a6d0ee6d5198c2548 Mon Sep 17 00:00:00 2001 From: Vankka Date: Wed, 4 Dec 2024 21:18:01 +0200 Subject: [PATCH] Handle integrations loading later better --- .../discordsrv/bukkit/BukkitDiscordSRV.java | 1 + .../bukkit/DiscordSRVBukkitBootstrap.java | 21 +-------- .../integration/EssentialsXIntegration.java | 4 +- .../PlaceholderAPIIntegration.java | 2 +- .../bukkit/integration/VaultIntegration.java | 2 +- .../chat/ChattyChatIntegration.java | 4 +- .../chat/GriefPreventionChatIntegration.java | 5 +- .../integration/chat/LunaChatIntegration.java | 4 +- .../chat/McMMOChatIntegration.java | 4 +- .../chat/TownyChatIntegration.java | 4 +- .../chat/VentureChatIntegration.java | 4 +- .../bukkit/player/BukkitPlayerProvider.java | 6 +++ .../bukkit/plugin/BukkitPluginManager.java | 29 +++++++++++- .../bungee/player/BungeePlayerProvider.java | 5 ++ .../discordsrv/common/AbstractDiscordSRV.java | 4 ++ .../provider/AbstractPlayerProvider.java | 1 + .../common/core/module/ModuleManager.java | 18 +++++++- .../core/module/type/PluginIntegration.java | 8 ++-- .../IntegrationLifecycleEvent.java | 46 +++++++++++++++++++ .../integration/LuckPermsIntegration.java | 2 +- .../com/discordsrv/common/MockDiscordSRV.java | 5 ++ .../player/VelocityPlayerProvider.java | 5 ++ .../plugin/VelocityPluginManager.java | 5 +- 23 files changed, 144 insertions(+), 45 deletions(-) create mode 100644 common/src/main/java/com/discordsrv/common/events/integration/IntegrationLifecycleEvent.java diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java index 582ecad4..eb345690 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/BukkitDiscordSRV.java @@ -240,6 +240,7 @@ public class BukkitDiscordSRV extends AbstractDiscordSRV this.discordSRV = new BukkitDiscordSRV(this)); + if (discordSRV == null) return; - boolean isFolia = false; - try { - Class.forName("io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler"); - isFolia = true; - } catch (ClassNotFoundException ignored) {} - - if (isFolia) { - if (discordSRV != null) { - discordSRV.invokeServerStarted(); - } - return; - } - - // Run a task on the main thread 1 tick later, so essentially when the server has finished booting - getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> { - if (discordSRV != null) { - discordSRV.invokeServerStarted(); - } - }, 1L); + discordSRV.scheduler().runOnMainThreadLaterInTicks(() -> discordSRV.invokeServerStarted(), 1); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java index 4c903ab2..479a542b 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/EssentialsXIntegration.java @@ -60,7 +60,7 @@ public class EssentialsXIntegration } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "Essentials"; } @@ -164,7 +164,7 @@ public class EssentialsXIntegration @Override public @NotNull String getOwnerName() { - return getIntegrationName(); + return getIntegrationId(); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/PlaceholderAPIIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/PlaceholderAPIIntegration.java index fbaf3f77..2546a4fa 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/PlaceholderAPIIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/PlaceholderAPIIntegration.java @@ -50,7 +50,7 @@ public class PlaceholderAPIIntegration extends PluginIntegration implem } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "Vault"; } diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/ChattyChatIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/ChattyChatIntegration.java index 05d4400d..02a7effa 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/ChattyChatIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/ChattyChatIntegration.java @@ -50,7 +50,7 @@ public class ChattyChatIntegration extends PluginIntegration i } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "Chatty"; } @@ -115,7 +115,7 @@ public class ChattyChatIntegration extends PluginIntegration i @Override public @NotNull String getOwnerName() { - return getIntegrationName(); + return getIntegrationId(); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java index a4f767ad..ae8756d2 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/GriefPreventionChatIntegration.java @@ -35,7 +35,7 @@ public class GriefPreventionChatIntegration extends PluginIntegration imp } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "LunaChat"; } @@ -134,7 +134,7 @@ public class LunaChatIntegration extends PluginIntegration imp @Override public @NotNull String getOwnerName() { - return getIntegrationName(); + return getIntegrationId(); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/McMMOChatIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/McMMOChatIntegration.java index de09c2ad..4d79f1f3 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/McMMOChatIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/McMMOChatIntegration.java @@ -55,7 +55,7 @@ public class McMMOChatIntegration extends PluginIntegration im } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "mcMMO"; } @@ -130,7 +130,7 @@ public class McMMOChatIntegration extends PluginIntegration im @Override public @NotNull String getOwnerName() { - return getIntegrationName(); + return getIntegrationId(); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/TownyChatIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/TownyChatIntegration.java index 18a5bf26..d9df00f4 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/TownyChatIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/TownyChatIntegration.java @@ -51,7 +51,7 @@ public class TownyChatIntegration extends PluginIntegration im } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "TownyChat"; } @@ -125,7 +125,7 @@ public class TownyChatIntegration extends PluginIntegration im @Override public @NotNull String getOwnerName() { - return getIntegrationName(); + return getIntegrationId(); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/VentureChatIntegration.java b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/VentureChatIntegration.java index 981f50b4..5131f7da 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/VentureChatIntegration.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/integration/chat/VentureChatIntegration.java @@ -54,7 +54,7 @@ public class VentureChatIntegration extends PluginIntegration } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "VentureChat"; } @@ -128,7 +128,7 @@ public class VentureChatIntegration extends PluginIntegration @Override public @NotNull String getOwnerName() { - return getIntegrationName(); + return getIntegrationId(); } @Override diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java index d536f841..83fea5e2 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java @@ -26,6 +26,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; @@ -53,6 +54,11 @@ public class BukkitPlayerProvider extends ServerPlayerProvider abstractModule = getAbstract(module); + if (abstractModule instanceof PluginIntegration + && ((PluginIntegration) abstractModule).getIntegrationId().equals(integrationIdentifier)) { + enableOrDisableAsNeeded(abstractModule, discordSRV.isReady(), true); + } + } + } + public List reload() { return reloadAndEnableModules(true); } @@ -240,7 +254,7 @@ public class ModuleManager { return results; } - private List enableOrDisableAsNeeded(AbstractModule module, boolean isReady, boolean reload) { + private List enableOrDisableAsNeeded(AbstractModule module, boolean isReady, boolean mayReload) { boolean canBeEnabled = isReady || module.canEnableBeforeReady(); if (!canBeEnabled) { return Collections.emptyList(); @@ -278,7 +292,7 @@ public class ModuleManager { List results = enable(module); if (results != null) { reloadResults.addAll(results); - } else if (reload) { + } else if (mayReload) { reloadResults.addAll(reload(module)); } } diff --git a/common/src/main/java/com/discordsrv/common/core/module/type/PluginIntegration.java b/common/src/main/java/com/discordsrv/common/core/module/type/PluginIntegration.java index 95d33116..063f33ce 100644 --- a/common/src/main/java/com/discordsrv/common/core/module/type/PluginIntegration.java +++ b/common/src/main/java/com/discordsrv/common/core/module/type/PluginIntegration.java @@ -38,16 +38,16 @@ public abstract class PluginIntegration
extends AbstractM * @return the id (when available) or name of the plugin or mod */ @NotNull - public abstract String getIntegrationName(); + public abstract String getIntegrationId(); @Override @MustBeInvokedByOverriders public boolean isEnabled() { - String integrationName = getIntegrationName(); - if (discordSRV.config().integrations.disabledIntegrations.contains(integrationName)) { + String integrationId = getIntegrationId(); + if (discordSRV.config().integrations.disabledIntegrations.contains(integrationId)) { return false; } - if (!discordSRV.pluginManager().isPluginEnabled(integrationName)) { + if (!discordSRV.pluginManager().isPluginEnabled(integrationId)) { return false; } return super.isEnabled(); diff --git a/common/src/main/java/com/discordsrv/common/events/integration/IntegrationLifecycleEvent.java b/common/src/main/java/com/discordsrv/common/events/integration/IntegrationLifecycleEvent.java new file mode 100644 index 00000000..920024d7 --- /dev/null +++ b/common/src/main/java/com/discordsrv/common/events/integration/IntegrationLifecycleEvent.java @@ -0,0 +1,46 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2024 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.discordsrv.common.events.integration; + +import com.discordsrv.api.events.Event; + +public class IntegrationLifecycleEvent implements Event { + + private final String integrationIdentifier; + private final Type type; + + public IntegrationLifecycleEvent(String integrationIdentifier, Type type) { + this.integrationIdentifier = integrationIdentifier; + this.type = type; + } + + public String integrationIdentifier() { + return integrationIdentifier; + } + + public Type getType() { + return type; + } + + public enum Type { + ENABLE, + DISABLE, + RELOAD + } +} diff --git a/common/src/main/java/com/discordsrv/common/integration/LuckPermsIntegration.java b/common/src/main/java/com/discordsrv/common/integration/LuckPermsIntegration.java index d024bc19..ab628b32 100644 --- a/common/src/main/java/com/discordsrv/common/integration/LuckPermsIntegration.java +++ b/common/src/main/java/com/discordsrv/common/integration/LuckPermsIntegration.java @@ -66,7 +66,7 @@ public class LuckPermsIntegration extends PluginIntegration implemen } @Override - public @NotNull String getIntegrationName() { + public @NotNull String getIntegrationId() { return "LuckPerms"; } diff --git a/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java b/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java index 5009476f..055cba33 100644 --- a/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java +++ b/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java @@ -185,6 +185,11 @@ public class MockDiscordSRV extends AbstractDiscordSRV