diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..941d18c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +charset = utf-8 +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{kt,kts}] +ktlint_code_style = intellij_idea + +[*{.yml,yaml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/build-workflow.yml b/.github/workflows/build-workflow.yml index 34003af..4a2c855 100644 --- a/.github/workflows/build-workflow.yml +++ b/.github/workflows/build-workflow.yml @@ -9,21 +9,27 @@ on: jobs: build: name: Gradle Build - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 outputs: version: ${{ steps.version.outputs.version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: gradle/gradle-build-action@v2 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 21 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - name: Gradle Build - run: ./gradlew build + run: ./gradlew build shadowJar - name: Get Version id: version run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT - name: Upload build - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: build path: build/libs/*.jar diff --git a/.github/workflows/release-workflow.yml b/.github/workflows/create-version.yml similarity index 68% rename from .github/workflows/release-workflow.yml rename to .github/workflows/create-version.yml index f9ea281..5697840 100644 --- a/.github/workflows/release-workflow.yml +++ b/.github/workflows/create-version.yml @@ -1,4 +1,4 @@ -name: Create Release +name: Create Version on: workflow_dispatch: @@ -17,22 +17,26 @@ on: jobs: release: name: Gradle Release - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 outputs: version: ${{ steps.version.outputs.version }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: - token: "${{ secrets.PAT }}" + ssh-key: "${{ secrets.COMMIT_KEY }}" fetch-depth: 0 - - uses: gradle/gradle-build-action@v2 + - uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.COMMIT_KEY }} + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 21 + - uses: gradle/actions/setup-gradle@v4 - name: Gradle Release if: ${{ inputs.versionIncrementer == 'default' }} - env: - DEPLOY_KEY: ${{ secrets.COMMIT_KEY }} run: ./gradlew release - name: Gradle Release w/ Increment Override if: ${{ inputs.versionIncrementer != 'default' }} - env: - DEPLOY_KEY: ${{ secrets.COMMIT_KEY }} run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }} diff --git a/.github/workflows/publish-workflow.yml b/.github/workflows/publish-workflow.yml index 7232470..00882bc 100644 --- a/.github/workflows/publish-workflow.yml +++ b/.github/workflows/publish-workflow.yml @@ -11,19 +11,15 @@ jobs: release: needs: build name: Create Release - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: gradle/gradle-build-action@v2 - name: Download build - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: build path: build - name: Release - uses: docker://antonyurchenko/git-release:v5 + uses: docker://antonyurchenko/git-release:v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_NAME: ${{ needs.build.outputs.version }} @@ -32,5 +28,4 @@ jobs: UNRELEASED_TAG: latest-snapshot ALLOW_EMPTY_CHANGELOG: ${{ github.ref_type == 'branch' && 'true' || 'false' }} with: - args: | - build/*.jar + args: build/*.jar diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f32399..e2f81d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog ## [Unreleased] +### Changed +- MC 1.21, Kotlin 2.1, Gradle 8.12 (@tajobe) + +### Fixed +- Prevent name healthbar from overwriting name tags (@tajobe) ## [0.3.1] - 2023-03-08 ### Changed diff --git a/build.gradle.kts b/build.gradle.kts index 6da362d..c670f01 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,3 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation import org.yaml.snakeyaml.DumperOptions import org.yaml.snakeyaml.Yaml import pl.allegro.tech.build.axion.release.domain.hooks.HookContext @@ -6,86 +5,74 @@ import java.time.OffsetDateTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.yaml:snakeyaml:2.0") - } -} - plugins { - kotlin("jvm") - id("com.github.johnrengelman.shadow") version "8.0.0" - id("pl.allegro.tech.build.axion-release") version "1.14.4" - id("org.jlleitschuh.gradle.ktlint") version "11.2.0" + alias(libs.plugins.axionRelease) + alias(libs.plugins.kotlin) + alias(libs.plugins.ktlint) + alias(libs.plugins.shadow) } -group = "org.simplemc" -version = scmVersion.version - -val mcApiVersion: String by project -val repoRef: String by project - scmVersion { versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+")) + unshallowRepoOnCI.set(true) hooks { + // Automate moving `[Unreleased]` changelog entries into `[]` on release // FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500 + val changelogPattern = + "\\[Unreleased\\]([\\s\\S]+?)\\n" + + "(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/(\\S+\\/\\S+)\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z" pre( "fileUpdate", mapOf( "file" to "CHANGELOG.md", - "pattern" to KotlinClosure2({ v, _ -> - "\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z" - }), - "replacement" to KotlinClosure2({ v, c -> + "pattern" to KotlinClosure2({ _, _ -> changelogPattern }), + "replacement" to KotlinClosure2({ version, context -> + // github "diff" for previous version + val previousVersionDiffLink = + when (context.previousVersion == version) { + true -> "releases/tag/v$version" // no previous, just link to the version + false -> "compare/v${context.previousVersion}...v$version" + } """ \[Unreleased\] - ## \[$v\] - ${currentDateString()}$1 - \[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD - \[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2 + ## \[$version\] - $currentDateString$1 + \[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD + \[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3 """.trimIndent() - }) - ) + }), + ), ) pre("commit") } } -fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) +group = "org.simplemc" +version = scmVersion.version -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } -} +val currentDateString: String + get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) -repositories { - mavenCentral() - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") - maven("https://oss.sonatype.org/content/repositories/snapshots") +kotlin { + jvmToolchain(21) } dependencies { - implementation(kotlin("stdlib-jdk8")) - compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+") + compileOnly(libs.spigot) } tasks { wrapper { - gradleVersion = "8.0.1" distributionType = Wrapper.DistributionType.ALL } processResources { val placeholders = mapOf( "version" to version, - "apiVersion" to mcApiVersion, - "kotlinVersion" to project.properties["kotlinVersion"] + "apiVersion" to libs.versions.mcApi.get(), + "kotlinVersion" to libs.versions.kotlin.get(), ) filesMatching("plugin.yml") { @@ -117,15 +104,9 @@ tasks { archiveClassifier.set("offline") exclude("plugin.yml") rename("offline-plugin.yml", "plugin.yml") - } - - // avoid classpath conflicts/pollution via relocation - val configureShadowRelocation by registering(ConfigureShadowRelocation::class) { - target = shadowJar.get() - prefix = "${project.group}.${project.name.lowercase()}.libraries" - } - build { - dependsOn(shadowJar).dependsOn(configureShadowRelocation) + // avoid classpath conflicts/pollution via relocation + isEnableRelocation = true + relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries" } } diff --git a/gradle.properties b/gradle.properties index c7bbb72..7fc6f1f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1 @@ kotlin.code.style=official - -kotlinVersion=1.8.10 -mcApiVersion=1.19 -repoRef=SimpleMC/SimpleHealthbars2 diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 0000000..63e5bbd --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,2 @@ +#This file is generated by updateDaemonJvm +toolchainVersion=21 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..bc0894d --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,16 @@ +[versions] +axionRelease = "1.18.16" +kotlin = "2.1.10" +ktlintGradle = "12.1.2" +mcApi = "1.21" +shadow = "8.3.6" +spigot = "1.21.+" + +[plugins] +axionRelease = { id = "pl.allegro.tech.build.axion-release", version.ref = "axionRelease"} +kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"} +ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"} +shadow = { id = "com.gradleup.shadow", version.ref = "shadow"} + +[libraries] +spigot = { group = "org.spigotmc", name = "spigot-api", version.ref = "spigot" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index ccebba7..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6ec1567..d9fbee2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-all.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 79a61d4..f3b75f3 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +133,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +147,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +200,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 6689b85..9b42019 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/settings.gradle.kts b/settings.gradle.kts index fbd2210..3c5ceb2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,10 +1,26 @@ - pluginManagement { - val kotlinVersion: String by settings + repositories { + gradlePluginPortal() + mavenCentral() + } +} + +buildscript { + dependencies { + classpath("org.yaml:snakeyaml:2.3") + } +} - plugins { - id("org.jetbrains.kotlin.jvm").version(kotlinVersion) +dependencyResolutionManagement { + repositories { + mavenCentral() + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") + maven("https://oss.sonatype.org/content/repositories/snapshots") } } +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0" +} + rootProject.name = "simplehealthbars2" diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/DamageListener.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/DamageListener.kt index 52da97f..2f652ff 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/DamageListener.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/DamageListener.kt @@ -7,6 +7,7 @@ import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.entity.EntityDamageByEntityEvent +import org.bukkit.event.entity.EntityDeathEvent import org.bukkit.plugin.Plugin import org.simplemc.simplehealthbars2.healthbar.MobHealthbar import org.simplemc.simplehealthbars2.healthbar.PlayerHealthbar @@ -15,7 +16,7 @@ import java.util.UUID class DamageListener( private val plugin: Plugin, private val playerHealthbars: Map, - private val mobHealthbars: Map + private val mobHealthbars: Map, ) : Listener, AutoCloseable { private data class RemoveHealthbarTask(val taskId: Int, val task: () -> Unit) @@ -32,6 +33,17 @@ class DamageListener( source?.let { healthbar(target, it, 0.0) } } + /** + * Remove the healthbar from dying entities immediately + */ + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + fun onEntityDeathEvent(event: EntityDeathEvent) { + removeHealthbarTasks[event.entity.uniqueId]?.let { + scheduler.cancelTask(it.taskId) + it.task() + } + } + private fun healthbar(source: LivingEntity?, target: LivingEntity, damage: Double) { // cancel scheduled healthbar removal and run it now to prepare for new (updated) healthbar removeHealthbarTasks[target.uniqueId]?.let { diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/Extensions.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/Extensions.kt index d5c95d4..d7b962b 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/Extensions.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/Extensions.kt @@ -8,17 +8,14 @@ import kotlin.math.max fun LivingEntity.getDamagedHealth(damage: Double): Double = max(health - damage, 0.0) fun LivingEntity.getDamagedHealthRatio(damage: Double): Double = - getDamagedHealth(damage) / checkNotNull(getAttribute(Attribute.GENERIC_MAX_HEALTH)).value + getDamagedHealth(damage) / checkNotNull(getAttribute(Attribute.MAX_HEALTH)).value -fun LivingEntity.getCustomDisplayName(): String = when { +fun LivingEntity.getDisplayName(): String = when { this is Player -> displayName - isCustomNameVisible -> checkNotNull(customName) - else -> type.name.lowercase().split('_').joinToString(separator = " ", transform = String::titlecaseFirstChar) + else -> customName ?: type.name.underscoresToTitlecase() } -fun String.titlecaseFirstChar() = replaceFirstChar(Char::titlecase) +fun String.underscoresToTitlecase() = + lowercase().split('_').joinToString(separator = " ", transform = String::titlecaseFirstChar) -fun LivingEntity.setCustomDisplayName(name: String) { - customName = name - isCustomNameVisible = true -} +fun String.titlecaseFirstChar() = replaceFirstChar(Char::titlecase) diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/SimpleHealthbars2.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/SimpleHealthbars2.kt index 8d76395..949b69d 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/SimpleHealthbars2.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/SimpleHealthbars2.kt @@ -87,8 +87,8 @@ class SimpleHealthbars2 : JavaPlugin() { ScoreboardHealthbar.Config( useMainScoreboard = config.getBoolean("useMainScoreboard", false), style = Healthbar.Style.valueOf(checkNotNull(config.getString("style", "ABSOLUTE"))), - duration = Duration.ofSeconds(config.getLong("duration", 5)) - ) + duration = Duration.ofSeconds(config.getLong("duration", 5)), + ), ) Healthbar.Type.NONE -> null } @@ -99,7 +99,7 @@ class SimpleHealthbars2 : JavaPlugin() { duration = Duration.ofSeconds(config.getLong("duration", 5)), length = config.getInt("length", 20), char = config.getInt("char", 0x25ae).toChar(), - showMobNames = config.getBoolean("showMobNames", true) + showMobNames = config.getBoolean("showMobNames", true), ) override fun onDisable() { diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ActionHealthbar.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ActionHealthbar.kt index 96f84df..6c776cb 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ActionHealthbar.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ActionHealthbar.kt @@ -4,7 +4,7 @@ import net.md_5.bungee.api.ChatMessageType import net.md_5.bungee.api.chat.TextComponent import org.bukkit.entity.LivingEntity import org.bukkit.entity.Player -import org.simplemc.simplehealthbars2.getCustomDisplayName +import org.simplemc.simplehealthbars2.getDisplayName class ActionHealthbar(config: Config) : StringHealthbar(config), PlayerHealthbar, MobHealthbar { @@ -12,7 +12,7 @@ class ActionHealthbar(config: Config) : StringHealthbar(config), PlayerHealthbar if (source != null && source is Player) { source.spigot().sendMessage( ChatMessageType.ACTION_BAR, - *TextComponent.fromLegacyText(formatHealthbar(target, target.getCustomDisplayName(), damage)) + TextComponent.fromLegacy(formatHealthbar(target, target.getDisplayName(), damage)), ) } diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/NameHealthbar.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/NameHealthbar.kt index ea71e08..d222966 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/NameHealthbar.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/NameHealthbar.kt @@ -1,23 +1,19 @@ package org.simplemc.simplehealthbars2.healthbar import org.bukkit.entity.LivingEntity -import org.simplemc.simplehealthbars2.getCustomDisplayName -import org.simplemc.simplehealthbars2.setCustomDisplayName +import org.simplemc.simplehealthbars2.getDisplayName class NameHealthbar(config: Config) : StringHealthbar(config), MobHealthbar { override fun updateHealth(source: LivingEntity?, target: LivingEntity, damage: Double): (() -> Unit) { - val hadCustomName = target.isCustomNameVisible - val oldName = target.getCustomDisplayName() + val oldCustomName = target.customName + val wasCustomNameVisible = target.isCustomNameVisible - target.setCustomDisplayName(formatHealthbar(target, oldName, damage)) + target.customName = formatHealthbar(target, target.getDisplayName(), damage) + target.isCustomNameVisible = true return { - if (hadCustomName) { - target.setCustomDisplayName(oldName) - } else { - target.isCustomNameVisible = false - target.customName = null - } + target.customName = oldCustomName + target.isCustomNameVisible = wasCustomNameVisible } } } diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ScoreboardHealthbar.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ScoreboardHealthbar.kt index 2cb1e3c..9e53eda 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ScoreboardHealthbar.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/ScoreboardHealthbar.kt @@ -21,7 +21,7 @@ class ScoreboardHealthbar(override val config: Config) : PlayerHealthbar { data class Config( val useMainScoreboard: Boolean = false, override val style: Healthbar.Style = Healthbar.Style.ABSOLUTE, - override val duration: Duration = Duration.ofSeconds(5) + override val duration: Duration = Duration.ofSeconds(5), ) : Healthbar.Config private val objective: Objective @@ -43,13 +43,13 @@ class ScoreboardHealthbar(override val config: Config) : PlayerHealthbar { OBJECTIVE_NAME, Criteria.HEALTH, "${ChatColor.RED}${0x2764.toChar()}", - RenderType.HEARTS + RenderType.HEARTS, ) Healthbar.Style.PERCENT -> scoreboard.registerNewObjective( OBJECTIVE_NAME, Criteria.DUMMY, "${ChatColor.RED}${0x2764.toChar()}", - RenderType.INTEGER + RenderType.INTEGER, ) Healthbar.Style.BAR -> throw IllegalArgumentException("BAR healthbar style not valid for scoreboard healthbar!") diff --git a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/StringHealthbar.kt b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/StringHealthbar.kt index ebb25e2..471d014 100644 --- a/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/StringHealthbar.kt +++ b/src/main/kotlin/org/simplemc/simplehealthbars2/healthbar/StringHealthbar.kt @@ -13,7 +13,7 @@ abstract class StringHealthbar(final override val config: Config) : Healthbar { override val duration: Duration = Duration.ofSeconds(5), val length: Int = 20, val char: Char = 0x25ae.toChar(), - val showMobNames: Boolean = true + val showMobNames: Boolean = true, ) : Healthbar.Config private val step = config.char.toString()