mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
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:
1 parent
6dd22fa34e
commit
561ec4e0db
4 files changed
+42
-8
No files matched your search
+4
-3
@@ -91,9 +91,10 @@ public final class WorldRefusalReporter implements Listener {
|
||||
.hint("The console has the full refusal notice", null)
|
||||
.build();
|
||||
String tag = Iris.instance == null ? "" : Iris.instance.getTag();
|
||||
List<ChatReport.Line> lines = report.lines();
|
||||
for (int index = 0; index < lines.size(); index++) {
|
||||
player.sendMessage((index == 0 ? tag : "") + lines.get(index).text());
|
||||
player.sendMessage(ChatReport.SPACER.text());
|
||||
player.sendMessage(tag + report.titleLine().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 boolean clickable() {
|
||||
return command != null && !command.isBlank();
|
||||
@@ -82,9 +85,21 @@ public final class ChatReport {
|
||||
return tone;
|
||||
}
|
||||
|
||||
/** The compact layout: title first, no spacing. Used for logs and other plain output. */
|
||||
public List<Line> lines() {
|
||||
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());
|
||||
for (int index = 0; index < shown; 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));
|
||||
}
|
||||
if (hint != null) {
|
||||
if (spaced && !lines.isEmpty()) {
|
||||
lines.add(SPACER);
|
||||
}
|
||||
lines.add(new Line(C.GRAY + hint, hintCommand));
|
||||
}
|
||||
return lines;
|
||||
|
||||
@@ -325,10 +325,13 @@ public class VolmitSender implements CommandSender {
|
||||
}
|
||||
|
||||
public void sendReport(ChatReport report) {
|
||||
java.util.List<ChatReport.Line> lines = report.lines();
|
||||
sendMessage(lines.getFirst().text());
|
||||
for (int index = 1; index < lines.size(); index++) {
|
||||
sendUntagged(lines.get(index));
|
||||
boolean spaced = isPlayer();
|
||||
if (spaced) {
|
||||
sendUntagged(ChatReport.SPACER);
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
@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) {
|
||||
return report.lines().stream().map(line -> line.text().replaceAll("§.", "")).toList();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user