Archiviert
13
0

Make exception during command conversion non-fatal

Instead of allowing chunks to fail to convert completely,
simply log the exception and the offending command. Command
conversion failure should never result in chunk data deletion,
as commands are not critical chunk data.
Dieser Commit ist enthalten in:
Spottedleaf 2024-05-13 14:40:02 -07:00
Ursprung fa8a407072
Commit bebcc9cc93

Datei anzeigen

@ -2506,10 +2506,10 @@ index 0000000000000000000000000000000000000000..084c67a46bc5ec7f5a4bef3216805a87
+}
diff --git a/src/main/java/ca/spottedleaf/dataconverter/minecraft/converters/custom/V3818_Commands.java b/src/main/java/ca/spottedleaf/dataconverter/minecraft/converters/custom/V3818_Commands.java
new file mode 100644
index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817b0a4afa0
index 0000000000000000000000000000000000000000..cd190605a2c3d8631f85a74a634f7951eec6f0b1
--- /dev/null
+++ b/src/main/java/ca/spottedleaf/dataconverter/minecraft/converters/custom/V3818_Commands.java
@@ -0,0 +1,288 @@
@@ -0,0 +1,304 @@
+package ca.spottedleaf.dataconverter.minecraft.converters.custom;
+
+import ca.spottedleaf.dataconverter.converters.DataConverter;
@ -2528,6 +2528,7 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import com.mojang.logging.LogUtils;
+import com.mojang.serialization.Dynamic;
+import com.mojang.serialization.JsonOps;
+import net.minecraft.SharedConstants;
@ -2536,6 +2537,7 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+import net.minecraft.nbt.Tag;
+import net.minecraft.nbt.TagParser;
+import net.minecraft.util.GsonHelper;
+import org.slf4j.Logger;
+import java.util.Iterator;
+import java.util.function.Supplier;
+
@ -2545,6 +2547,8 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+
+ private static final boolean DISABLE_COMMAND_CONVERTER = Boolean.getBoolean("Paper.DisableCommandConverter");
+
+ private static final Logger LOGGER = LogUtils.getLogger();
+
+ public static String toCommandFormat(final CompoundTag components) {
+ final StringBuilder ret = new StringBuilder();
+ ret.append('[');
@ -2587,12 +2591,16 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+ final String cmdString = cmd.getAsString();
+
+ if ((actionString.equals("suggest_command") && cmdString.startsWith("/")) || actionString.equals("run_command")) {
+ try {
+ final Object res = MCDataConverter.convert(
+ MCTypeRegistry.DATACONVERTER_CUSTOM_TYPE_COMMAND, cmdString, MCVersions.V1_20_4, SharedConstants.getCurrentVersion().getDataVersion().getVersion()
+ );
+ if (res instanceof String newCmd) {
+ clickEvent.addProperty("value", newCmd);
+ }
+ } catch (final Exception ex) {
+ LOGGER.error("Failed to convert command '" + cmdString + "'", ex);
+ }
+ }
+ }
+ }
@ -2684,6 +2692,9 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+ return GsonHelper.toStableString(element);
+ } catch (final JsonParseException ex) {
+ return json;
+ } catch (final Exception ex) {
+ LOGGER.error("Failed to convert text component '" + json + "'", ex);
+ return json;
+ }
+ }
+
@ -2704,7 +2715,12 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+ }
+ // We use startsWith("/") because we aren't supporting WorldEdit style commands,
+ // and passing the context of whether the use supports leading slash would be high effort low return
+ try {
+ return COMMAND_UPGRADER.get().upgradeCommandArguments(cmd, cmd.startsWith("/"));
+ } catch (final Exception ex) {
+ LOGGER.error("Failed to convert command '" + cmd + "'", ex);
+ return null;
+ }
+ }
+ });
+