When using /unpublish in a singleplayer world that is not published, even though the command correctly shows a failure message, it actually technically succeeds, which can break data packs expecting the command’s success value to be 0.
How to reproduce:
Open a singleplayer world and don’t enable multiplayer.
Execute the following command:
/execute store success storage mc-308405:test success_value int 1 run unpublishExecute the following command:
/data get storage mc-308405:test success_value→ ❌ The value stored is 1, indicating the command executed by the
runargument of the first command succeeded.
Expected result:
The /unpublish command would fail when the game is not published.
Observed result:
The /unpublish command succeeds when the game is not published despite a failure message being sent.
Code analysis:
This code analysis uses 26.2 Snapshot 8’s code, decompiled using Vineflower.
In the net.minecraft.server.commands.UnpublishCommand class, there is a method called unpublish, which is called when the command is run. This method is shown below:
private static int unpublish(final CommandSourceStack source) {
if (source.getServer().unpublishServer()) {
source.sendSuccess(() -> Component.translatable("commands.unpublish.success"), true);
return 1;
} else {
source.sendFailure(Component.translatable("commands.unpublish.notPublished"));
return 0;
}
}The method tries to unpublish the integrated server, and if it fails (if the game wasn’t published), it sends a failure message and returns a Brigadier return value. When a command returns a value, it is considered successful, and its success value is therefore set to 1. Most other commands, when failing, throw a CommandSyntaxException instead of returning a value, since the game only sets a command’s success value to 0 when such an exception is thrown.
Comments 0
No comments.