papermc/Spigot-Server-Patches/0336-Extend-player-profile-API-to-support-skin-changes.patch
2018-07-21 18:17:54 +01:00

53 lines
2.2 KiB
Diff

From 8a9ff94f0db13f56873de8e6f555bc7893cffc31 Mon Sep 17 00:00:00 2001
From: NickAcPT <32451103+NickAcPT@users.noreply.github.com>
Date: Sat, 21 Jul 2018 01:30:30 +0100
Subject: [PATCH] Extend player profile API to support skin changes
Added code that refreshes the player's skin by sending packets with a special order, telling the client to respawn the player and re-apply the game profile
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 6cbf429f..01335b6b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1176,10 +1176,38 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
for (EntityPlayer player : players) {
player.getBukkitEntity().reregisterPlayer(self);
}
+ refreshPlayer();
}
public PlayerProfile getPlayerProfile() {
return new CraftPlayerProfile(this).clone();
}
+
+ private void refreshPlayer() {
+ EntityPlayer entityplayer = getHandle();
+
+ Location loc = getLocation();
+
+ EntityPlayer handle = getHandle();
+ PlayerConnection connection = handle.playerConnection;
+ reregisterPlayer(handle);
+
+ //Respawn the player then update their position and selected slot
+ connection.sendPacket(new PacketPlayOutRespawn(entityplayer.dimension, entityplayer.world.getDifficulty(), entityplayer.world.getWorldData().getType(), entityplayer.playerInteractManager.getGameMode()));
+ handle.updateAbilities();
+ connection.sendPacket(new PacketPlayOutPosition(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), new HashSet<>(), 0));
+ connection.sendPacket(new PacketPlayOutHeldItemSlot(getInventory().getHeldItemSlot()));
+
+ updateScaledHealth();
+ this.updateInventory();
+
+ handle.triggerHealthUpdate();
+
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
+
+ }
// Paper end
public void removeDisconnectingPlayer(Player player) {
--
2.16.2.windows.1