Skip to content

Commit

Permalink
Sync logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Apr 21, 2024
1 parent 81d6b51 commit b62ea3b
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 49 deletions.
6 changes: 4 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ class BetterHudImpl: BetterHud() {
}
managerReload()
}.onFailure { e ->
warn("Unable to reload.")
warn("Reason: ${e.message}")
warn(
"Unable to reload.",
"Reason: ${e.message}"
)
onReload = false
consumer.accept(ReloadResult(ReloadState.FAIL, System.currentTimeMillis() - time))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ object BackgroundManager: BetterHudManager {
)
}
}.onFailure { e ->
warn("Unable to load this yml: ${it.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this yml: ${it.name}",
"Reason: ${e.message}"
)
}
}
}, callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ object CompatibilityManager: BetterHudManager {
PLUGIN.triggerManager.addTrigger("${namespace}_${entry.key}", entry.value)
}
}.onFailure { e ->
warn("Unable to load ${it.key} support.")
warn("Reason: ${e.message}")
warn(
"Unable to load ${it.key} support.",
"Reason: ${e.message}"
)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/ConfigManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ object ConfigManager: BetterHudManager {
mergeOtherFolders = yaml.getStringList("merge-other-folders")
selfHostPort = yaml.getInt("self-host-port", 8163)
}.onFailure { e ->
warn("Unable to load config.yml")
warn("Reason: ${e.message}")
warn(
"Unable to load config.yml",
"Reason: ${e.message}"
)
}
}
override fun end() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ object DatabaseManagerImpl: BetterHudManager, DatabaseManager {
current = connectionMap[type].ifNull("this database doesn't exist: $type").connect(info)
}.onFailure { e ->
current = defaultConnector.connect(MemoryConfiguration())
warn("Unable to connect the database.")
warn("Reason: ${e.message}")
warn(
"Unable to connect the database.",
"Reason: ${e.message}"
)
}
callback()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ object HudManagerImpl: BetterHudManager, HudManager {
HudImpl(file.path, s, hudFolder, configurationSection)
}
}.onFailure { e ->
warn("Unable to load this hud: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this hud: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}, callback)
}
Expand Down
6 changes: 4 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/ImageManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ object ImageManager: BetterHudManager {
image
}
}.onFailure { e ->
warn("Unable to load this image: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this image: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}) {
val saveLocation = ArrayList(resource.textures).apply {
Expand Down
6 changes: 4 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/LayoutManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ object LayoutManager: BetterHudManager {
LayoutGroup(file.path, configurationSection)
}
}.onFailure { e ->
warn("Unable to load this layout: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this layout: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}, callback)
}
Expand Down
6 changes: 4 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/ModuleManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ object ModuleManager: BetterHudManager {
PlaceholderManagerImpl.booleanContainer.addPlaceholder("${module.key}_${boolean.key}", boolean.value)
}
}.onFailure { e ->
warn("Unable to load this module: ${module.key}")
warn("Reason: ${e.message}")
warn(
"Unable to load this module: ${module.key}",
"Reason: ${e.message}"
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,10 @@ object PlaceholderManagerImpl: PlaceholderManager, BetterHudManager {
}
})
}.onFailure { e ->
warn("Unable to read this placeholder task: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to read this placeholder task: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ object PlayerHeadManager: BetterHudManager {
head
}
}.onFailure { e ->
warn("Unable to load this head: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this head: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}, callback)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ object PopupManagerImpl: BetterHudManager, PopupManager {
PopupImpl(file.path, save, s, configurationSection)
}
}.onFailure { e ->
warn("Unable to load this popup: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this popup: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}, callback)
}
Expand Down
6 changes: 4 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ object ShaderManager: BetterHudManager {
}
hudShaders.clear()
}.onFailure { e ->
warn("Unable to load shader.yml")
warn("Reason: ${e.message}")
warn(
"Unable to load shader.yml",
"Reason: ${e.message}"
)
}
}
callback()
Expand Down
18 changes: 12 additions & 6 deletions dist/src/main/kotlin/kr/toxicity/hud/manager/TextManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ object TextManager: BetterHudManager {
}, section.toConditions(), section.getBoolean("merge-default-bitmap"))
}
}.onFailure { e ->
warn("Unable to load this text: $s in ${file.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this text: $s in ${file.name}",
"Reason: ${e.message}"
)
}
}) {
val defaultArray = JsonArray().apply {
Expand Down Expand Up @@ -158,8 +160,10 @@ object TextManager: BetterHudManager {
return
}
}.getOrElse { e ->
warn("Unable to load this image: $imageName")
warn("Reason: ${e.message}")
warn(
"Unable to load this image: $imageName",
"Reason: ${e.message}"
)
return
}
val array = obj.getAsJsonArray("chars")
Expand All @@ -174,8 +178,10 @@ object TextManager: BetterHudManager {
}
}
}.onFailure { e ->
warn("Unable to parse minecraft_default.json")
warn("Reason: ${e.message}")
warn(
"Unable to parse minecraft_default.json",
"Reason: ${e.message}"
)
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions dist/src/main/kotlin/kr/toxicity/hud/pack/PackGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,28 @@ object PackGenerator {
runCatching {
saveTask(t)
}.onFailure { e ->
warn("Unable to save this file: ${t.path}")
warn("Reason: ${e.message}")
warn(
"Unable to save this file: ${t.path}",
"Reason: ${e.message}"
)
}
}) {
runCatching {
saveTask.close()
}.onFailure { e ->
warn("Unable to finalized resource pack build.")
warn("Reason: ${e.message}")
warn(
"Unable to finalized resource pack build.",
"Reason: ${e.message}"
)
}
callback()
tasks.clear()
}
}.onFailure { e ->
warn("Unable to make a resource pack.")
warn("Reason: ${e.message}")
warn(
"Unable to make a resource pack.",
"Reason: ${e.message}"
)
callback()
tasks.clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ object Conditions {
}
}
}.onFailure { e ->
warn("Unable to load this condition: $s")
warn("Reason: ${e.message}")
warn(
"Unable to load this condition: $s",
"Reason: ${e.message}"
)
}
}
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kr.toxicity.hud.player
import com.google.gson.JsonParser
import kr.toxicity.hud.api.player.HudPlayerHead
import kr.toxicity.hud.manager.PlayerHeadManager
import kr.toxicity.hud.util.textures
import kr.toxicity.hud.util.toImage
import kr.toxicity.hud.util.warn
import net.kyori.adventure.text.format.NamedTextColor
Expand Down Expand Up @@ -45,8 +44,10 @@ class HudPlayerHeadImpl(player: Player): HudPlayerHead {
}
}
}.getOrElse { e ->
warn("Unable to get ${player.name}'s head.")
warn("Reason: ${e.message}")
warn(
"Unable to get ${player.name}'s head.",
"Reason: ${e.message}"
)
allBlack
}
override fun getColors(): List<TextColor> = colorList
Expand Down
12 changes: 8 additions & 4 deletions dist/src/main/kotlin/kr/toxicity/hud/util/Files.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ fun File.forEachAllYaml(block: (File, String, ConfigurationSection) -> Unit) {
block(it, s, configurationSection)
}
}.onFailure { e ->
warn("Unable to load this yml file: ${it.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this yml file: ${it.name}",
"Reason: ${e.message}"
)
}
}
}
Expand Down Expand Up @@ -70,8 +72,10 @@ fun File.forEachAllYamlAsync(block: (File, String, ConfigurationSection) -> Unit
}
if (list.isNotEmpty()) it to list else null
}.getOrElse { e ->
warn("Unable to load this yml file: ${it.name}")
warn("Reason: ${e.message}")
warn(
"Unable to load this yml file: ${it.name}",
"Reason: ${e.message}"
)
null
}
}
Expand Down
18 changes: 16 additions & 2 deletions dist/src/main/kotlin/kr/toxicity/hud/util/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ val DATA_FOLDER

val VERSION = PLUGIN.nms.version

fun info(message: String) = PLUGIN.logger.info(message)
fun warn(message: String) = PLUGIN.logger.warning(message)
fun info(vararg message: String) {
val logger = PLUGIN.logger
synchronized(logger) {
message.forEach {
logger.info(it)
}
}
}
fun warn(vararg message: String) {
val logger = PLUGIN.logger
synchronized(logger) {
message.forEach {
logger.warning(it)
}
}
}

fun task(block: () -> Unit) = PLUGIN.scheduler.task(PLUGIN, block)
fun taskLater(delay: Long, block: () -> Unit) = PLUGIN.scheduler.taskLater(PLUGIN, delay, block)
Expand Down

0 comments on commit b62ea3b

Please sign in to comment.