mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
@@ -20,28 +20,34 @@
|
||||
package dev.architectury.mixin.fabric;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import dev.architectury.event.events.common.CommandPerformEvent;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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.ModifyVariable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Commands.class)
|
||||
public class MixinCommands {
|
||||
@Redirect(method = "performCommand",
|
||||
at = @At(value = "INVOKE", target = "Lcom/mojang/brigadier/CommandDispatcher;execute(Lcom/mojang/brigadier/ParseResults;)I", remap = false))
|
||||
private int performCommand(CommandDispatcher<CommandSourceStack> dispatcher, ParseResults<CommandSourceStack> results) throws CommandSyntaxException {
|
||||
@ModifyVariable(method = "performCommand",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;validateParseResults(Lcom/mojang/brigadier/ParseResults;)V", remap = false), argsOnly = true)
|
||||
private ParseResults<CommandSourceStack> performCommand(ParseResults<CommandSourceStack> results) {
|
||||
var event = new CommandPerformEvent(results, null);
|
||||
if (CommandPerformEvent.EVENT.invoker().act(event).isPresent()) {
|
||||
if (event.getThrowable() != null) {
|
||||
Throwables.throwIfUnchecked(event.getThrowable());
|
||||
}
|
||||
return 1;
|
||||
return null;
|
||||
}
|
||||
return dispatcher.execute(event.getResults());
|
||||
return event.getResults();
|
||||
}
|
||||
|
||||
@Inject(method = "performCommand",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/commands/Commands;validateParseResults(Lcom/mojang/brigadier/ParseResults;)V", remap = false), cancellable = true)
|
||||
private void performCommand(ParseResults<CommandSourceStack> results, String command, CallbackInfo ci) {
|
||||
if (results == null) ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ org.gradle.daemon=false
|
||||
|
||||
platforms=fabric
|
||||
|
||||
minecraft_version=23w40a
|
||||
supported_version=23w40a
|
||||
minecraft_version=23w41a
|
||||
supported_version=23w41a
|
||||
|
||||
artifact_type=beta
|
||||
|
||||
@@ -14,7 +14,7 @@ base_version=11.0
|
||||
maven_group=dev.architectury
|
||||
|
||||
fabric_loader_version=0.14.23
|
||||
fabric_api_version=0.89.4+1.20.3
|
||||
fabric_api_version=0.90.1+1.20.3
|
||||
mod_menu_version=7.0.0
|
||||
|
||||
forge_version=48.0.1
|
||||
|
||||
@@ -73,6 +73,11 @@ public class DebugEvents {
|
||||
return EventResult.interruptTrue();
|
||||
});
|
||||
CommandPerformEvent.EVENT.register(event -> {
|
||||
if (event.getResults().getReader().getString().startsWith("help")) {
|
||||
TestMod.SINK.accept("Cancelling help command as a test!");
|
||||
return EventResult.interruptFalse();
|
||||
}
|
||||
|
||||
TestMod.SINK.accept("Server command performed: " + event.getResults().getReader().getString());
|
||||
return EventResult.pass();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user