Space chat reports

- Add a blank line before each report and before its hint in chat
- Keep console and log output compact
This commit is contained in:
piexel committed 2026-11-18 15:24:30 +01:00
1 parent 6dd22fa34e
commit 561ec4e0db
4 files changed
+42 -8

No files matched your search

@@ -91,9 +91,10 @@ public final class WorldRefusalReporter implements Listener {
.hint("The console has the full refusal notice", null) .hint("The console has the full refusal notice", null)
.build(); .build();
String tag = Iris.instance == null ? "" : Iris.instance.getTag(); String tag = Iris.instance == null ? "" : Iris.instance.getTag();
List<ChatReport.Line> lines = report.lines(); player.sendMessage(ChatReport.SPACER.text());
for (int index = 0; index < lines.size(); index++) { player.sendMessage(tag + report.titleLine().text());
player.sendMessage((index == 0 ? tag : "") + lines.get(index).text()); for (ChatReport.Line line : report.bodyLines(true)) {
player.sendMessage(line.text());
} }
} }
@@ -34,6 +34,9 @@ public final class ChatReport {
} }
} }
/** A blank chat line. A single space, because some clients drop fully empty messages. */
public static final Line SPACER = new Line(" ", null);
public record Line(String text, String command) { public record Line(String text, String command) {
public boolean clickable() { public boolean clickable() {
return command != null && !command.isBlank(); return command != null && !command.isBlank();
@@ -82,9 +85,21 @@ public final class ChatReport {
return tone; return tone;
} }
/** The compact layout: title first, no spacing. Used for logs and other plain output. */
public List<Line> lines() { public List<Line> lines() {
List<Line> lines = new ArrayList<>(); List<Line> lines = new ArrayList<>();
lines.add(new Line(ReportText.title(tone, clean(title)), null)); lines.add(titleLine());
lines.addAll(bodyLines(false));
return lines;
}
public Line titleLine() {
return new Line(ReportText.title(tone, clean(title)), null);
}
/** Every line after the title; {@code spaced} adds a blank line between the list and the hint, for chat. */
public List<Line> bodyLines(boolean spaced) {
List<Line> lines = new ArrayList<>();
int shown = Math.min(itemLimit, entries.size()); int shown = Math.min(itemLimit, entries.size());
for (int index = 0; index < shown; index++) { for (int index = 0; index < shown; index++) {
addEntryLines(lines, entries.get(index)); addEntryLines(lines, entries.get(index));
@@ -94,6 +109,9 @@ public final class ChatReport {
lines.add(new Line(C.DARK_GRAY + CONTINUATION_INDENT + ReportText.moreLabel(hidden), null)); lines.add(new Line(C.DARK_GRAY + CONTINUATION_INDENT + ReportText.moreLabel(hidden), null));
} }
if (hint != null) { if (hint != null) {
if (spaced && !lines.isEmpty()) {
lines.add(SPACER);
}
lines.add(new Line(C.GRAY + hint, hintCommand)); lines.add(new Line(C.GRAY + hint, hintCommand));
} }
return lines; return lines;
@@ -325,10 +325,13 @@ public class VolmitSender implements CommandSender {
} }
public void sendReport(ChatReport report) { public void sendReport(ChatReport report) {
java.util.List<ChatReport.Line> lines = report.lines(); boolean spaced = isPlayer();
sendMessage(lines.getFirst().text()); if (spaced) {
for (int index = 1; index < lines.size(); index++) { sendUntagged(ChatReport.SPACER);
sendUntagged(lines.get(index)); }
sendMessage(report.titleLine().text());
for (ChatReport.Line line : report.bodyLines(spaced)) {
sendUntagged(line);
} }
} }
@@ -92,6 +92,18 @@ public class ChatReportTest {
assertEquals("/iris std regen-stop world=w", hint.command()); assertEquals("/iris std regen-stop world=w", hint.command());
} }
@Test
public void chatBodySeparatesTheHintButTheCompactLayoutDoesNot() {
ChatReport report = ChatReport.of(ChatReport.Tone.ERROR, "t")
.item("Missing dimensions/ folder.")
.hint("Run /iris pack validate p", "/iris pack validate p")
.build();
assertEquals(List.of(report.bodyLines(false).get(0), ChatReport.SPACER, report.bodyLines(false).get(1)),
report.bodyLines(true));
assertEquals(3, report.lines().size());
}
private static List<String> plainLines(ChatReport report) { private static List<String> plainLines(ChatReport report) {
return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList(); return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList();
} }