2025-11-24 22:52:51 +03:00

99 lines
3.1 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.common.collect.Maps
* com.google.common.collect.Sets
* com.mojang.authlib.GameProfile
* com.mojang.authlib.minecraft.UserApiService
*/
package net.minecraft.client.gui.screens.social;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.UserApiService;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.social.SocialInteractionsScreen;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.util.Util;
public class PlayerSocialManager {
private final Minecraft minecraft;
private final Set<UUID> hiddenPlayers = Sets.newHashSet();
private final UserApiService service;
private final Map<String, UUID> discoveredNamesToUUID = Maps.newHashMap();
private boolean onlineMode;
private CompletableFuture<?> pendingBlockListRefresh = CompletableFuture.completedFuture(null);
public PlayerSocialManager(Minecraft minecraft, UserApiService service) {
this.minecraft = minecraft;
this.service = service;
}
public void hidePlayer(UUID id) {
this.hiddenPlayers.add(id);
}
public void showPlayer(UUID id) {
this.hiddenPlayers.remove(id);
}
public boolean shouldHideMessageFrom(UUID id) {
return this.isHidden(id) || this.isBlocked(id);
}
public boolean isHidden(UUID id) {
return this.hiddenPlayers.contains(id);
}
public void startOnlineMode() {
this.onlineMode = true;
this.pendingBlockListRefresh = this.pendingBlockListRefresh.thenRunAsync(() -> ((UserApiService)this.service).refreshBlockList(), Util.ioPool());
}
public void stopOnlineMode() {
this.onlineMode = false;
}
public boolean isBlocked(UUID id) {
if (!this.onlineMode) {
return false;
}
this.pendingBlockListRefresh.join();
return this.service.isBlockedPlayer(id);
}
public Set<UUID> getHiddenPlayers() {
return this.hiddenPlayers;
}
public UUID getDiscoveredUUID(String name) {
return this.discoveredNamesToUUID.getOrDefault(name, Util.NIL_UUID);
}
public void addPlayer(PlayerInfo info) {
GameProfile gameProfile = info.getProfile();
this.discoveredNamesToUUID.put(gameProfile.name(), gameProfile.id());
Screen screen = this.minecraft.screen;
if (screen instanceof SocialInteractionsScreen) {
SocialInteractionsScreen screen2 = (SocialInteractionsScreen)screen;
screen2.onAddPlayer(info);
}
}
public void removePlayer(UUID id) {
Screen screen = this.minecraft.screen;
if (screen instanceof SocialInteractionsScreen) {
SocialInteractionsScreen screen2 = (SocialInteractionsScreen)screen;
screen2.onRemovePlayer(id);
}
}
}