Skip to content

Commit

Permalink
fix 1.13+ client on 1.12.2- server sidebar line styling bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vytskalt committed Oct 13, 2024
1 parent 97cd00b commit 50d567a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 70 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Join the [Discord](https://discord.gg/v7nmTDTW8W) or create an issue for support

## Features

- Sidebars. Up to 42 characters (depends on the formatting) for 1.12.2 and below, no limit for newer versions
- Sidebars. Up to 44 characters (depends on the formatting) for 1.12.2 and below, no limit for newer versions
- Teams. Supports showing different properties (display name, prefix, entries etc.) of the same team to different
players
- Objectives.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.base.Preconditions;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.translation.GlobalTranslator;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot;
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType;
Expand All @@ -16,7 +17,6 @@
import net.megavex.scoreboardlibrary.implementation.player.ScoreboardLibraryPlayer;
import net.megavex.scoreboardlibrary.implementation.sidebar.line.GlobalLineInfo;
import net.megavex.scoreboardlibrary.implementation.sidebar.line.LocaleLineHandler;
import net.megavex.scoreboardlibrary.implementation.sidebar.line.PlayerNameProvider;
import org.apache.commons.lang.RandomStringUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -32,7 +32,6 @@
public abstract class AbstractSidebar implements Sidebar, PlayerDisplayable {
private final ScoreboardLibraryImpl scoreboardLibrary;
private final ObjectivePacketAdapter packetAdapter;
private final List<String> linePlayerNames;

private final GlobalLineInfo[] lines;
private Component title = empty();
Expand All @@ -48,7 +47,6 @@ public AbstractSidebar(@NotNull ScoreboardLibraryImpl scoreboardLibrary, int max

String objectiveName = RandomStringUtils.randomAlphanumeric(16);
this.packetAdapter = scoreboardLibrary.packetAdapter().createObjectiveAdapter(objectiveName);
this.linePlayerNames = PlayerNameProvider.provideLinePlayerNames(maxLines);
this.lines = new GlobalLineInfo[maxLines];
}

Expand Down Expand Up @@ -280,7 +278,10 @@ private void updateScores() {
private @NotNull GlobalLineInfo getLineInfo(int line) {
GlobalLineInfo globalLineInfo = lines[line];
if (globalLineInfo == null) {
globalLineInfo = lines[line] = new GlobalLineInfo(this, linePlayerNames.get(line), line);
char c = Character.toChars(128 + line)[0];
String playerName = "" + LegacyComponentSerializer.SECTION_CHAR + c;

globalLineInfo = lines[line] = new GlobalLineInfo(this, playerName, line);
updateScores();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void value(@NotNull Component renderedComponent) {
this.prefix = legacyValue.substring(0, prefixEnd);

String last = prefix + LegacyComponentSerializer.SECTION_CHAR + (endsWithSection ? legacyValue.charAt(16) : "");
this.player = info.player() + ChatColor.RESET + ChatColor.getLastColors(last);
this.player = info.player() + ChatColor.getLastColors(last);

int playerEnd = prefixEnd;
if (legacyValue.length() > 32) {
Expand All @@ -93,11 +93,10 @@ public void value(@NotNull Component renderedComponent) {
player += legacyValue.substring(prefixEnd, playerEnd);
}

this.suffix = legacyValue.substring(playerEnd + (endsWithSection ? 2 : 0));
this.suffix = ChatColor.getLastColors(this.player) + legacyValue.substring(playerEnd + (endsWithSection ? 2 : 0));
if (suffix.length() > 16) {
String newSuffix = suffix.substring(0, 16);
if (newSuffix.endsWith(String.valueOf(LegacyComponentSerializer.SECTION_CHAR)) &&
ChatColor.getByChar(suffix.charAt(16)) != null) {
if (newSuffix.endsWith(String.valueOf(LegacyComponentSerializer.SECTION_CHAR))) {
newSuffix = newSuffix.substring(0, 15);
}

Expand Down

This file was deleted.

0 comments on commit 50d567a

Please sign in to comment.