Skip to content

Commit

Permalink
Fix: motd showing incorrect version
Browse files Browse the repository at this point in the history
  • Loading branch information
iceBear67 committed Jan 3, 2025
1 parent 2ed077c commit a733806
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import io.ib67.sfcraft.util.SFConsts;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(MinecraftServer.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerMetadata;
import net.minecraft.server.network.ServerHandshakeNetworkHandler;
import org.spongepowered.asm.mixin.Debug;
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;

@Mixin(ServerHandshakeNetworkHandler.class)
@Debug(export = true)
public abstract class ServerHandshakeNetworkHandlerMixin {
@Shadow
@Final
private ClientConnection connection;

@Redirect(method = "onHandshake", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getServerMetadata()Lnet/minecraft/server/ServerMetadata;"))
public ServerMetadata getMetadata(MinecraftServer instance) {
return SFCallbacks.MOTD.invoker().onMotd(instance,connection);
var result = SFCallbacks.MOTD.invoker().onMotd(instance,connection);
if(result == null) {
return instance.getServerMetadata();
}else{
return result;
}
}
}
10 changes: 0 additions & 10 deletions src/main/java/io/ib67/sfcraft/module/MotdModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
import com.google.inject.Inject;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import io.ib67.sfcraft.callback.SFCallbacks;
import io.ib67.sfcraft.inject.MinecraftServerSupplier;
import io.ib67.sfcraft.util.Helper;
import io.ib67.sfcraft.ServerModule;
import io.ib67.sfcraft.config.ConfigResources;
import io.ib67.sfcraft.inject.ConfigResource;
import io.ib67.sfcraft.inject.ConfigRoot;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerMetadata;

import java.nio.file.Path;
import java.util.Optional;

public class MotdModule extends ServerModule {
@Inject
Expand All @@ -29,11 +24,6 @@ public class MotdModule extends ServerModule {
@Override
public void onInitialize() {
motd = getMotd(configRoot);
SFCallbacks.MOTD.register(this::onMotd);
}

private ServerMetadata onMotd(MinecraftServer minecraftServer, ClientConnection clientConnection) {
return minecraftServer.getServerMetadata(); // it works, but who knows why?
}

@Override
Expand Down

0 comments on commit a733806

Please sign in to comment.