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 ae7d883e..33bbdeda 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 @@ -21,7 +21,6 @@ import com.willfp.eco.core.gui.menu.MenuBuilder; import com.willfp.eco.core.gui.menu.MenuType; import com.willfp.eco.core.gui.slot.SlotBuilder; import com.willfp.eco.core.gui.slot.functional.SlotProvider; -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; @@ -138,10 +137,9 @@ public interface Eco { * Create a PAPI integration. * * @param plugin The plugin. - * @return The integration. */ @NotNull - PlaceholderIntegration createPAPIIntegration(@NotNull EcoPlugin plugin); + void createPAPIIntegration(@NotNull EcoPlugin plugin); /** * Create a proxy factory. 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 501281d0..463a83cb 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 @@ -13,7 +13,6 @@ import com.willfp.eco.core.factory.MetadataValueFactory; import com.willfp.eco.core.factory.NamespacedKeyFactory; import com.willfp.eco.core.factory.RunnableFactory; import com.willfp.eco.core.integrations.IntegrationLoader; -import com.willfp.eco.core.integrations.placeholder.PlaceholderManager; import com.willfp.eco.core.proxy.ProxyFactory; import com.willfp.eco.core.scheduling.Scheduler; import com.willfp.eco.core.web.UpdateChecker; @@ -375,8 +374,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { .collect(Collectors.toSet()); if (enabledPlugins.contains("PlaceholderAPI".toLowerCase())) { - this.loadedIntegrations.add("PlaceholderAPI"); - PlaceholderManager.addIntegration(Eco.get().createPAPIIntegration(this)); + Eco.get().createPAPIIntegration(this); } this.loadIntegrationLoaders().forEach(integrationLoader -> { @@ -386,6 +384,8 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { } }); + this.loadedIntegrations.removeIf(pl -> pl.equalsIgnoreCase(this.getName())); + this.getLogger().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations())); Prerequisite.update(); diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java index 89def921..112f7899 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java @@ -70,7 +70,7 @@ public final class PlaceholderManager { /** * The default PlaceholderAPI pattern; brought in for compatibility. */ - private static final Pattern PATTERN = Pattern.compile("[%]([^%]+)[%]"); + private static final Pattern PATTERN = Pattern.compile("[%]([^% ]+)[%]"); /** * Register a new placeholder integration. diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PlaceholderIntegrationPAPI.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt similarity index 50% rename from eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PlaceholderIntegrationPAPI.kt rename to eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt index e6d05e51..8a96e3cd 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PlaceholderIntegrationPAPI.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/integrations/PAPIExpansion.kt @@ -1,13 +1,11 @@ package com.willfp.eco.internal.integrations import com.willfp.eco.core.EcoPlugin -import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration import com.willfp.eco.core.integrations.placeholder.PlaceholderManager -import me.clip.placeholderapi.PlaceholderAPI import me.clip.placeholderapi.expansion.PlaceholderExpansion import org.bukkit.entity.Player -class PlaceholderIntegrationPAPI(private val plugin: EcoPlugin) : PlaceholderExpansion(), PlaceholderIntegration { +class PAPIExpansion(private val plugin: EcoPlugin) : PlaceholderExpansion() { override fun persist(): Boolean { return true } @@ -34,29 +32,4 @@ class PlaceholderIntegrationPAPI(private val plugin: EcoPlugin) : PlaceholderExp ): String { return PlaceholderManager.getResult(player, identifier, plugin) } - - override fun registerIntegration() { - register() - } - - override fun getPluginName(): String { - return "PlaceholderAPI" - } - - override fun translate( - text: String, - player: Player? - ): String { - return PlaceholderAPI.setPlaceholders(player, text) - } - - override fun findPlaceholdersIn(text: String): MutableList { - val placeholders = mutableListOf() - val matcher = PlaceholderAPI.getPlaceholderPattern().matcher(text) - while (matcher.find()) { - placeholders.add(matcher.group()) - } - - return placeholders - } -} \ 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 0192bb48..4c742a4c 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 @@ -34,7 +34,7 @@ import com.willfp.eco.internal.gui.MergedStateMenu import com.willfp.eco.internal.gui.menu.EcoMenuBuilder import com.willfp.eco.internal.gui.menu.renderedInventory import com.willfp.eco.internal.gui.slot.EcoSlotBuilder -import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI +import com.willfp.eco.internal.integrations.PAPIExpansion import com.willfp.eco.internal.logging.EcoLogger import com.willfp.eco.internal.proxy.EcoProxyFactory import com.willfp.eco.internal.scheduling.EcoScheduler @@ -114,8 +114,9 @@ class EcoImpl : EcoSpigotPlugin(), Eco { override fun createLogger(plugin: EcoPlugin) = EcoLogger(plugin) - override fun createPAPIIntegration(plugin: EcoPlugin) = - PlaceholderIntegrationPAPI(plugin) + override fun createPAPIIntegration(plugin: EcoPlugin) { + PAPIExpansion(plugin) + } override fun getEcoPlugin(): EcoPlugin = this diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 2c24d36e..e4cec9b7 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -14,6 +14,7 @@ import com.willfp.eco.core.integrations.customitems.CustomItemsManager import com.willfp.eco.core.integrations.economy.EconomyManager import com.willfp.eco.core.integrations.hologram.HologramManager import com.willfp.eco.core.integrations.mcmmo.McmmoManager +import com.willfp.eco.core.integrations.placeholder.PlaceholderManager import com.willfp.eco.core.integrations.shop.ShopManager import com.willfp.eco.core.items.Items import com.willfp.eco.internal.entities.EntityArgParserAdult @@ -106,6 +107,7 @@ import com.willfp.eco.internal.spigot.integrations.hologram.HologramDecentHologr import com.willfp.eco.internal.spigot.integrations.hologram.HologramHolographicDisplays import com.willfp.eco.internal.spigot.integrations.mcmmo.McmmoIntegrationImpl import com.willfp.eco.internal.spigot.integrations.multiverseinventories.MultiverseInventoriesIntegration +import com.willfp.eco.internal.spigot.integrations.placeholder.PlaceholderIntegrationPAPI import com.willfp.eco.internal.spigot.integrations.shop.ShopDeluxeSellwands import com.willfp.eco.internal.spigot.integrations.shop.ShopEconomyShopGUI import com.willfp.eco.internal.spigot.integrations.shop.ShopShopGuiPlus @@ -311,6 +313,9 @@ abstract class EcoSpigotPlugin : EcoPlugin() { } }, + // Placeholder + IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) }, + // Misc IntegrationLoader("mcMMO") { McmmoManager.register(McmmoIntegrationImpl()) }, IntegrationLoader("Multiverse-Inventories") { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/placeholder/PlaceholderIntegrationPAPI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/placeholder/PlaceholderIntegrationPAPI.kt new file mode 100644 index 00000000..badc75fc --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/placeholder/PlaceholderIntegrationPAPI.kt @@ -0,0 +1,36 @@ +package com.willfp.eco.internal.spigot.integrations.placeholder + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration +import me.clip.placeholderapi.PlaceholderAPI +import org.bukkit.entity.Player +import java.util.regex.Pattern + +class PlaceholderIntegrationPAPI : PlaceholderIntegration { + private val pattern = Pattern.compile("[%]([^% ]+)[%]") + + override fun registerIntegration() { + // Do nothing. + } + + override fun getPluginName(): String { + return "PlaceholderAPI" + } + + override fun translate( + text: String, + player: Player? + ): String { + return PlaceholderAPI.setPlaceholders(player, text) + } + + override fun findPlaceholdersIn(text: String): MutableList { + val placeholders = mutableListOf() + val matcher = pattern.matcher(text) + while (matcher.find()) { + placeholders.add(matcher.group()) + } + + return placeholders + } +}