diff --git a/output/production/commander-bta.main/commander.accesswidener b/output/production/commander-bta.main/commander.accesswidener index 4887c74..6a64719 100644 --- a/output/production/commander-bta.main/commander.accesswidener +++ b/output/production/commander-bta.main/commander.accesswidener @@ -1,3 +1,3 @@ -accessWidener v1 named +accessWidener v2 named accessible method net/minecraft/client/gui/Gui drawRect (IIIII)V accessible method net/minecraft/client/gui/Gui drawRectWidthHeight (IIIII)V \ No newline at end of file diff --git a/output/production/commander-bta.main/net/pedroricardo/commander/Commander.class b/output/production/commander-bta.main/net/pedroricardo/commander/Commander.class index fc5775e..a7643df 100644 Binary files a/output/production/commander-bta.main/net/pedroricardo/commander/Commander.class and b/output/production/commander-bta.main/net/pedroricardo/commander/Commander.class differ diff --git a/src/main/java/net/pedroricardo/commander/BeautifulNbt.java b/src/main/java/net/pedroricardo/commander/BeautifulNbt.java new file mode 100644 index 0000000..c8bacc1 --- /dev/null +++ b/src/main/java/net/pedroricardo/commander/BeautifulNbt.java @@ -0,0 +1,76 @@ +package net.pedroricardo.commander; + +import com.mojang.nbt.*; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class BeautifulNbt { + public static String toBeautifulNbt(@NotNull CompoundTag nbt) { + StringBuilder builder = new StringBuilder("{"); + boolean comma = false; + for (Tag tag : nbt.getValue().values()) { + if (comma) builder.append(", "); + builder.append(tag.getTagName()).append(": ").append(element(tag instanceof CompoundTag ? tag : tag.getValue())); + comma = true; + } + return builder.append("}").toString(); + } + + private static String element(Object o) { + if (o instanceof byte[] || o instanceof short[] || o instanceof double[] || o instanceof List) { + return collection(o); + } + if (o instanceof Byte) { + return o + "b"; + } + if (o instanceof Short) { + return o + "s"; + } + if (o instanceof Long) { + return o + "l"; + } + if (o instanceof Float) { + return o + "f"; + } + if (o instanceof String) { + return "\"" + o + "\""; + } + return o instanceof CompoundTag ? toBeautifulNbt((CompoundTag) o) : o.toString(); + } + + private static String collection(Object o) { + StringBuilder result = new StringBuilder("["); + boolean comma = false; + if (o instanceof byte[]) { + result.append("B; "); + for (double element : ((byte[])o)) { + if (comma) result.append(", "); + result.append(element(element)); + comma = true; + } + } else if (o instanceof short[]) { + result.append("S; "); + for (double element : ((short[])o)) { + if (comma) result.append(", "); + result.append(element(element)); + comma = true; + } + } else if (o instanceof double[]) { + result.append("D; "); + for (double element : ((double[])o)) { + if (comma) result.append(", "); + result.append(element(element)); + comma = true; + } + } else if (o instanceof List) { + //noinspection unchecked + for (Tag element : ((List>)o)) { + if (comma) result.append(", "); + result.append(element(element.getValue())); + comma = true; + } + } + return result.append("]").toString(); + } +} diff --git a/src/main/java/net/pedroricardo/commander/Commander.java b/src/main/java/net/pedroricardo/commander/Commander.java index c8ebb52..a34ad54 100644 --- a/src/main/java/net/pedroricardo/commander/Commander.java +++ b/src/main/java/net/pedroricardo/commander/Commander.java @@ -1,7 +1,6 @@ package net.pedroricardo.commander; import com.google.gson.JsonObject; -import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.ModInitializer; import net.minecraft.core.net.command.TextFormatting; @@ -10,9 +9,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import turniplabs.halplibe.helper.NetworkHelper; -import turniplabs.halplibe.util.GameStartEntrypoint; -import java.text.ParseException; import java.util.ArrayList; import java.util.List; @@ -40,15 +37,6 @@ public void onInitialize() { ARGUMENT_STYLES.add(TextFormatting.ORANGE.toString()); NetworkHelper.register(CommandManagerPacket.class, false, true); NetworkHelper.register(RequestCommandManagerPacket.class, true, false); -// try { -// System.out.println(NbtHelper.parseNbt("{Data1:16,Data2:\"hello\",Data3:[D;1.52,940.2,38.3],Data4:[B;1b,12b]}")); -// System.out.println(NbtHelper.parseNbt("{DataShort:23s,DataInt:39230,DataString:\"Hello!\"}")); -// System.out.println(NbtHelper.parseNbt("{DataBoolTrue:true,DataBoolFalse:false,DataByte:22b, DataShort : 51s, DataInt:42351, DataLong: 2934021941L, DataFloat: 3.1415926f, DataDouble: 22.543d, DataDoubleNoSuffix: 2942.43290}")); -// System.out.println(NbtHelper.parseNbt("{DataByteArray:[B;6b,12b,24b] ,DataShortArray:[S ; 20s , 40s , 63s ] , DataDoubleArray:[D ; 22.53, 239.43d, 39.4D]}")); -// System.out.println(NbtHelper.parseNbt("{DataList:[6b,12b,24b]}")); -// } catch (CommandSyntaxException e) { -// System.out.println(e.getMessage()); -// } } @Override diff --git a/src/main/java/net/pedroricardo/commander/NbtHelper.java b/src/main/java/net/pedroricardo/commander/NbtHelper.java index f379838..f0d8448 100644 --- a/src/main/java/net/pedroricardo/commander/NbtHelper.java +++ b/src/main/java/net/pedroricardo/commander/NbtHelper.java @@ -10,12 +10,12 @@ import java.util.regex.Pattern; public class NbtHelper { - private static final Pattern DOUBLE_PATTERN_NO_SUFFIX = Pattern.compile("[-+]?(?:[0-9]+[.]|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?", 2); - private static final Pattern DOUBLE_PATTERN = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?d", 2); - private static final Pattern FLOAT_PATTERN = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?f", 2); - private static final Pattern BYTE_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)b", 2); - private static final Pattern LONG_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)l", 2); - private static final Pattern SHORT_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)s", 2); + private static final Pattern DOUBLE_PATTERN_NO_SUFFIX = Pattern.compile("[-+]?(?:[0-9]+[.]|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?", Pattern.CASE_INSENSITIVE); + private static final Pattern DOUBLE_PATTERN = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?d", Pattern.CASE_INSENSITIVE); + private static final Pattern FLOAT_PATTERN = Pattern.compile("[-+]?(?:[0-9]+[.]?|[0-9]*[.][0-9]+)(?:e[-+]?[0-9]+)?f", Pattern.CASE_INSENSITIVE); + private static final Pattern BYTE_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)b", Pattern.CASE_INSENSITIVE); + private static final Pattern LONG_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)l", Pattern.CASE_INSENSITIVE); + private static final Pattern SHORT_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)s", Pattern.CASE_INSENSITIVE); private static final Pattern INT_PATTERN = Pattern.compile("[-+]?(?:0|[1-9][0-9]*)"); public static CompoundTag parseNbt(String string) throws CommandSyntaxException { @@ -53,7 +53,7 @@ public static CompoundTag parseNbt(StringReader reader) throws CommandSyntaxExce return tag; } - private static Tag parseTag(StringReader reader) throws CommandSyntaxException { + public static Tag parseTag(StringReader reader) throws CommandSyntaxException { if (!reader.canRead()) throw CommanderExceptions.incomplete().create(); if (reader.peek() == '{') { return parseNbt(reader); diff --git a/src/main/resources/commander.accesswidener b/src/main/resources/commander.accesswidener index 4887c74..6a64719 100644 --- a/src/main/resources/commander.accesswidener +++ b/src/main/resources/commander.accesswidener @@ -1,3 +1,3 @@ -accessWidener v1 named +accessWidener v2 named accessible method net/minecraft/client/gui/Gui drawRect (IIIII)V accessible method net/minecraft/client/gui/Gui drawRectWidthHeight (IIIII)V \ No newline at end of file