Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #481 #487

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading