feat: add mixin login/leave messages
Build and Release / build (push) Successful in 20m11s Details

This commit is contained in:
itqop 2025-11-11 22:47:38 +03:00
parent 4e5682c6b1
commit 998157c3c9
4 changed files with 35 additions and 28 deletions

View File

@ -29,7 +29,7 @@ mod_name=whitelist
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=All Rights Reserved
# The mod version. See https://semver.org/
mod_version=0.1-BETA
mod_version=0.2-BETA
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@ -4,34 +4,18 @@ import net.minecraft.network.chat.Component;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(PlayerList.class)
public class PlayerListMixin {
public abstract class PlayerListMixin {
/**
* Suppress ALL player join/leave messages
* Intercepts ALL calls to broadcastSystemMessage and filters out join/leave messages
*/
@ModifyArg(method = "*",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"),
index = 0)
private Component suppressJoinLeaveMessages(Component original) {
String messageString = original.getString();
// Check if this is a join or leave message
// Common patterns: "Player joined the game", "Player left the game"
// Russian: "Игрок присоединился к игре", "Игрок покинул игру"
if (messageString.contains("joined the game") ||
messageString.contains("left the game") ||
messageString.contains("присоединился") ||
messageString.contains("покинул")) {
// Return empty component to suppress the message
return Component.empty();
}
// For all other messages, return the original
return original;
@Redirect(
method = "placeNewPlayer",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"
)
)
private void itqop$skipJoinBroadcast(PlayerList self, Component message, boolean bypassHiddenChat) {
}
}

View File

@ -0,0 +1,22 @@
package org.itqop.whitelist.mixin;
import net.minecraft.network.chat.Component;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ServerGamePacketListenerImpl.class)
public abstract class ServerGamePacketListenerMixin {
@Redirect(
method = "removePlayerFromWorld",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/players/PlayerList;broadcastSystemMessage(Lnet/minecraft/network/chat/Component;Z)V"
)
)
private void itqop$skipLeaveBroadcast(PlayerList list, Component message, boolean overlay) {
}
}

View File

@ -5,7 +5,8 @@
"compatibilityLevel": "JAVA_21",
"refmap": "whitelist.refmap.json",
"mixins": [
"PlayerListMixin"
"PlayerListMixin",
"ServerGamePacketListenerMixin"
],
"injectors": {
"defaultRequire": 1