Skip to content

Commit f52a81b

Browse files
committed
fix: left-align all Minecraft chat UI and remove pixel-width centering
Replace dynamic pixel-width-based centering in ChatFrame/ChatLayout with consistent left-aligned rendering using a fixed 40-char separator line. Remove width computation from all 9 subcommands and clean up unused imports.
1 parent 330fcc3 commit f52a81b

12 files changed

Lines changed: 43 additions & 156 deletions

File tree

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/DebugCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dev.objz.commandbridge.logging.Log;
55
import dev.objz.commandbridge.util.MM;
66
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
7-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
7+
88
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
99
import dev.objz.commandbridge.velocity.ui.RenderContext;
1010
import dev.objz.commandbridge.velocity.ui.Theme;
@@ -33,9 +33,7 @@ private void renderChat(RenderContext ctx, boolean enabled) {
3333
.hoverEvent(net.kyori.adventure.text.event.HoverEvent.showText(
3434
MM.parse("<" + Theme.C_MUTED + ">Click to toggle debug</" + Theme.C_MUTED + ">")));
3535
Component line = statusComp.append(toggle);
36-
int width = Math.max(ChatLayout.titleWidth("Debug"), ChatLayout.visibleLength(line));
37-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
38-
ChatFrame frame = new ChatFrame("Debug").width(width);
36+
ChatFrame frame = new ChatFrame("Debug");
3937
frame.line(line);
4038
frame.send(ctx.source());
4139
}

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/DumpCommand.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import dev.objz.commandbridge.velocity.net.session.SessionHub;
1414
import dev.objz.commandbridge.util.MM;
1515
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
16-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
16+
1717
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
1818
import dev.objz.commandbridge.velocity.ui.RenderContext;
1919
import dev.objz.commandbridge.velocity.ui.Theme;
@@ -137,13 +137,7 @@ private void renderChatSuccess(
137137
+ safeMessage(result.localError()) + "</" + Theme.C_ERROR + ">"));
138138
}
139139

140-
int width = ChatLayout.titleWidth("Dump");
141-
for (Component line : lines) {
142-
width = Math.max(width, ChatLayout.visibleLength(line));
143-
}
144-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
145-
146-
ChatFrame frame = new ChatFrame("Dump").width(width);
140+
ChatFrame frame = new ChatFrame("Dump");
147141
frame.lines(lines);
148142
frame.send(ctx.source());
149143
}
@@ -186,9 +180,7 @@ private void renderConsoleSuccess(int clientCount, int remoteCollected, int remo
186180

187181
private void renderChatError(RenderContext ctx, Exception ex) {
188182
Component line = MM.error("Failed to build dump: " + safeMessage(ex));
189-
int width = Math.max(ChatLayout.titleWidth("Dump"), ChatLayout.visibleLength(line));
190-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
191-
ChatFrame frame = new ChatFrame("Dump").width(width);
183+
ChatFrame frame = new ChatFrame("Dump");
192184
frame.line(line);
193185
frame.send(ctx.source());
194186
}

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/HelpCommand.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.velocitypowered.api.command.CommandSource;
44
import dev.objz.commandbridge.util.MM;
55
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
6-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
6+
77
import java.util.ArrayList;
88
import java.util.List;
99
import dev.objz.commandbridge.velocity.ui.cli.BoxDrawing;
@@ -54,14 +54,7 @@ private void renderChatHelp(CommandSource sender) {
5454
lines.add(desc);
5555
}
5656

57-
int width = ChatLayout.titleWidth("CommandBridge Help");
58-
for (Component line : lines) {
59-
width = Math.max(width, ChatLayout.visibleLength(line));
60-
}
61-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
62-
63-
ChatFrame frame = new ChatFrame("CommandBridge Help")
64-
.width(width);
57+
ChatFrame frame = new ChatFrame("CommandBridge Help");
6558
frame.lines(lines);
6659
frame.send(sender);
6760
}

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/InfoCommand.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.velocitypowered.api.command.CommandSource;
44
import dev.objz.commandbridge.util.MM;
55
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
6-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
6+
77
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
88
import dev.objz.commandbridge.velocity.ui.cli.CliTable;
99
import dev.objz.commandbridge.velocity.ui.RenderContext;
@@ -48,15 +48,7 @@ private void renderChat(CommandSource sender, RenderContext ctx) {
4848
.append(bar.renderChat(ctx))
4949
.append(MM.parse(" <" + Theme.C_MUTED + ">" + memUsed + "MB / " + memTotal + "MB (" + percent + "%)</" + Theme.C_MUTED + ">"));
5050

51-
int width = ChatLayout.titleWidth("System Info");
52-
for (Component line : lines) {
53-
width = Math.max(width, ChatLayout.visibleLength(line));
54-
}
55-
width = Math.max(width, ChatLayout.visibleLength(barLine));
56-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
57-
5851
ChatFrame frame = new ChatFrame("System Info")
59-
.width(width)
6052
.hint(MM.parse("<" + Theme.C_MUTED + "><italic>Snapshot from this proxy</italic></" + Theme.C_MUTED + ">"));
6153
frame.lines(lines);
6254
frame.space();

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/ListCommand.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import dev.objz.commandbridge.velocity.net.session.SessionHub;
77
import dev.objz.commandbridge.util.MM;
88
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
9-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
9+
1010
import java.util.ArrayList;
1111
import java.util.List;
1212
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
@@ -37,9 +37,7 @@ private void renderChat(CommandSource sender, RenderContext ctx) {
3737

3838
if (authenticated.isEmpty()) {
3939
Component warn = MM.warn("No authenticated clients connected");
40-
int width = Math.max(ChatLayout.titleWidth("Clients"), ChatLayout.visibleLength(warn));
41-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
42-
ChatFrame frame = new ChatFrame("Clients").width(width);
40+
ChatFrame frame = new ChatFrame("Clients");
4341
frame.line(warn);
4442
frame.send(sender);
4543
return;
@@ -68,14 +66,7 @@ private void renderChat(CommandSource sender, RenderContext ctx) {
6866
index++;
6967
}
7068

71-
int width = ChatLayout.titleWidth("Clients");
72-
for (Component line : lines) {
73-
width = Math.max(width, ChatLayout.visibleLength(line));
74-
}
75-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
76-
77-
ChatFrame frame = new ChatFrame("Clients")
78-
.width(width);
69+
ChatFrame frame = new ChatFrame("Clients");
7970
frame.lines(lines);
8071
frame.send(sender);
8172
}

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/MigrateCommand.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import dev.objz.commandbridge.velocity.ui.RenderContext;
99
import dev.objz.commandbridge.velocity.ui.Theme;
1010
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
11-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
11+
1212
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
1313
import dev.objz.commandbridge.velocity.ui.cli.CliTable;
1414
import net.kyori.adventure.text.Component;
@@ -293,13 +293,7 @@ private void renderChat(RenderContext ctx, List<FileResult> results, int targetV
293293
lines.add(reloadHint);
294294
}
295295

296-
int width = ChatLayout.titleWidth("Migrate");
297-
for (Component line : lines) {
298-
width = Math.max(width, ChatLayout.visibleLength(line));
299-
}
300-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
301-
302-
ChatFrame frame = new ChatFrame("Migrate").width(width);
296+
ChatFrame frame = new ChatFrame("Migrate");
303297
frame.lines(lines);
304298
frame.send(ctx.source());
305299
}
@@ -309,10 +303,7 @@ private void renderChat(RenderContext ctx, List<FileResult> results, int targetV
309303
private void sendError(RenderContext ctx, String message, long startNs) {
310304
if (ctx.isPlayer()) {
311305
Component err = MM.error(message);
312-
int width = Math.max(ChatLayout.titleWidth("Migrate"),
313-
ChatLayout.visibleLength(err));
314-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
315-
ChatFrame frame = new ChatFrame("Migrate").width(width);
306+
ChatFrame frame = new ChatFrame("Migrate");
316307
frame.line(err);
317308
frame.send(ctx.source());
318309
} else {
@@ -326,10 +317,7 @@ private void sendError(RenderContext ctx, String message, long startNs) {
326317
private void sendEmpty(RenderContext ctx, long startNs) {
327318
if (ctx.isPlayer()) {
328319
Component msg = MM.muted("No scripts found in scripts directory");
329-
int width = Math.max(ChatLayout.titleWidth("Migrate"),
330-
ChatLayout.visibleLength(msg));
331-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
332-
ChatFrame frame = new ChatFrame("Migrate").width(width);
320+
ChatFrame frame = new ChatFrame("Migrate");
333321
frame.line(msg);
334322
frame.send(ctx.source());
335323
} else {

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/PingCommand.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import dev.objz.commandbridge.velocity.net.session.SessionHub;
1111
import dev.objz.commandbridge.util.MM;
1212
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
13-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
13+
1414
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
1515
import dev.objz.commandbridge.velocity.ui.cli.CliTable;
1616
import dev.objz.commandbridge.velocity.ui.RenderContext;
@@ -173,24 +173,15 @@ private void renderChatResults(RenderContext ctx, ConcurrentHashMap<String, Ping
173173
}
174174

175175
Component hint = MM.parse("<" + Theme.C_MUTED + ">Latency reflects round trip time</" + Theme.C_MUTED + ">");
176-
int width = ChatLayout.titleWidth("Ping");
177-
for (Component line : lines) {
178-
width = Math.max(width, ChatLayout.visibleLength(line));
179-
}
180-
width = Math.max(width, ChatLayout.visibleLength(hint));
181-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
182176

183177
ChatFrame frame = new ChatFrame("Ping")
184-
.width(width)
185178
.hint(hint);
186179
frame.lines(lines);
187180
frame.send(ctx.source());
188181
}
189182

190183
private void renderChatMessage(RenderContext ctx, Component line) {
191-
int width = Math.max(ChatLayout.titleWidth("Ping"), ChatLayout.visibleLength(line));
192-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
193-
ChatFrame frame = new ChatFrame("Ping").width(width);
184+
ChatFrame frame = new ChatFrame("Ping");
194185
frame.line(line);
195186
frame.send(ctx.source());
196187
}

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/ReloadCommand.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import dev.objz.commandbridge.velocity.net.session.SessionHub;
1515
import dev.objz.commandbridge.util.MM;
1616
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
17-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
17+
1818
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
1919
import dev.objz.commandbridge.velocity.ui.cli.CliTable;
2020
import dev.objz.commandbridge.velocity.ui.RenderContext;
@@ -232,25 +232,15 @@ private void renderChatSuccess(RenderContext ctx, int loaded, int enabled, int d
232232
MM.parse("<" + Theme.C_MUTED + ">Open script list</" + Theme.C_MUTED + ">")));
233233
lines.add(action);
234234

235-
int width = ChatLayout.titleWidth("Reload");
236-
for (Component line : lines) {
237-
width = Math.max(width, ChatLayout.visibleLength(line));
238-
}
239-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
240-
241-
ChatFrame frame = new ChatFrame("Reload")
242-
.width(width);
235+
ChatFrame frame = new ChatFrame("Reload");
243236
frame.lines(lines);
244237
frame.send(ctx.source());
245238
}
246239

247240
private void renderChatError(RenderContext ctx, String error, String details) {
248241
Component err = MM.error(error);
249242
Component detail = MM.muted(details);
250-
int width = Math.max(ChatLayout.titleWidth("Reload"), ChatLayout.visibleLength(err));
251-
width = Math.max(width, ChatLayout.visibleLength(detail));
252-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
253-
ChatFrame frame = new ChatFrame("Reload").width(width);
243+
ChatFrame frame = new ChatFrame("Reload");
254244
frame.line(err);
255245
frame.line(detail);
256246
frame.send(ctx.source());
@@ -345,14 +335,7 @@ private void displayChatResults(RenderContext ctx,
345335
idx++;
346336
}
347337

348-
int width = ChatLayout.titleWidth("Reload");
349-
for (Component line : lines) {
350-
width = Math.max(width, ChatLayout.visibleLength(line));
351-
}
352-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
353-
354-
ChatFrame frame = new ChatFrame("Reload")
355-
.width(width);
338+
ChatFrame frame = new ChatFrame("Reload");
356339
frame.lines(lines);
357340
frame.send(ctx.source());
358341
}

velocity/src/main/java/dev/objz/commandbridge/velocity/cli/subcommands/ScriptsCommand.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import dev.objz.commandbridge.util.MM;
77
import dev.objz.commandbridge.velocity.ScriptManager;
88
import dev.objz.commandbridge.velocity.ui.chat.ChatFrame;
9-
import dev.objz.commandbridge.velocity.ui.chat.ChatLayout;
9+
1010
import dev.objz.commandbridge.velocity.ui.cli.CliOutput;
1111
import dev.objz.commandbridge.velocity.ui.RenderContext;
1212
import dev.objz.commandbridge.velocity.ui.Theme;
@@ -38,9 +38,7 @@ private void renderChatScripts(CommandSource sender, int page) {
3838

3939
if (scripts.isEmpty()) {
4040
Component warn = MM.warn("No scripts loaded");
41-
int width = Math.max(ChatLayout.titleWidth("Scripts"), ChatLayout.visibleLength(warn));
42-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
43-
ChatFrame frame = new ChatFrame("Scripts").width(width);
41+
ChatFrame frame = new ChatFrame("Scripts");
4442
frame.line(warn);
4543
frame.send(sender);
4644
return;
@@ -112,14 +110,7 @@ private void renderChatScripts(CommandSource sender, int page) {
112110
lines.add(nav);
113111
}
114112

115-
int width = ChatLayout.titleWidth("Scripts");
116-
for (Component line : lines) {
117-
width = Math.max(width, ChatLayout.visibleLength(line));
118-
}
119-
width = Math.max(width, ChatLayout.DEFAULT_WIDTH_PX);
120-
121-
ChatFrame frame = new ChatFrame("Scripts")
122-
.width(width);
113+
ChatFrame frame = new ChatFrame("Scripts");
123114
frame.lines(lines);
124115
frame.send(sender);
125116
}

velocity/src/main/java/dev/objz/commandbridge/velocity/ui/chat/ChatFrame.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ public final class ChatFrame {
1010
private final String title;
1111
private final List<Component> lines = new ArrayList<>();
1212
private Component hint;
13-
private int width;
1413

1514
public ChatFrame(String title) {
1615
this.title = title;
1716
}
1817

19-
public ChatFrame width(int width) {
20-
this.width = Math.max(0, width);
21-
return this;
22-
}
23-
2418
public ChatFrame hint(Component hint) {
2519
this.hint = hint;
2620
return this;
@@ -42,14 +36,12 @@ public ChatFrame space() {
4236
}
4337

4438
public List<Component> render() {
45-
int resolvedWidth = width > 0 ? width : computeWidth();
46-
resolvedWidth = Math.max(ChatLayout.DEFAULT_WIDTH_PX, resolvedWidth);
4739
List<Component> out = new ArrayList<>();
4840
out.add(Component.empty());
49-
out.add(ChatLayout.headerTitle(title, resolvedWidth));
50-
out.add(ChatLayout.headerUnderline(resolvedWidth));
41+
out.add(ChatLayout.headerTitle(title));
42+
out.add(ChatLayout.headerUnderline());
5143
if (hint != null) {
52-
out.add(ChatLayout.center(hint, resolvedWidth));
44+
out.add(hint);
5345
}
5446
out.addAll(lines);
5547
return out;
@@ -63,16 +55,4 @@ public void send(Audience audience) {
6355
audience.sendMessage(line);
6456
}
6557
}
66-
67-
68-
private int computeWidth() {
69-
int max = ChatLayout.titleWidth(title);
70-
if (hint != null) {
71-
max = Math.max(max, ChatLayout.visibleLength(hint));
72-
}
73-
for (Component line : lines) {
74-
max = Math.max(max, ChatLayout.visibleLength(line));
75-
}
76-
return max;
77-
}
7858
}

0 commit comments

Comments
 (0)