Skip to content

Commit 27a216b

Browse files
committed
Implement and use getPlayerSkin?
Signed-off-by: BT (calcastor/mame) <43831917+calcastor@users.noreply.github.com>
1 parent a5772e0 commit 27a216b

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

platform/platform-modern/src/main/java/dev/pgm/community/platform/modern/ModernPlayerUtils.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public String getPlayerDisplayName(Player player, Player viewer) {
5656
if (playerDisplayNames.containsKey(player.getUniqueId())) {
5757
Map<UUID, String> uuidStringMap = playerDisplayNames.get(player.getUniqueId());
5858
String displayName = uuidStringMap.get(viewer.getUniqueId());
59-
return displayName == null ? player.getDisplayName() : displayName;
59+
if (displayName != null) return displayName;
6060
}
6161
return player.getDisplayName();
6262
}
@@ -66,23 +66,19 @@ public String getPlayerName(Player player, Player viewer) {
6666
if (playerNames.containsKey(player.getUniqueId())) {
6767
Map<UUID, String> uuidStringMap = playerNames.get(player.getUniqueId());
6868
String name = uuidStringMap.get(viewer.getUniqueId());
69-
return name == null ? player.getName() : name;
69+
if (name != null) return name;
7070
}
7171
return player.getName();
7272
}
7373

7474
@Override
7575
public Skin getPlayerSkin(Player player, Player viewer) {
76-
return null;
77-
// if (playerSkins.containsKey(player.getUniqueId())) {
78-
// Map<UUID, Skin> uuidSkinMap = playerSkins.get(player.getUniqueId());
79-
// Skin skin = uuidSkinMap.get(viewer.getUniqueId());
80-
// if (skin == null) {
81-
// return new Skin(player.getPlayerProfile().getTextures())
82-
// }
83-
// return skin == null ? Skin.EMPTY : skin;
84-
// }
85-
// return Skin.EMPTY;
76+
if (playerSkins.containsKey(player.getUniqueId())) {
77+
Map<UUID, Skin> uuidSkinMap = playerSkins.get(player.getUniqueId());
78+
Skin skin = uuidSkinMap.get(viewer.getUniqueId());
79+
if (skin != null) return skin;
80+
}
81+
return getPlayerSkin(player);
8682
}
8783

8884
@Override

platform/platform-modern/src/main/java/dev/pgm/community/platform/modern/PacketManipulations.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.comphenix.protocol.wrappers.PlayerInfoData;
1010
import com.comphenix.protocol.wrappers.WrappedChatComponent;
1111
import com.comphenix.protocol.wrappers.WrappedGameProfile;
12+
import com.comphenix.protocol.wrappers.WrappedSignedProperty;
1213
import java.util.List;
1314
import java.util.Map;
1415
import java.util.Objects;
@@ -19,6 +20,7 @@
1920
import org.bukkit.plugin.Plugin;
2021
import tc.oc.pgm.platform.modern.packets.PacketSender;
2122
import tc.oc.pgm.platform.modern.util.Packets;
23+
import tc.oc.pgm.util.skin.Skin;
2224

2325
public class PacketManipulations implements PacketSender {
2426

@@ -47,7 +49,7 @@ private void handlePlayerInfo(PacketEvent event) {
4749
.write(
4850
0,
4951
infoList.stream()
50-
.map((playerInfoData -> {
52+
.map(playerInfoData -> {
5153
UUID playerId = playerInfoData.getProfileId();
5254
Player player = Bukkit.getPlayer(playerId);
5355
if (player == null || player.equals(viewer) || !player.isOnline()) {
@@ -63,11 +65,13 @@ private void handlePlayerInfo(PacketEvent event) {
6365

6466
WrappedGameProfile playerProfile =
6567
playerInfoData.getProfile().withName(playerName);
66-
playerInfoData
67-
.getProfile()
68+
Skin skin = PLAYER_UTILS.getPlayerSkin(player, viewer);
69+
playerProfile
6870
.getProperties()
69-
.forEach(
70-
(key, property) -> playerProfile.getProperties().put(key, property));
71+
.put(
72+
"textures",
73+
new WrappedSignedProperty(
74+
"textures", skin.getData(), skin.getSignature()));
7175

7276
return new PlayerInfoData(
7377
playerId,
@@ -76,7 +80,7 @@ private void handlePlayerInfo(PacketEvent event) {
7680
playerInfoData.getGameMode(),
7781
playerProfile,
7882
WrappedChatComponent.fromLegacyText(playerDisplayName));
79-
}))
83+
})
8084
.toList());
8185
}
8286
}

0 commit comments

Comments
 (0)