diff --git a/eco-api/src/main/java/com/willfp/eco/core/Eco.java b/eco-api/src/main/java/com/willfp/eco/core/Eco.java index 6d7592a9..c9f8d502 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/Eco.java +++ b/eco-api/src/main/java/com/willfp/eco/core/Eco.java @@ -25,7 +25,6 @@ import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration; import com.willfp.eco.core.items.TestableItem; import com.willfp.eco.core.placeholder.AdditionalPlayer; import com.willfp.eco.core.placeholder.PlaceholderInjectable; -import com.willfp.eco.core.proxy.Cleaner; import com.willfp.eco.core.proxy.ProxyFactory; import com.willfp.eco.core.scheduling.Scheduler; import net.kyori.adventure.platform.bukkit.BukkitAudiences; @@ -269,12 +268,11 @@ public interface Eco { @NotNull Menu additional); /** - * Get cleaner. + * Clean up ClassLoader (etc.) to allow PlugMan support. * - * @return The cleaner. + * @param plugin The plugin to clean up. */ - @NotNull - Cleaner getCleaner(); + void clean(@NotNull EcoPlugin plugin); /** * Add new plugin. diff --git a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java index 44160f43..501281d0 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java +++ b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java @@ -81,12 +81,12 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { private final Set loadedIntegrations = new HashSet<>(); /** - * The internal plugin scheduler. + * The plugin scheduler. */ private final Scheduler scheduler; /** - * The internal plugin Event Manager. + * The plugin Event Manager. */ private final EventManager eventManager; @@ -101,17 +101,17 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { private final LangYml langYml; /** - * The internal factory to produce {@link org.bukkit.NamespacedKey}s. + * The factory to produce {@link org.bukkit.NamespacedKey}s. */ private final NamespacedKeyFactory namespacedKeyFactory; /** - * The internal factory to produce {@link org.bukkit.metadata.FixedMetadataValue}s. + * The factory to produce {@link org.bukkit.metadata.FixedMetadataValue}s. */ private final MetadataValueFactory metadataValueFactory; /** - * The internal factory to produce {@link com.willfp.eco.core.scheduling.RunnableTask}s. + * The factory to produce {@link com.willfp.eco.core.scheduling.RunnableTask}s. */ private final RunnableFactory runnableFactory; @@ -283,11 +283,11 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { if (Eco.get() == null && this instanceof Eco) { /* - This code is only ever called by EcoSpigotPlugin (EcoHandler) - as it's the first plugin to load, and it is a handler. + This code is only ever called by EcoSpigotPlugin (EcoImpl) + as it's the first plugin to load, and it's an instance of eco. - Any other plugins will never call this code as the handler - will have already been initialized. + Any other plugins will never call this code as eco will have already + been initialized. */ Eco.Instance.set((Eco) this); @@ -435,7 +435,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { } this.getLogger().info("Cleaning up..."); - Eco.get().getCleaner().clean(this); + Eco.get().clean(this); } /** diff --git a/eco-api/src/main/java/com/willfp/eco/core/extensions/ExtensionLoader.java b/eco-api/src/main/java/com/willfp/eco/core/extensions/ExtensionLoader.java index daa57073..08da55d4 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/extensions/ExtensionLoader.java +++ b/eco-api/src/main/java/com/willfp/eco/core/extensions/ExtensionLoader.java @@ -3,7 +3,7 @@ package com.willfp.eco.core.extensions; import java.util.Set; /** - * Internal component to manage loading and unloading extensions. + * Manages the loading and unloading of extensions for a particular plugin. */ public interface ExtensionLoader { /** diff --git a/eco-api/src/main/java/com/willfp/eco/core/proxy/Cleaner.java b/eco-api/src/main/java/com/willfp/eco/core/proxy/Cleaner.java index 9d4c628d..a872f09e 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/proxy/Cleaner.java +++ b/eco-api/src/main/java/com/willfp/eco/core/proxy/Cleaner.java @@ -7,7 +7,10 @@ import org.jetbrains.annotations.NotNull; * A cleaner is an internal component to fix classloader errors. *

* Important to allow for PlugMan/ServerUtils support. + * + * @deprecated No reason for this to be in the API. */ +@Deprecated(since = "6.43.0", forRemoval = true) public interface Cleaner { /** * Clean up classes left over from plugin. diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/EcoCleaner.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/EcoCleaner.kt deleted file mode 100644 index ed9b451c..00000000 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/EcoCleaner.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.willfp.eco.internal - -import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.items.Items -import com.willfp.eco.core.proxy.Cleaner -import com.willfp.eco.internal.proxy.EcoProxyFactory -import java.net.URLClassLoader - -class EcoCleaner: Cleaner { - override fun clean(plugin: EcoPlugin) { - if (plugin.proxyPackage.isNotEmpty()) { - val factory = plugin.proxyFactory as EcoProxyFactory - factory.clean() - } - - Plugins.LOADED_ECO_PLUGINS.remove(plugin.name.lowercase()) - - for (customItem in Items.getCustomItems()) { - if (customItem.key.namespace.equals(plugin.name.lowercase(), ignoreCase = true)) { - Items.removeCustomItem(customItem.key) - } - } - - val classLoader = plugin::class.java.classLoader - - if (classLoader is URLClassLoader) { - classLoader.close() - } - - System.gc() - } -} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt index 68d1c337..8e4bb8f4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt @@ -11,9 +11,9 @@ import com.willfp.eco.core.data.keys.PersistentDataKey import com.willfp.eco.core.gui.menu.Menu import com.willfp.eco.core.gui.menu.MenuType import com.willfp.eco.core.gui.slot.functional.SlotProvider +import com.willfp.eco.core.items.Items import com.willfp.eco.core.placeholder.AdditionalPlayer import com.willfp.eco.core.placeholder.PlaceholderInjectable -import com.willfp.eco.internal.EcoCleaner import com.willfp.eco.internal.EcoPropsParser import com.willfp.eco.internal.config.EcoConfigHandler import com.willfp.eco.internal.config.EcoConfigSection @@ -21,6 +21,7 @@ import com.willfp.eco.internal.config.EcoLoadableConfig import com.willfp.eco.internal.config.EcoUpdatableConfig import com.willfp.eco.internal.config.toMap import com.willfp.eco.internal.drops.EcoDropQueue +import com.willfp.eco.internal.drops.EcoFastCollatedDropQueue import com.willfp.eco.internal.events.EcoEventManager import com.willfp.eco.internal.extensions.EcoExtensionLoader import com.willfp.eco.internal.factory.EcoMetadataValueFactory @@ -42,7 +43,6 @@ import com.willfp.eco.internal.spigot.data.EcoProfileHandler import com.willfp.eco.internal.spigot.data.KeyRegistry import com.willfp.eco.internal.spigot.data.storage.HandlerType import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler -import com.willfp.eco.internal.spigot.items.EcoSNBTHandler import com.willfp.eco.internal.spigot.math.evaluateExpression import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy @@ -50,6 +50,7 @@ import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy import com.willfp.eco.internal.spigot.proxy.ExtendedPersistentDataContainerFactoryProxy import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy import com.willfp.eco.internal.spigot.proxy.MiniMessageTranslatorProxy +import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy import com.willfp.eco.internal.spigot.proxy.SkullProxy import com.willfp.eco.internal.spigot.proxy.TPSProxy import net.kyori.adventure.platform.bukkit.BukkitAudiences @@ -62,30 +63,27 @@ import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.SkullMeta import org.bukkit.persistence.PersistentDataContainer +import java.net.URLClassLoader import java.util.UUID @Suppress("UNUSED") class EcoImpl : EcoSpigotPlugin(), Eco { - private val loaded = mutableMapOf() - - init { - getProxy(CommonsInitializerProxy::class.java).init() - } - override val dataYml = DataYml(this) - private val cleaner = EcoCleaner() - - private var adventure: BukkitAudiences? = if (!Prerequisite.HAS_PAPER.isMet) { - BukkitAudiences.create(this) - } else null - override val profileHandler = EcoProfileHandler( HandlerType.valueOf(this.configYml.getString("data-handler").uppercase()), this ) - private val snbtHandler = EcoSNBTHandler(this) + private val loadedPlugins = mutableMapOf() + + init { + getProxy(CommonsInitializerProxy::class.java).init() + } + + private var adventure: BukkitAudiences? = if (!Prerequisite.HAS_PAPER.isMet) { + BukkitAudiences.create(this) + } else null @Suppress("RedundantNullableReturnType") private val keyFactory: InternalNamespacedKeyFactory? = @@ -173,8 +171,8 @@ class EcoImpl : EcoSpigotPlugin(), Eco { return config } - override fun createDropQueue(player: Player) = - EcoDropQueue(player) + override fun createDropQueue(player: Player) = if (this.configYml.getBool("use-fast-collated-drops")) + EcoFastCollatedDropQueue(player) else EcoDropQueue(player) override fun getPersistentDataKeyFrom(namespacedKey: NamespacedKey) = KeyRegistry.getKeyFrom(namespacedKey) @@ -194,21 +192,41 @@ class EcoImpl : EcoSpigotPlugin(), Eco { override fun blendMenuState(base: Menu, additional: Menu) = MergedStateMenu(base, additional) - override fun getCleaner(): EcoCleaner = - cleaner + override fun clean(plugin: EcoPlugin) { + if (plugin.proxyPackage.isNotEmpty()) { + val factory = plugin.proxyFactory as EcoProxyFactory + factory.clean() + } + + loadedPlugins.remove(plugin.name.lowercase()) + + for (customItem in Items.getCustomItems()) { + if (customItem.key.namespace.equals(plugin.name.lowercase(), ignoreCase = true)) { + Items.removeCustomItem(customItem.key) + } + } + + val classLoader = plugin::class.java.classLoader + + if (classLoader is URLClassLoader) { + classLoader.close() + } + + System.gc() + } override fun createProxyFactory(plugin: EcoPlugin) = EcoProxyFactory(plugin) override fun addNewPlugin(plugin: EcoPlugin) { - loaded[plugin.name.lowercase()] = plugin + loadedPlugins[plugin.name.lowercase()] = plugin } override fun getLoadedPlugins(): List = - loaded.keys.toList() + loadedPlugins.keys.toList() override fun getPluginByName(name: String): EcoPlugin? = - loaded[name.lowercase()] + loadedPlugins[name.lowercase()] override fun createFastItemStack(itemStack: ItemStack) = getProxy(FastItemStackFactoryProxy::class.java).create(itemStack) @@ -257,13 +275,13 @@ class EcoImpl : EcoSpigotPlugin(), Eco { getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).newPdc() override fun toSNBT(itemStack: ItemStack) = - snbtHandler.toSNBT(itemStack) + getProxy(SNBTConverterProxy::class.java).toSNBT(itemStack) override fun fromSNBT(snbt: String) = - snbtHandler.fromSNBT(snbt) + getProxy(SNBTConverterProxy::class.java).fromSNBT(snbt) override fun testableItemFromSNBT(snbt: String) = - snbtHandler.createTestable(snbt) + getProxy(SNBTConverterProxy::class.java).makeSNBTTestable(snbt) override fun getSkullTexture(meta: SkullMeta): String? = getProxy(SkullProxy::class.java).getSkullTexture(meta) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt deleted file mode 100644 index 2ebaf307..00000000 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.willfp.eco.internal.spigot.items - -import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.items.TestableItem -import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy -import org.bukkit.inventory.ItemStack - -class EcoSNBTHandler( - private val plugin: EcoPlugin -) { - fun fromSNBT(snbt: String): ItemStack? = - plugin.getProxy(SNBTConverterProxy::class.java).fromSNBT(snbt) - - fun toSNBT(itemStack: ItemStack): String = - plugin.getProxy(SNBTConverterProxy::class.java).toSNBT(itemStack) - - fun createTestable(snbt: String): TestableItem = - plugin.getProxy(SNBTConverterProxy::class.java).makeSNBTTestable(snbt) -} \ No newline at end of file