Skip to content

Commit

Permalink
Fixed bug; new version
Browse files Browse the repository at this point in the history
  • Loading branch information
randombyte-developer committed May 31, 2018
1 parent 0452c10 commit cb800f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group "de.randombyte"
version "2.0"
version "2.1"

repositories {
jcenter()
Expand Down
14 changes: 1 addition & 13 deletions src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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()
Expand Down Expand Up @@ -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!")
}
}
}
7 changes: 6 additions & 1 deletion src/main/kotlin/de/randombyte/commandutils/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down

0 comments on commit cb800f8

Please sign in to comment.