Add mixins for /msg and /me commands to post events

This commit is contained in:
Xujiayao 2026-03-19 10:51:35 +08:00
parent a2fb89616a
commit a3a03244f2
4 changed files with 79 additions and 0 deletions

View file

@ -110,6 +110,24 @@ public class MinecraftEvents {
) {
}
/**
* Posted when the /msg, /tell, /w command is used.
*/
public record SourceMsg(
CommandContext<CommandSourceStack> commandContext,
PlayerChatMessage playerChatMessage
) {
}
/**
* Posted when the /me command is used.
*/
public record SourceMe(
CommandContext<CommandSourceStack> commandContext,
PlayerChatMessage playerChatMessage
) {
}
/**
* Posted when commands are being registered.
*/

View file

@ -0,0 +1,28 @@
package com.xujiayao.discord_mc_chat.minecraft.mixins;
import com.mojang.brigadier.context.CommandContext;
import com.xujiayao.discord_mc_chat.minecraft.events.MinecraftEvents;
import com.xujiayao.discord_mc_chat.utils.events.EventManager;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.server.commands.EmoteCommands;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* @author Xujiayao
*/
@Mixin(EmoteCommands.class)
public class MixinEmoteCommands {
@Inject(method = "lambda$register$0", at = @At("HEAD"))
private static void lambda$register$0(CommandContext<CommandSourceStack> commandContext, PlayerChatMessage playerChatMessage, CallbackInfo ci) {
// SourceMe Event
EventManager.post(new MinecraftEvents.SourceMe(
commandContext,
playerChatMessage
));
}
}

View file

@ -0,0 +1,31 @@
package com.xujiayao.discord_mc_chat.minecraft.mixins;
import com.mojang.brigadier.context.CommandContext;
import com.xujiayao.discord_mc_chat.minecraft.events.MinecraftEvents;
import com.xujiayao.discord_mc_chat.utils.events.EventManager;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.server.commands.MsgCommand;
import net.minecraft.server.level.ServerPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Collection;
/**
* @author Xujiayao
*/
@Mixin(MsgCommand.class)
public class MixinMsgCommand {
@Inject(method = "lambda$register$0", at = @At("HEAD"))
private static void lambda$register$0(CommandContext<CommandSourceStack> commandContext, Collection<ServerPlayer> collection, PlayerChatMessage playerChatMessage, CallbackInfo ci) {
// SourceMsg Event
EventManager.post(new MinecraftEvents.SourceMsg(
commandContext,
playerChatMessage
));
}
}

View file

@ -4,7 +4,9 @@
"compatibilityLevel": "JAVA_25",
"mixins": [
"MixinCommands",
"MixinEmoteCommands",
"MixinMinecraftServer",
"MixinMsgCommand",
"MixinPlayerAdvancements",
"MixinPlayerList",
"MixinReloadableServerResources",