3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-Server-Patches/0212-Player.setPlayerProfile-API.patch
Zach Brown ef170ee659
Update upstream B/CB/S
--- work/Bukkit
Submodule work/Bukkit 6eac6d70..1ef8b9d9:
  > Add Player#openBook(ItemStack) method

--- work/CraftBukkit
Submodule work/CraftBukkit 17543ecf..649921e5:
  > Add Player#openBook(ItemStack) method
  > SPIGOT-2000: Picking up items to shield slot working inconsistently when inventory is full
  > SPIGOT-5037: Player.openMerchant does not show merchant level
  > SPIGOT-5038: Inventory.getHolder returns null for wandering traders

--- work/Spigot
Submodule work/Spigot baafee91..df0eb250:
  > SPIGOT-5043: Desync if world is changed in PlayerSpawnLocationEvent
  > Rebuild patches

Implementation developer note:
This patch adds a "pre-source" patch system for fixing malformed patches
from upstream directly. This seems to keep happening so it's best we
have some way to deal with them. This system brings those issues into
our domain rather than needing to wait for upstream to fix their
malformed files.
2019-06-08 15:33:05 -05:00

143 Zeilen
6.8 KiB
Diff

From 90933dd501026190c055f6ec8b1cf276540d91dd Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 18 Mar 2018 12:29:48 -0400
Subject: [PATCH] Player.setPlayerProfile API
This can be useful for changing name or skins after a player has logged in.
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index cc9b26518..f4f1037b3 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -65,7 +65,7 @@ public abstract class EntityHuman extends EntityLiving {
protected int bR;
protected final float bS = 0.02F;
private int bU;
- private final GameProfile bV;
+ private GameProfile bV; public final void setProfile(final GameProfile profile) { this.bV = profile; } // Paper - OBFHELPER
private ItemStack bX;
private final ItemCooldown bY;
@Nullable
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
index 7c3b9c0b9..d4d752ddb 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
@@ -37,7 +37,7 @@ public class LoginListener implements PacketLoginInListener {
public final NetworkManager networkManager;
private LoginListener.EnumProtocolState g;
private int h;
- private GameProfile i;
+ private GameProfile i; private void setGameProfile(final GameProfile profile) { this.i = profile; } private GameProfile getGameProfile() { return this.i; } // Paper - OBFHELPER
private final String j;
private SecretKey loginKey;
private EntityPlayer l;
@@ -286,12 +286,12 @@ public class LoginListener implements PacketLoginInListener {
final org.bukkit.craftbukkit.CraftServer server = LoginListener.this.server.server;
// Paper start
- PlayerProfile profile = Bukkit.createProfile(uniqueId, playerName);
+ PlayerProfile profile = CraftPlayerProfile.asBukkitMirror(getGameProfile());
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
server.getPluginManager().callEvent(asyncEvent);
profile = asyncEvent.getPlayerProfile();
- profile.complete();
- i = CraftPlayerProfile.asAuthlibCopy(profile);
+ profile.complete(true);
+ setGameProfile(CraftPlayerProfile.asAuthlib(profile));
playerName = i.getName();
uniqueId = i.getId();
// Paper end
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 7f1138cbb..e6d2a40b6 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1,6 +1,8 @@
package org.bukkit.craftbukkit.entity;
import com.destroystokyo.paper.Title;
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
+import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.BaseEncoding;
@@ -1194,8 +1196,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
// Remove this player from the hidden player's EntityTrackerEntry
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper start
EntityPlayer other = ((CraftPlayer) player).getHandle();
+ unregisterPlayer(other);
+ }
+ private void unregisterPlayer(EntityPlayer other) {
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper end
PlayerChunkMap.EntityTracker entry = tracker.trackedEntities.get(other.getId());
if (entry != null) {
entry.clear(getHandle());
@@ -1236,8 +1243,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
hiddenPlayers.remove(player.getUniqueId());
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper start
EntityPlayer other = ((CraftPlayer) player).getHandle();
+ registerPlayer(other);
+ }
+ private void registerPlayer(EntityPlayer other) {
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper end
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
@@ -1246,6 +1258,46 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
entry.updatePlayer(getHandle());
}
}
+ // Paper start
+ private void reregisterPlayer(EntityPlayer player) {
+ if (!hiddenPlayers.containsKey(player.getUniqueID())) {
+ unregisterPlayer(player);
+ registerPlayer(player);
+ }
+ }
+ public void setPlayerProfile(PlayerProfile profile) {
+ EntityPlayer self = getHandle();
+ self.setProfile(CraftPlayerProfile.asAuthlibCopy(profile));
+ List<EntityPlayer> players = server.getServer().getPlayerList().players;
+ for (EntityPlayer player : players) {
+ player.getBukkitEntity().reregisterPlayer(self);
+ }
+ refreshPlayer();
+ }
+ public PlayerProfile getPlayerProfile() {
+ return new CraftPlayerProfile(this).clone();
+ }
+
+ private void refreshPlayer() {
+ EntityPlayer handle = getHandle();
+
+ Location loc = getLocation();
+
+ PlayerConnection connection = handle.playerConnection;
+ reregisterPlayer(handle);
+
+ //Respawn the player then update their position and selected slot
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutRespawn(handle.dimension, handle.world.getWorldData().getType(), handle.playerInteractManager.getGameMode()));
+ handle.updateAbilities();
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutPosition(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), new HashSet<>(), 0));
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().updateClient(handle);
+
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
+ }
+ // Paper end
public void removeDisconnectingPlayer(Player player) {
hiddenPlayers.remove(player.getUniqueId());
--
2.21.0