mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-25 22:39:50 -04:00
Update command api to use new non-tail constructor inject (#1140)
* Update command api to use new non-tail constructor inject This removes a redirect in fabric api and fixes the location of the command api's icon. * Update lifecycle events for command-api-v1 testmod
This commit is contained in:
parent
25b143484c
commit
74aedfbe43
7 changed files with 32 additions and 32 deletions
build.gradle
fabric-command-api-v1
build.gradle
src
main
java/net/fabricmc/fabric/mixin/command
resources
testmod/java/net/fabricmc/fabric/test/command
|
@ -21,7 +21,7 @@ class Globals {
|
|||
static def baseVersion = "0.24.1"
|
||||
static def mcVersion = "1.16.3"
|
||||
static def yarnVersion = "+build.47"
|
||||
static def loaderVersion = "0.10.3+build.211"
|
||||
static def loaderVersion = "0.10.5+build.213"
|
||||
}
|
||||
|
||||
version = Globals.baseVersion + "+" + (ENV.BUILD_NUMBER ? ("build." + ENV.BUILD_NUMBER) : "local") + "-" + getBranch()
|
||||
|
|
|
@ -4,5 +4,5 @@ version = getSubprojectVersion(project, "1.0.8")
|
|||
dependencies {
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
|
||||
testmodCompile project(path: ':fabric-events-lifecycle-v0', configuration: 'dev')
|
||||
testmodCompile project(path: ':fabric-lifecycle-events-v1', configuration: 'dev')
|
||||
}
|
||||
|
|
|
@ -16,11 +16,13 @@
|
|||
|
||||
package net.fabricmc.fabric.mixin.command;
|
||||
|
||||
import com.mojang.brigadier.AmbiguityConsumer;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
@ -28,14 +30,20 @@ import net.minecraft.server.command.ServerCommandSource;
|
|||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
|
||||
@Mixin(CommandManager.class)
|
||||
public abstract class MixinCommandManager {
|
||||
public abstract class CommandManagerMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private CommandDispatcher<ServerCommandSource> dispatcher;
|
||||
|
||||
/**
|
||||
* Wait an inject in a constructor?
|
||||
* This is a new addition to Fabric's fork of mixin.
|
||||
* If you are not using fabric's fork of mixin this will fail.
|
||||
*
|
||||
* @reason Add commands before ambiguities are calculated.
|
||||
*/
|
||||
@Redirect(at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V"), method = "<init>")
|
||||
private void fabric_addCommands(CommandDispatcher<ServerCommandSource> dispatcher, AmbiguityConsumer<ServerCommandSource> ambiguityConsumer, CommandManager.RegistrationEnvironment registrationEnvironment) {
|
||||
CommandRegistrationCallback.EVENT.invoker().register(dispatcher, registrationEnvironment == CommandManager.RegistrationEnvironment.DEDICATED);
|
||||
|
||||
dispatcher.findAmbiguities(ambiguityConsumer);
|
||||
@Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;findAmbiguities(Lcom/mojang/brigadier/AmbiguityConsumer;)V"), method = "<init>")
|
||||
private void fabric_addCommands(CommandManager.RegistrationEnvironment environment, CallbackInfo ci) {
|
||||
CommandRegistrationCallback.EVENT.invoker().register(this.dispatcher, environment == CommandManager.RegistrationEnvironment.DEDICATED);
|
||||
}
|
||||
}
|
Before ![]() (image error) Size: 1.5 KiB After ![]() (image error) Size: 1.5 KiB ![]() ![]() |
|
@ -3,7 +3,7 @@
|
|||
"package": "net.fabricmc.fabric.mixin.command",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinCommandManager"
|
||||
"CommandManagerMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"FabricMC"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=0.8.8",
|
||||
"fabricloader": ">=0.10.5",
|
||||
"fabric-api-base": "*"
|
||||
},
|
||||
"description": "Adds command-related hooks.",
|
||||
|
|
|
@ -31,15 +31,13 @@ import net.minecraft.text.LiteralText;
|
|||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.server.ServerTickCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
|
||||
public class CommandTest implements ModInitializer {
|
||||
public final class CommandTest implements ModInitializer {
|
||||
private static final Logger LOGGER = LogManager.getLogger(CommandTest.class);
|
||||
private static final SimpleCommandExceptionType WRONG_SIDE_SHOULD_BE_INTEGRATED = new SimpleCommandExceptionType(new LiteralText("This command was registered incorrectly. Should only be present on an integrated server but was ran on a dedicated server!"));
|
||||
private static final SimpleCommandExceptionType WRONG_SIDE_SHOULD_BE_DEDICATED = new SimpleCommandExceptionType(new LiteralText("This command was registered incorrectly. Should only be present on an dedicated server but was ran on an integrated server!"));
|
||||
|
||||
private boolean hasTested = false;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
|
||||
|
@ -55,50 +53,44 @@ public class CommandTest implements ModInitializer {
|
|||
}
|
||||
});
|
||||
|
||||
// Use the ServerTickCallback to verify the commands actually exist in the command dispatcher.
|
||||
ServerTickCallback.EVENT.register(server -> {
|
||||
// Don't run the test more than once
|
||||
if (this.hasTested) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||
// Verify the commands actually exist in the command dispatcher.
|
||||
final boolean dedicated = server.isDedicated();
|
||||
final RootCommandNode<ServerCommandSource> rootNode = server.getCommandManager().getDispatcher().getRoot();
|
||||
|
||||
// Now we climb the tree
|
||||
final CommandNode<ServerCommandSource> fabric_common_test_command = rootNode.getChild("fabric_common_test_command");
|
||||
final CommandNode<ServerCommandSource> fabric_dedicated_test_command = rootNode.getChild("fabric_dedicated_test_command");
|
||||
final CommandNode<ServerCommandSource> fabric_integrated_test_command = rootNode.getChild("fabric_integrated_test_command");
|
||||
final CommandNode<ServerCommandSource> fabricCommonTestCommand = rootNode.getChild("fabric_common_test_command");
|
||||
final CommandNode<ServerCommandSource> fabricDedicatedTestCommand = rootNode.getChild("fabric_dedicated_test_command");
|
||||
final CommandNode<ServerCommandSource> fabricIntegratedTestCommand = rootNode.getChild("fabric_integrated_test_command");
|
||||
|
||||
// Verify the common command exists
|
||||
if (fabric_common_test_command == null) {
|
||||
if (fabricCommonTestCommand == null) {
|
||||
throw new AssertionError("Expected to find 'fabric_common_test_command' on the server's command dispatcher. But it was not found.");
|
||||
}
|
||||
|
||||
if (dedicated) {
|
||||
// Verify we don't have the integrated command
|
||||
if (fabric_integrated_test_command != null) {
|
||||
if (fabricIntegratedTestCommand != null) {
|
||||
throw new AssertionError("Found 'fabric_integrated_test_command' on the dedicated server's command dispatcher. This should not happen!");
|
||||
}
|
||||
|
||||
// Verify we have the dedicated command
|
||||
if (fabric_dedicated_test_command == null) {
|
||||
if (fabricDedicatedTestCommand == null) {
|
||||
throw new AssertionError("Expected to find 'fabric_dedicated_test_command' on the dedicated server's command dispatcher. But it was not found.");
|
||||
}
|
||||
} else {
|
||||
// Verify we don't have the dedicated command
|
||||
if (fabric_dedicated_test_command != null) {
|
||||
if (fabricDedicatedTestCommand != null) {
|
||||
throw new AssertionError("Found 'fabric_dedicated_test_command' on the integrated server's command dispatcher. This should not happen!");
|
||||
}
|
||||
|
||||
// Verify we have the integrated command
|
||||
if (fabric_integrated_test_command == null) {
|
||||
if (fabricIntegratedTestCommand == null) {
|
||||
throw new AssertionError("Expected to find 'fabric_integrated_test_command' on the integrated server's command dispatcher. But it was not found.");
|
||||
}
|
||||
}
|
||||
|
||||
// Success!
|
||||
this.hasTested = true;
|
||||
CommandTest.LOGGER.info("The command tests have passed! Please make sure you execute the three commands for extra safety.");
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue