aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSpottedleaf <[email protected]>2024-05-13 14:40:02 -0700
committerSpottedleaf <[email protected]>2024-05-13 14:40:02 -0700
commitbebcc9cc933bd13a841844c250dcb83bd132a8e7 (patch)
tree070986e2d4ecfc1a22e050e818e6c66bed8ed42f
parentfa8a407072c320564c39d32d2d221550c3e6d5b6 (diff)
downloadPaper-bebcc9cc933bd13a841844c250dcb83bd132a8e7.tar.gz
Paper-bebcc9cc933bd13a841844c250dcb83bd132a8e7.zip
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.
-rw-r--r--patches/server/0975-Rewrite-dataconverter-system.patch32
1 files changed, 24 insertions, 8 deletions
diff --git a/patches/server/0975-Rewrite-dataconverter-system.patch b/patches/server/0975-Rewrite-dataconverter-system.patch
index a9ae9021b3..e96c877748 100644
--- a/patches/server/0975-Rewrite-dataconverter-system.patch
+++ b/patches/server/0975-Rewrite-dataconverter-system.patch
@@ -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,11 +2591,15 @@ index 0000000000000000000000000000000000000000..7cd980b32ce45af9de1849d61b8f1817
+ final String cmdString = cmd.getAsString();
+
+ if ((actionString.equals("suggest_command") && cmdString.startsWith("/")) || actionString.equals("run_command")) {
-+ 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);
++ 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
-+ return COMMAND_UPGRADER.get().upgradeCommandArguments(cmd, cmd.startsWith("/"));
++ try {
++ return COMMAND_UPGRADER.get().upgradeCommandArguments(cmd, cmd.startsWith("/"));
++ } catch (final Exception ex) {
++ LOGGER.error("Failed to convert command '" + cmd + "'", ex);
++ return null;
++ }
+ }
+ });
+