Skip to content

Commit

Permalink
fixed player name truncation on paper servers
Browse files Browse the repository at this point in the history
  • Loading branch information
KruASe76 committed Feb 16, 2024
1 parent 7ce1e7b commit e6ea9b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

<groupId>me.kruase</groupId>
<artifactId>tablist-tweaks</artifactId>
<version>1.3.3</version>
<version>1.3.4</version>
<packaging>jar</packaging>

<name>TablistTweaks</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<kotlin.version>1.9.10</kotlin.version>
<kotlin.version>1.9.22</kotlin.version>
<mcApi.version>1.16</mcApi.version>
</properties>

Expand All @@ -24,7 +24,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/me/kruase/tablisttweaks/util/PlayerExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ fun Player.deleteIdleTreadId() {


fun Player.coloredName(color: ChatColor, initial: Boolean): String {
return "$color${if (initial) playerListName else playerListName.drop(2).dropLast(2)}${ChatColor.RESET}"
return "$color${if (initial) playerListName else playerListName.drop(2)}" +
(if (playerListName.endsWith(ChatColor.RESET.toString())) "" else ChatColor.RESET)
// dropping only first color code and then adding ChatColor.RESET only if not already present
// (it seems like Paper automatically removes ChatColor.RESET at the end of the playerListName)
}

fun Player.updateDimension(destinationLocation: Location = location, initial: Boolean = false) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/me/kruase/tablisttweaks/util/StringExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.kruase.tablisttweaks.util


fun String.replaceLast(oldValue: String, newValue: String): String {
if (!contains(oldValue)) return this

return substringBeforeLast(oldValue) + newValue + substringAfterLast(oldValue)
}

0 comments on commit e6ea9b4

Please sign in to comment.