diff --git a/build.gradle b/build.gradle index defe7b6..c665aba 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { } group "de.randombyte" -version "2.0" +version "2.1" repositories { jcenter() diff --git a/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt b/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt index 85df21d..f8574f4 100644 --- a/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt +++ b/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt @@ -23,8 +23,6 @@ import de.randombyte.commandutils.executeonserverstartup.ServerStartupListener import de.randombyte.commandutils.service.CommandUtilsService import de.randombyte.commandutils.service.CommandUtilsServiceImpl import de.randombyte.kosp.extensions.toText -import de.randombyte.kosp.getServiceOrFail -import me.rojo8399.placeholderapi.PlaceholderService import org.bstats.sponge.Metrics import org.slf4j.Logger import org.spongepowered.api.Sponge @@ -54,7 +52,7 @@ class CommandUtils @Inject constructor( companion object { const val ID = "command-utils" const val NAME = "CommandUtils" - const val VERSION = "2.0" + const val VERSION = "2.0.5" const val AUTHOR = "RandomByte" const val PLACEHOLDER_API_ID = "placeholderapi" @@ -77,13 +75,10 @@ class CommandUtils @Inject constructor( get() = LAZY_INSTANCE.value } - var placeholderApi: PlaceholderService? = null - val configAccessor = ConfigAccessor(configPath) @Listener fun onInit(event: GameInitializationEvent) { - loadPlaceholderApi() ConfigUpdater.from1_8(configAccessor, logger) configAccessor.reloadAll() registerCommands() @@ -195,11 +190,4 @@ class CommandUtils @Inject constructor( .build(), "commandutils", "cmdutils", "cu") } - - private fun loadPlaceholderApi() { - if (Sponge.getPluginManager().getPlugin(PLACEHOLDER_API_ID).isPresent) { - placeholderApi = getServiceOrFail(PlaceholderService::class, - failMessage = "Failed getting the placeholder API despite the plugin itself being loaded!") - } - } } \ No newline at end of file diff --git a/src/main/kotlin/de/randombyte/commandutils/utils.kt b/src/main/kotlin/de/randombyte/commandutils/utils.kt index 9018903..2b1629e 100644 --- a/src/main/kotlin/de/randombyte/commandutils/utils.kt +++ b/src/main/kotlin/de/randombyte/commandutils/utils.kt @@ -2,6 +2,7 @@ package de.randombyte.commandutils import de.randombyte.kosp.extensions.executeCommand import de.randombyte.kosp.extensions.replace +import de.randombyte.kosp.getServiceOrFail import me.rojo8399.placeholderapi.PlaceholderService import org.spongepowered.api.Sponge import org.spongepowered.api.command.CommandResult @@ -24,7 +25,11 @@ fun executeCommand( val executeAsConsole = command.startsWith(EXECUTE_AS_CONSOLE_PREFIX) val processedCommand = if (doPlaceholderProcessing) { - unprefixedCommand.tryProcessPlaceholders(CommandUtils.INSTANCE.placeholderApi, target) + if (Sponge.getPluginManager().getPlugin(CommandUtils.PLACEHOLDER_API_ID).isPresent) { + val placeholderApi = getServiceOrFail(PlaceholderService::class, + failMessage = "Failed getting the placeholder API despite the plugin itself being loaded!") + unprefixedCommand.tryProcessPlaceholders(placeholderApi, target) + } else unprefixedCommand } else unprefixedCommand // Any additional custom replacements(like the alias arguments, or the legacy '$p')