testserver/patches/server/0186-Player.setPlayerProfil...

134 lines
7.3 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 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/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2021-06-16 04:53:50 +00:00
index 94b1ec73f2039c83203045db42bf0270c985d995..dbdd320eca27e82d5b058a7e6596b0a5fbc2631f 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2021-06-12 16:56:13 +00:00
@@ -340,12 +340,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
2021-06-11 12:02:28 +00:00
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;
// Paper start
- PlayerProfile profile = Bukkit.createProfile(uniqueId, playerName);
2021-06-12 16:56:13 +00:00
+ PlayerProfile profile = CraftPlayerProfile.asBukkitMirror(ServerLoginPacketListenerImpl.this.gameProfile);
2021-06-11 12:02:28 +00:00
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
server.getPluginManager().callEvent(asyncEvent);
profile = asyncEvent.getPlayerProfile();
- profile.complete();
- gameProfile = CraftPlayerProfile.asAuthlibCopy(profile);
+ profile.complete(true);
2021-06-12 16:56:13 +00:00
+ ServerLoginPacketListenerImpl.this.gameProfile = CraftPlayerProfile.asAuthlib(profile);
2021-06-11 12:02:28 +00:00
playerName = gameProfile.getName();
uniqueId = gameProfile.getId();
// Paper end
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2021-06-16 04:53:50 +00:00
index 278416af649425890ad00ca6f47d459ebab08e0b..91f96f5718f7a7f2e0ce56f4dbf894d8a052630c 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2021-06-12 16:56:13 +00:00
@@ -173,7 +173,7 @@ public abstract class Player extends LivingEntity {
2021-06-11 12:02:28 +00:00
protected int enchantmentSeed;
protected final float defaultFlySpeed = 0.02F;
private int lastLevelUpTime;
- private final GameProfile gameProfile;
2021-06-12 16:56:13 +00:00
+ public GameProfile gameProfile; // Paper - private->public
private boolean reducedDebugInfo;
2021-06-11 12:02:28 +00:00
private ItemStack lastItemInMainHand;
private final ItemCooldowns cooldowns;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 44533533c4860a23a0d469c6a544825297d221de..be339681a63db12222a2e5727399f088c053fa4f 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2021-06-12 16:56:13 +00:00
@@ -71,6 +71,7 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper;
2021-06-11 12:02:28 +00:00
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.GameType;
2021-06-12 16:56:13 +00:00
import net.minecraft.world.level.block.Blocks;
2021-06-11 12:02:28 +00:00
+import net.minecraft.world.level.biome.BiomeManager;
import net.minecraft.world.level.block.entity.SignBlockEntity;
import net.minecraft.world.level.saveddata.maps.MapDecoration;
2021-06-12 16:56:13 +00:00
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
@@ -1333,8 +1334,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-12 16:56:13 +00:00
this.hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
2021-06-11 12:02:28 +00:00
// Remove this player from the hidden player's EntityTrackerEntry
- ChunkMap tracker = ((ServerLevel) entity.level).getChunkSource().chunkMap;
+ // Paper start
ServerPlayer other = ((CraftPlayer) player).getHandle();
+ unregisterPlayer(other);
+ }
+ private void unregisterPlayer(ServerPlayer other) {
+ ChunkMap tracker = ((ServerLevel) entity.level).getChunkSource().chunkMap;
+ // Paper end
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
if (entry != null) {
2021-06-12 16:56:13 +00:00
entry.removePlayer(this.getHandle());
@@ -1375,8 +1381,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 12:02:28 +00:00
}
2021-06-12 16:56:13 +00:00
this.hiddenPlayers.remove(player.getUniqueId());
2021-06-11 12:02:28 +00:00
- ChunkMap tracker = ((ServerLevel) entity.level).getChunkSource().chunkMap;
+ // Paper start
ServerPlayer other = ((CraftPlayer) player).getHandle();
+ registerPlayer(other);
+ }
+ private void registerPlayer(ServerPlayer other) {
+ ChunkMap tracker = ((ServerLevel) entity.level).getChunkSource().chunkMap;
+ // Paper end
2021-06-12 16:56:13 +00:00
this.getHandle().connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, other));
2021-06-11 12:02:28 +00:00
@@ -1385,6 +1396,50 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-12 16:56:13 +00:00
entry.updatePlayer(this.getHandle());
2021-06-11 12:02:28 +00:00
}
}
+ // Paper start
+ private void reregisterPlayer(ServerPlayer player) {
+ if (!hiddenPlayers.containsKey(player.getUUID())) {
+ unregisterPlayer(player);
+ registerPlayer(player);
+ }
+ }
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
+ ServerPlayer self = getHandle();
2021-06-12 16:56:13 +00:00
+ self.gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
2021-06-11 12:02:28 +00:00
+ if (!self.sentListPacket) {
+ return;
+ }
+ List<ServerPlayer> players = server.getServer().getPlayerList().players;
+ for (ServerPlayer player : players) {
+ player.getBukkitEntity().reregisterPlayer(self);
+ }
+ refreshPlayer();
+ }
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this).clone();
+ }
+
+ private void refreshPlayer() {
+ ServerPlayer handle = getHandle();
+
+ Location loc = getLocation();
+
+ ServerGamePacketListenerImpl connection = handle.connection;
+ reregisterPlayer(handle);
+
+ //Respawn the player then update their position and selected slot
+ ServerLevel worldserver = handle.getLevel();
+ connection.send(new net.minecraft.network.protocol.game.ClientboundRespawnPacket(worldserver.dimensionType(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), handle.gameMode.getGameModeForPlayer(), handle.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true));
+ handle.onUpdateAbilities();
2021-06-12 16:56:13 +00:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet(), 0, false));
2021-06-11 12:02:28 +00:00
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().sendAllPlayerInfo(handle);
+
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
+ }
+ // Paper end
public void removeDisconnectingPlayer(Player player) {
2021-06-12 16:56:13 +00:00
this.hiddenPlayers.remove(player.getUniqueId());