Skip to content

Commit

Permalink
Fixes #481 (#487)
Browse files Browse the repository at this point in the history
* Fixes #481

* Update some javadocs

* Just in case, you never know

---------

Co-authored-by: Aizistral <[email protected]>
  • Loading branch information
pietro-lopes and Aizistral authored Oct 28, 2024
1 parent 0400e5f commit 58ec132
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 110 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"client": [
"client.MixinClientConnection",
"client.MixinClientHandshakePacketListenerImpl",
"client.MixinClientPacketListener",
"client.MixinServerStatusPinger$1"
"client.MixinClientPacketListener"
],
"server": [],
"injectors": {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"client": [
"client.MixinClientConnection",
"client.MixinClientHandshakePacketListenerImpl",
"client.MixinClientPacketListener",
"client.MixinServerStatusPinger$1"
"client.MixinClientPacketListener"
],
"server": [],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.aizistral.nochatreports.common.mixins.client;

import java.lang.reflect.Field;
import java.net.InetSocketAddress;

import net.minecraft.client.multiplayer.ServerStatusPinger;
import net.minecraft.client.multiplayer.resolver.ServerAddress;
import net.minecraft.network.Connection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -12,28 +16,43 @@
import com.aizistral.nochatreports.common.core.ServerDataExtension;
import com.aizistral.nochatreports.common.platform.extensions.ServerPingerExtension;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
import net.minecraft.network.protocol.status.ServerStatus;


/**
* This one ensures "preventsChatReports" property is transferred from {@link ServerStatus} to
* {@link ServerData} when handling status response.
* @author fxmorin (original implementation)
* @author Aizistral (current version)
* @author pietro-lopes (fixed https://github.com/Aizistral-Studios/No-Chat-Reports/issues/481)
*/

@Mixin(targets = "net/minecraft/client/multiplayer/ServerStatusPinger$1")
public abstract class MixinServerStatusPinger$1 implements ServerPingerExtension {

/**
* @reason Ensure "preventsChatReports" property is transferred from {@link ServerStatus} to
* {@link ServerData} when handling status response.
* @author fxmorin (original implementation)
* @author Aizistral (current version)
*/
@Unique
private ServerDataExtension nochatreports$serverData;

@Inject(method = "<init>", at = @At("RETURN"))
private void captureServerData(ServerStatusPinger serverStatusPinger, Connection connection, ServerData serverData, Runnable runnable, Runnable runnable2, InetSocketAddress inetSocketAddress, ServerAddress serverAddress, CallbackInfo ci){
this.nochatreports$serverData = (ServerDataExtension) serverData;
}

@Inject(method = "handleStatusResponse(Lnet/minecraft/network/protocol/status/ClientboundStatusResponsePacket;)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/status/ServerStatus;"
+ "description()Lnet/minecraft/network/chat/Component;",
ordinal = 0, shift = At.Shift.BEFORE))
+ "description()Lnet/minecraft/network/chat/Component;"))
private void getNoChatReports(ClientboundStatusResponsePacket packet, CallbackInfo info) {
boolean preventsReports = ((ServerDataExtension) (Object) packet.status()).preventsChatReports();
((ServerDataExtension) this.getServerData()).setPreventsChatReports(preventsReports);

if (this.nochatreports$serverData == null) {
NCRCore.LOGGER.error("Failed to capture ServerData instance in MixinServerStatusPinger$1!");
NCRCore.LOGGER.catching(new IllegalStateException());
return;
}

this.nochatreports$serverData.setPreventsChatReports(preventsReports);

if (NCRConfig.getCommon().enableDebugLog()) {
NCRCore.LOGGER.info("Received status response packet from server, preventsChatReports: {}",
Expand Down

0 comments on commit 58ec132

Please sign in to comment.