Fixed the same thing for 1.21.5
This commit is contained in:
@@ -127,4 +127,36 @@ public abstract class MinecraftClientMixin implements MinecraftClientRef {
|
|||||||
public void executeOnThread(Runnable runnable) {
|
public void executeOnThread(Runnable runnable) {
|
||||||
((java.util.concurrent.Executor) (Object) this).execute(runnable);
|
((java.util.concurrent.Executor) (Object) this).execute(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public String getPlayerListEntry(UUID uuid) {
|
||||||
|
var client = (MinecraftClient) (Object) this;
|
||||||
|
var handler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (handler == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var entry = handler.getPlayerListEntry(uuid);
|
||||||
|
if (entry == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return entry.getProfile().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("resource")
|
||||||
|
public UUID getPlayerListEntryUUID(String name) {
|
||||||
|
var client = (MinecraftClient) (Object) this;
|
||||||
|
var handler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (handler == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var entry = handler.getPlayerListEntry(name);
|
||||||
|
if (entry == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return entry.getProfile().getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package org.saturnclient.saturnclient;
|
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
|
||||||
|
|
||||||
import org.saturnclient.client.ServiceClient;
|
|
||||||
|
|
||||||
import net.minecraft.client.network.PlayerListEntry;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
|
|
||||||
public class PlayerTracker {
|
|
||||||
private static Set<UUID> trackedPlayers = new HashSet<>();
|
|
||||||
|
|
||||||
public static void initialize() {
|
|
||||||
// When client joins a server, reset tracked players
|
|
||||||
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
|
|
||||||
trackedPlayers.clear();
|
|
||||||
client.execute(() -> {
|
|
||||||
checkForNewPlayers(SaturnClient.client);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check for new players every tick
|
|
||||||
ClientTickEvents.END_CLIENT_TICK.register(client -> checkForNewPlayers(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkForNewPlayers(MinecraftClient client) {
|
|
||||||
if (client.getNetworkHandler() == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (PlayerListEntry player : client.getNetworkHandler().getPlayerList()) {
|
|
||||||
UUID playerUUID = player.getProfile().getId();
|
|
||||||
|
|
||||||
if (!trackedPlayers.contains(playerUUID)) {
|
|
||||||
// A new player has joined
|
|
||||||
onPlayerJoin(client, player);
|
|
||||||
trackedPlayers.add(playerUUID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void onPlayerJoin(MinecraftClient client, PlayerListEntry player) {
|
|
||||||
GameProfile profile = player.getProfile();
|
|
||||||
ServiceClient.player(profile.getId(), profile.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user