2018-07-23 16:39:55 +08:00
|
|
|
From 4557d91dd4ca4ccd0d1ddbb66fdde9161dc25f47 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
|
2018-07-23 16:39:55 +08:00
|
|
|
index d04f9b380e..5015bd0710 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
|
2018-07-19 02:55:52 +08:00
|
|
|
@@ -67,7 +67,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
|
|
protected int bZ;
|
|
|
|
protected float ca = 0.02F;
|
|
|
|
private int g;
|
|
|
|
- private final GameProfile h;
|
2018-07-19 07:16:19 +08:00
|
|
|
+ private GameProfile h; public void setProfile(GameProfile profile) { this.h = profile; } // Paper - OBFHELPER
|
2018-07-19 02:55:52 +08:00
|
|
|
private ItemStack cd;
|
|
|
|
private final ItemCooldown ce;
|
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
|
2018-07-23 16:39:55 +08:00
|
|
|
index a721eb30e9..258bdfe66a 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
|
2018-07-19 02:55:52 +08:00
|
|
|
@@ -38,7 +38,7 @@ public class LoginListener implements PacketLoginInListener, ITickable {
|
2018-03-23 09:40:57 +08:00
|
|
|
public final NetworkManager networkManager;
|
|
|
|
private LoginListener.EnumProtocolState g;
|
|
|
|
private int h;
|
|
|
|
- private GameProfile i;
|
|
|
|
+ private GameProfile i; private void setGameProfile(GameProfile profile) { i = profile; } private GameProfile getGameProfile() { return i; } // Paper - OBFHELPER
|
|
|
|
private final String j;
|
|
|
|
private SecretKey loginKey;
|
|
|
|
private EntityPlayer l;
|
2018-07-19 02:55:52 +08:00
|
|
|
@@ -285,12 +285,12 @@ public class LoginListener implements PacketLoginInListener, ITickable {
|
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
|
2018-07-23 16:39:55 +08:00
|
|
|
index 9f69000cb2..3c85d6323b 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;
|
2018-07-19 02:55:52 +08:00
|
|
|
@@ -1139,8 +1141,14 @@ 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
|
|
|
|
- EntityTracker tracker = ((WorldServer) entity.world).tracker;
|
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
|
|
|
+ // Paper start
|
|
|
|
+ unregisterPlayer(other);
|
|
|
|
+ }
|
|
|
|
+ private void unregisterPlayer(EntityPlayer other) {
|
|
|
|
+ EntityTracker tracker = ((WorldServer) entity.world).tracker;
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId());
|
|
|
|
if (entry != null) {
|
|
|
|
entry.clear(getHandle());
|
2018-07-19 02:55:52 +08:00
|
|
|
@@ -1181,8 +1189,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-19 00:32:09 +08:00
|
|
|
}
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|
|
|
|
|
|
|
|
- EntityTracker tracker = ((WorldServer) entity.world).tracker;
|
|
|
|
+ // 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) {
|
|
|
|
+ EntityTracker tracker = ((WorldServer) entity.world).tracker;
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
|
|
|
|
|
2018-07-19 02:55:52 +08:00
|
|
|
@@ -1191,6 +1204,25 @@ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public PlayerProfile getPlayerProfile() {
|
2018-03-23 09:40:57 +08:00
|
|
|
+ return new CraftPlayerProfile(this).clone();
|
2018-03-19 00:32:09 +08:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public void removeDisconnectingPlayer(Player player) {
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|
|
|
|
--
|
2018-06-30 13:40:52 +08:00
|
|
|
2.18.0
|
2018-03-19 00:32:09 +08:00
|
|
|
|