From db9293e658a070a74cc9ff8654cc73b8f03c0a93 Mon Sep 17 00:00:00 2001 From: Basique Date: Sun, 14 May 2023 02:16:34 +0300 Subject: [PATCH] restrict /e4mc stop and touchup mixin --- .../skye/e4mc_minecraft/mixins/ServerNetworkIoMixin.java | 7 ++++--- src/main/kotlin/vg/skye/e4mc_minecraft/E4mcClient.kt | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/vg/skye/e4mc_minecraft/mixins/ServerNetworkIoMixin.java b/src/main/java/vg/skye/e4mc_minecraft/mixins/ServerNetworkIoMixin.java index efede88..180221b 100644 --- a/src/main/java/vg/skye/e4mc_minecraft/mixins/ServerNetworkIoMixin.java +++ b/src/main/java/vg/skye/e4mc_minecraft/mixins/ServerNetworkIoMixin.java @@ -11,6 +11,7 @@ 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.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import vg.skye.e4mc_minecraft.E4mcClient; @@ -45,9 +46,9 @@ public abstract class ServerNetworkIoMixin { } } - @Redirect(method = "bind", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/ServerBootstrap;channel(Ljava/lang/Class;)Lio/netty/bootstrap/AbstractBootstrap;", remap = false)) - private AbstractBootstrap redirectChannel(ServerBootstrap instance, Class aClass) { - return initializingE4mc.get() ? instance.channel(LocalServerChannel.class) : instance.channel(aClass); + @ModifyArg(method = "bind", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/ServerBootstrap;channel(Ljava/lang/Class;)Lio/netty/bootstrap/AbstractBootstrap;", remap = false)) + private Class redirectChannel(Class aClass) { + return initializingE4mc.get() ? LocalServerChannel.class : aClass; } @Redirect(method = "bind", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/ServerBootstrap;localAddress(Ljava/net/InetAddress;I)Lio/netty/bootstrap/AbstractBootstrap;", remap = false)) diff --git a/src/main/kotlin/vg/skye/e4mc_minecraft/E4mcClient.kt b/src/main/kotlin/vg/skye/e4mc_minecraft/E4mcClient.kt index 5a53a8c..6a9a090 100644 --- a/src/main/kotlin/vg/skye/e4mc_minecraft/E4mcClient.kt +++ b/src/main/kotlin/vg/skye/e4mc_minecraft/E4mcClient.kt @@ -49,6 +49,13 @@ object E4mcClient : ModInitializer { dispatcher.register(literal("e4mc") .then( literal("stop") + .requires { src -> + if (src.server.isDedicated) { + src.hasPermissionLevel(4) + } else { + src.server.isHost((src.player ?: return@requires false).gameProfile) + } + } .executes { context -> if (HANDLER != null) { HANDLER!!.close()