From 70af3ed7e1ea29094b1cdcb45f9e860f469b944c Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Tue, 5 May 2020 23:26:37 +0300 Subject: [PATCH] Columns & better space compensation --- .../plan/commands/subcommands/DevCommand.java | 18 ++- .../plan/utilities/chat/ChatFormatter.java | 128 ++++++++++++++++-- .../plan/utilities/chat/DefaultFontInfo.java | 1 - 3 files changed, 134 insertions(+), 13 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/DevCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/DevCommand.java index 751f418c2..84431c654 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/DevCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/commands/subcommands/DevCommand.java @@ -24,6 +24,7 @@ import com.djrapitops.plugin.command.CommandNode; import com.djrapitops.plugin.command.CommandType; import com.djrapitops.plugin.command.Sender; import com.djrapitops.plugin.utilities.Verify; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.TextStringBuilder; import javax.inject.Inject; @@ -54,16 +55,25 @@ public class DevCommand extends CommandNode { Verify.isTrue(args.length >= 1, () -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments())))); + sender.sendMessage(" |space"); + sender.sendMessage("§l §r|fat space"); + sender.sendMessage(" |space"); + sender.sendMessage("§l §r|fat space"); + Object actual = sender.getSender(); try { Method method = actual.getClass().getMethod("sendMessage", String.class); - int indent = 8; +// int indent = new Random().nextInt(25); String msg = new TextStringBuilder().appendWithSeparators(args, " ").toString(); - method.invoke(actual, "With indent: " + indent); - method.invoke(actual, ChatFormatter.indent(indent, msg)); - method.invoke(actual, "Centered:"); +// method.invoke(actual, "With indent: " + indent); +// method.invoke(actual, ChatFormatter.leftPad(msg, indent)); +// method.invoke(actual, "Centered:"); method.invoke(actual, ChatFormatter.center(msg)); + method.invoke(actual, "Table:"); + String[] split = StringUtils.split(msg, ':'); + int columnCount = split[0].length() - split[0].replace("-", "").length(); + method.invoke(actual, ChatFormatter.columns(columnCount, split, "-")); } catch (Exception e) { e.printStackTrace(); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/utilities/chat/ChatFormatter.java b/Plan/common/src/main/java/com/djrapitops/plan/utilities/chat/ChatFormatter.java index 7bac3c230..9248356c4 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/utilities/chat/ChatFormatter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/utilities/chat/ChatFormatter.java @@ -2,16 +2,19 @@ package com.djrapitops.plan.utilities.chat; import org.apache.commons.lang3.StringUtils; +import java.util.ArrayList; +import java.util.List; + /** * Formats chat messages in different ways. *
* Original code: https://hastebin.com/uziyajirag.avrasm
*/
public class ChatFormatter {
- private final static int CENTER_PX = 154;
- private final static int MAX_PX = 250;
+ private static final int CENTER_PX = 154;
+ private static final int MAX_PX = 260;
- public static String indent(int spaces, String message) {
+ public static String leftPad(String message, int spaces) {
StringBuilder returnMessage = new StringBuilder();
String padding = StringUtils.leftPad("", spaces);
@@ -32,10 +35,104 @@ public class ChatFormatter {
line = new StringBuilder(padding);
}
}
- returnMessage.append(line.toString().trim());
+ returnMessage.append(StringUtils.chop(line.toString()));
return returnMessage.toString();
}
+ public static String columns(int columns, String[] lines, String separator) {
+ StringBuilder returnMessage = new StringBuilder();
+ List