2019-07-20 12:01:24 +08:00
|
|
|
From 73e8d2932986ca06676e887f4dc839cd86468fd1 Mon Sep 17 00:00:00 2001
|
2018-03-19 00:32:09 +08:00
|
|
|
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
|
2019-07-20 12:01:24 +08:00
|
|
|
index 0ca5e7886b..778356381d 100644
|
2018-03-19 00:32:09 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
2019-07-20 12:01:24 +08:00
|
|
|
@@ -66,7 +66,7 @@ public abstract class EntityHuman extends EntityLiving {
|
2019-04-29 01:59:47 +08:00
|
|
|
protected int bR;
|
|
|
|
protected final float bS = 0.02F;
|
2019-07-20 12:01:24 +08:00
|
|
|
private int bV;
|
|
|
|
- private final GameProfile bW;
|
|
|
|
+ private GameProfile bW; public final void setProfile(final GameProfile profile) { this.bW = profile; } // Paper - OBFHELPER
|
|
|
|
private ItemStack bY;
|
|
|
|
private final ItemCooldown bZ;
|
2018-03-19 00:32:09 +08:00
|
|
|
@Nullable
|
2018-03-23 09:40:57 +08:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
|
2019-07-20 12:01:24 +08:00
|
|
|
index a272a70303..d6befec184 100644
|
2018-03-23 09:40:57 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/LoginListener.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/LoginListener.java
|
2019-04-29 01:59:47 +08:00
|
|
|
@@ -37,7 +37,7 @@ public class LoginListener implements PacketLoginInListener {
|
2018-03-23 09:40:57 +08:00
|
|
|
public final NetworkManager networkManager;
|
|
|
|
private LoginListener.EnumProtocolState g;
|
|
|
|
private int h;
|
|
|
|
- private GameProfile i;
|
2019-04-29 01:59:47 +08:00
|
|
|
+ private GameProfile i; private void setGameProfile(final GameProfile profile) { this.i = profile; } private GameProfile getGameProfile() { return this.i; } // Paper - OBFHELPER
|
2018-03-23 09:40:57 +08:00
|
|
|
private final String j;
|
|
|
|
private SecretKey loginKey;
|
|
|
|
private EntityPlayer l;
|
2019-07-20 12:01:24 +08:00
|
|
|
@@ -291,12 +291,12 @@ public class LoginListener implements PacketLoginInListener {
|
2018-03-23 09:40:57 +08:00
|
|
|
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
|
2018-03-19 00:32:09 +08:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2019-07-20 12:01:24 +08:00
|
|
|
index 854d6f7999..a2ef3f59ee 100644
|
2018-03-19 00:32:09 +08:00
|
|
|
--- 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;
|
2019-06-25 09:47:58 +08:00
|
|
|
@@ -1203,8 +1205,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-19 00:32:09 +08:00
|
|
|
hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
|
|
|
|
|
|
|
|
// Remove this player from the hidden player's EntityTrackerEntry
|
2019-04-29 01:59:47 +08:00
|
|
|
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-19 00:32:09 +08:00
|
|
|
+ // Paper start
|
2019-04-29 01:59:47 +08:00
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
2018-03-19 00:32:09 +08:00
|
|
|
+ unregisterPlayer(other);
|
|
|
|
+ }
|
|
|
|
+ private void unregisterPlayer(EntityPlayer other) {
|
2019-04-29 01:59:47 +08:00
|
|
|
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-19 00:32:09 +08:00
|
|
|
+ // Paper end
|
2019-04-29 01:59:47 +08:00
|
|
|
PlayerChunkMap.EntityTracker entry = tracker.trackedEntities.get(other.getId());
|
2018-03-19 00:32:09 +08:00
|
|
|
if (entry != null) {
|
|
|
|
entry.clear(getHandle());
|
2019-06-25 09:47:58 +08:00
|
|
|
@@ -1245,8 +1252,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-19 00:32:09 +08:00
|
|
|
}
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|
|
|
|
|
2019-04-29 01:59:47 +08:00
|
|
|
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-19 00:32:09 +08:00
|
|
|
+ // Paper start
|
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
2018-03-21 00:27:00 +08:00
|
|
|
+ registerPlayer(other);
|
2018-03-19 00:32:09 +08:00
|
|
|
+ }
|
|
|
|
+ private void registerPlayer(EntityPlayer other) {
|
2019-04-29 01:59:47 +08:00
|
|
|
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-19 00:32:09 +08:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
|
|
|
|
|
2019-06-25 09:47:58 +08:00
|
|
|
@@ -1255,6 +1267,46 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-19 00:32:09 +08:00
|
|
|
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);
|
|
|
|
+ }
|
2018-07-24 08:31:33 +08:00
|
|
|
+ refreshPlayer();
|
2018-03-19 00:32:09 +08:00
|
|
|
+ }
|
|
|
|
+ public PlayerProfile getPlayerProfile() {
|
2018-03-23 09:40:57 +08:00
|
|
|
+ return new CraftPlayerProfile(this).clone();
|
2018-03-19 00:32:09 +08:00
|
|
|
+ }
|
2018-07-24 08:31:33 +08:00
|
|
|
+
|
|
|
|
+ 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
|
2019-04-29 01:59:47 +08:00
|
|
|
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutRespawn(handle.dimension, handle.world.getWorldData().getType(), handle.playerInteractManager.getGameMode()));
|
2018-07-24 08:31:33 +08:00
|
|
|
+ handle.updateAbilities();
|
2018-07-24 11:20:41 +08:00
|
|
|
+ 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);
|
2018-07-24 08:31:33 +08:00
|
|
|
+
|
|
|
|
+ if (this.isOp()) {
|
|
|
|
+ this.setOp(false);
|
|
|
|
+ this.setOp(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
2018-03-19 00:32:09 +08:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public void removeDisconnectingPlayer(Player player) {
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|
|
|
|
--
|
2019-06-25 09:47:58 +08:00
|
|
|
2.22.0
|
2018-03-19 00:32:09 +08:00
|
|
|
|