|
2 | 2 |
|
3 | 3 | import static dev.pgm.community.util.Supports.Variant.PAPER; |
4 | 4 |
|
| 5 | +import com.comphenix.protocol.events.PacketEvent; |
5 | 6 | import com.destroystokyo.paper.profile.CraftPlayerProfile; |
6 | 7 | import com.destroystokyo.paper.profile.PlayerProfile; |
| 8 | +import com.google.common.collect.ImmutableMultimap; |
| 9 | +import com.mojang.authlib.GameProfile; |
| 10 | +import com.mojang.authlib.properties.Property; |
| 11 | +import com.mojang.authlib.properties.PropertyMap; |
7 | 12 | import dev.pgm.community.util.PlayerUtils; |
8 | 13 | import dev.pgm.community.util.Supports; |
9 | 14 | import dev.pgm.community.utils.MessageUtils; |
|
12 | 17 | import java.net.URISyntaxException; |
13 | 18 | import java.util.Arrays; |
14 | 19 | import java.util.HashMap; |
| 20 | +import java.util.List; |
15 | 21 | import java.util.Map; |
16 | 22 | import java.util.UUID; |
| 23 | +import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; |
| 24 | +import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; |
| 25 | +import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket; |
| 26 | +import net.minecraft.server.level.ServerPlayer; |
| 27 | +import net.minecraft.world.scores.PlayerTeam; |
| 28 | +import net.minecraft.world.scores.Scoreboard; |
| 29 | +import org.apache.commons.lang3.StringUtils; |
17 | 30 | import org.bukkit.Material; |
18 | 31 | import org.bukkit.craftbukkit.entity.CraftPlayer; |
19 | 32 | import org.bukkit.entity.Player; |
20 | 33 | import org.bukkit.inventory.ItemFlag; |
21 | 34 | import org.bukkit.inventory.ItemStack; |
22 | 35 | import org.bukkit.inventory.meta.SkullMeta; |
23 | 36 | import org.bukkit.profile.PlayerTextures; |
| 37 | +import org.jspecify.annotations.Nullable; |
24 | 38 | import tc.oc.pgm.platform.modern.util.Skins; |
25 | 39 | import tc.oc.pgm.util.bukkit.BukkitUtils; |
26 | 40 | import tc.oc.pgm.util.skin.Skin; |
@@ -106,4 +120,45 @@ public ItemStack customSkull(String url, String displayName, String... lore) { |
106 | 120 | head.setItemMeta(headMeta); |
107 | 121 | return head; |
108 | 122 | } |
| 123 | + |
| 124 | + @Override |
| 125 | + public void refreshPlayer(@Nullable PacketEvent event, Player player, Player viewer) { |
| 126 | + String playerDisplayName = PLAYER_UTILS.getPlayerDisplayName(player, viewer); |
| 127 | + String playerName = PLAYER_UTILS.getPlayerName(player, viewer); |
| 128 | + |
| 129 | + if (StringUtils.isBlank(playerName) || StringUtils.isBlank(playerDisplayName)) { |
| 130 | + return; |
| 131 | + } |
| 132 | + |
| 133 | + if (event != null) event.setCancelled(true); |
| 134 | + |
| 135 | + ServerPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); |
| 136 | + ServerPlayer viewerNms = ((CraftPlayer) viewer).getHandle(); |
| 137 | + GameProfile realProfile = nmsPlayer.gameProfile; |
| 138 | + |
| 139 | + Skin skin = PLAYER_UTILS.getPlayerSkin(player, viewer); |
| 140 | + ImmutableMultimap.Builder<String, Property> builder = ImmutableMultimap.builder(); |
| 141 | + if (skin != null && skin.getData() != null) { |
| 142 | + builder.put("textures", new Property("textures", skin.getData(), skin.getSignature())); |
| 143 | + } else { |
| 144 | + realProfile.properties().get("textures").forEach(p -> builder.put("textures", p)); |
| 145 | + } |
| 146 | + |
| 147 | + viewerNms.connection.send(new ClientboundPlayerInfoRemovePacket(List.of(player.getUniqueId()))); |
| 148 | + nmsPlayer.gameProfile = |
| 149 | + new GameProfile(realProfile.id(), playerName, new PropertyMap(builder.build())); |
| 150 | + viewerNms.connection.send( |
| 151 | + ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(nmsPlayer), viewerNms)); |
| 152 | + nmsPlayer.gameProfile = realProfile; |
| 153 | + |
| 154 | + Scoreboard scoreboard = nmsPlayer.getBukkitEntity().getScoreboard().getHandle(); |
| 155 | + PlayerTeam nmsTeam = scoreboard.getPlayersTeam(player.getName()); |
| 156 | + |
| 157 | + if (nmsTeam != null) { |
| 158 | + ClientboundSetPlayerTeamPacket teamPacket = ClientboundSetPlayerTeamPacket.createPlayerPacket( |
| 159 | + nmsTeam, playerName, ClientboundSetPlayerTeamPacket.Action.ADD); |
| 160 | + |
| 161 | + viewerNms.connection.send(teamPacket); |
| 162 | + } |
| 163 | + } |
109 | 164 | } |
0 commit comments