From c6de777f621a01f569adbe8b5be6a253131ec299 Mon Sep 17 00:00:00 2001 From: anhgelus Date: Wed, 21 Aug 2024 23:40:23 +0000 Subject: feat(player): disable chat --- src/main/java/world/anhgelus/molehunt/Molehunt.java | 3 ++- .../world/anhgelus/molehunt/mixin/NoMsgCommand.java | 17 +++++++++++++++++ src/main/resources/molehunt.mixins.json | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java (limited to 'src/main') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 4edaf24..92a28fe 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -6,6 +6,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.entity.event.v1.ServerLivingEntityEvents; import net.fabricmc.fabric.api.message.v1.ServerMessageEvents; +import net.minecraft.network.message.MessageType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; import org.slf4j.Logger; @@ -55,7 +56,7 @@ public class Molehunt implements ModInitializer { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(command)); -// ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) -> false); + ServerMessageEvents.ALLOW_CHAT_MESSAGE.register((message, sender, params) -> false); ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> { if (!(entity instanceof ServerPlayerEntity)) return; diff --git a/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java b/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java new file mode 100644 index 0000000..2727143 --- /dev/null +++ b/src/main/java/world/anhgelus/molehunt/mixin/NoMsgCommand.java @@ -0,0 +1,17 @@ +package world.anhgelus.molehunt.mixin; + +import com.mojang.brigadier.CommandDispatcher; +import net.minecraft.server.command.MessageCommand; +import net.minecraft.server.command.ServerCommandSource; +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; + +@Mixin(MessageCommand.class) +public class NoMsgCommand { + @Inject(at = @At("HEAD"), method = "register", cancellable = true) + private static void register(CommandDispatcher dispatcher, CallbackInfo ci) { + ci.cancel(); + } +} diff --git a/src/main/resources/molehunt.mixins.json b/src/main/resources/molehunt.mixins.json index 5b76af8..7ee051d 100644 --- a/src/main/resources/molehunt.mixins.json +++ b/src/main/resources/molehunt.mixins.json @@ -4,6 +4,7 @@ "package": "world.anhgelus.molehunt.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ + "NoMsgCommand" ], "injectors": { "defaultRequire": 1 -- cgit v1.2.3