Skip to content

Commit f0abc99

Browse files
author
NEZNAMY
committed
[Layout] Properly format / unformat original tablist entries when layout is set / reset (#1728)
1 parent b669871 commit f0abc99

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

‎shared/src/main/java/me/neznamy/tab/shared/features/layout/LayoutManagerImpl.java‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,10 @@ public void onJoin(@NotNull TabPlayer p) {
7777
p.layoutData.sortingString = p.sortingData.fullTeamName;
7878
sortedPlayers.put(p, p.sortingData.fullTeamName);
7979
LayoutPattern highest = getHighestLayout(p);
80-
if (highest != null) {
81-
sendLayout(p, highest);
82-
}
80+
sendLayout(p, highest);
8381
for (TabPlayer all : TAB.getInstance().getOnlinePlayers()) {
8482
if (all.layoutData.currentLayout != null) all.layoutData.currentLayout.view.onJoin(p);
8583
}
86-
87-
// Unformat original entries for players who can see a layout to avoid spaces due to unparsed placeholders and such
88-
if (highest == null) return;
89-
for (TabPlayer all : TAB.getInstance().getOnlinePlayers()) {
90-
p.getTabList().updateDisplayName(all, null);
91-
}
9284
}
9385

9486
@Override
@@ -112,17 +104,30 @@ public void refresh(@NotNull TabPlayer p, boolean force) {
112104
LayoutPattern current = p.layoutData.currentLayout == null ? null : p.layoutData.currentLayout.view.getPattern();
113105
if (highest != current) {
114106
if (current != null) p.layoutData.currentLayout.view.destroy();
115-
p.layoutData.currentLayout = null;
116-
if (highest != null) {
117-
sendLayout(p, highest);
118-
}
107+
sendLayout(p, highest);
119108
}
120109
}
121110

122-
private void sendLayout(@NotNull TabPlayer player, @NotNull LayoutPattern pattern) {
123-
LayoutBase view = new FakeEntryLayout(this, pattern, player);
124-
player.layoutData.currentLayout = new LayoutData(view);
125-
view.send();
111+
private void sendLayout(@NotNull TabPlayer player, @Nullable LayoutPattern pattern) {
112+
if (pattern != null) {
113+
LayoutBase view = new FakeEntryLayout(this, pattern, player);
114+
player.layoutData.currentLayout = new LayoutData(view);
115+
view.send();
116+
if (playerList != null) {
117+
// Unformat original entries for players who can see a layout to avoid spaces due to unparsed placeholders and such
118+
for (TabPlayer all : TAB.getInstance().getOnlinePlayers()) {
119+
player.getTabList().updateDisplayName(all, null);
120+
}
121+
}
122+
} else {
123+
player.layoutData.currentLayout = null;
124+
if (playerList != null) {
125+
// Reformat original entries for players without any layout
126+
for (TabPlayer all : TAB.getInstance().getOnlinePlayers()) {
127+
player.getTabList().updateDisplayName(all, playerList.getTabFormat(all, player));
128+
}
129+
}
130+
}
126131
}
127132

128133
@Override

0 commit comments

Comments
 (0)