2021-06-11 14:02:28 +02: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.
|
|
|
|
|
2022-11-20 00:53:20 +01:00
|
|
|
== AT ==
|
|
|
|
public-f net.minecraft.world.entity.player.Player gameProfile
|
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2024-10-22 23:30:51 +02:00
|
|
|
index 4a62c1abc6f3c48bbda40325b4ce46632db3f28d..bab8c53041afb9606db55923e5466eab25640226 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2024-09-15 21:39:53 +02:00
|
|
|
@@ -341,11 +341,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
2024-01-14 13:51:41 +01:00
|
|
|
|
|
|
|
// Paper start - Add more fields to AsyncPlayerPreLoginEvent
|
2024-02-01 10:15:57 +01:00
|
|
|
final InetAddress rawAddress = ((InetSocketAddress) this.connection.channel.remoteAddress()).getAddress();
|
2024-01-14 13:51:41 +01:00
|
|
|
- com.destroystokyo.paper.profile.PlayerProfile profile = org.bukkit.Bukkit.createProfile(uniqueId, playerName);
|
|
|
|
+ com.destroystokyo.paper.profile.PlayerProfile profile = com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(gameprofile); // Paper - setPlayerProfileAPI
|
2024-04-24 04:21:40 +02:00
|
|
|
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, rawAddress, uniqueId, this.transferred, profile, this.connection.hostname);
|
2024-01-14 10:46:04 +01:00
|
|
|
server.getPluginManager().callEvent(asyncEvent);
|
|
|
|
profile = asyncEvent.getPlayerProfile();
|
|
|
|
- profile.complete();
|
|
|
|
+ profile.complete(true); // Paper - setPlayerProfileAPI
|
|
|
|
gameprofile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
|
|
|
|
playerName = gameprofile.getName();
|
|
|
|
uniqueId = gameprofile.getId();
|
2023-12-28 00:22:44 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2024-10-27 18:11:15 +01:00
|
|
|
index 5cb84271abdabc0f2d44ad9425828431f8818a47..a929c809dc1dcb2bdab4db0d2a8ca794189e93d9 100644
|
2023-12-28 00:22:44 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
2024-10-27 18:11:15 +01:00
|
|
|
@@ -799,10 +799,16 @@ public abstract class PlayerList {
|
2023-12-28 00:22:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void sendPlayerPermissionLevel(ServerPlayer player) {
|
|
|
|
+ // Paper start - avoid recalculating permissions if possible
|
|
|
|
+ this.sendPlayerPermissionLevel(player, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void sendPlayerPermissionLevel(ServerPlayer player, boolean recalculatePermissions) {
|
|
|
|
+ // Paper end - avoid recalculating permissions if possible
|
|
|
|
GameProfile gameprofile = player.getGameProfile();
|
|
|
|
int i = this.server.getProfilePermissions(gameprofile);
|
|
|
|
|
|
|
|
- this.sendPlayerPermissionLevel(player, i);
|
|
|
|
+ this.sendPlayerPermissionLevel(player, i, recalculatePermissions); // Paper - avoid recalculating permissions if possible
|
|
|
|
}
|
|
|
|
|
|
|
|
public void tick() {
|
2022-12-20 19:56:33 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
2024-09-15 21:39:53 +02:00
|
|
|
index 818df09e9245b5d89b4180b1eaa51470b7539341..f6b2ca92fd3510a76cbf56d0ea55aa6caaf12ba1 100644
|
2022-12-20 19:56:33 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
|
2024-01-26 20:17:06 +01:00
|
|
|
@@ -82,8 +82,8 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
|
2022-12-20 19:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
- public PlayerProfile getPlayerProfile() {
|
|
|
|
- return new CraftPlayerProfile(this.profile);
|
|
|
|
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() { // Paper
|
2024-09-15 21:39:53 +02:00
|
|
|
+ return com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitCopy(this.profile); // Paper
|
2022-12-20 19:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Server getServer() {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2024-10-25 18:08:28 +02:00
|
|
|
index 128fcd537783986d816dae6d1ce2afb7af07d45a..32eeca2467189c6c97f7da5529d4fe9375e8a848 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2024-10-24 19:29:35 +02:00
|
|
|
@@ -254,11 +254,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-10-27 01:34:58 +02:00
|
|
|
return this.server.getPlayer(this.getUniqueId()) != null;
|
2022-02-12 14:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
- public PlayerProfile getPlayerProfile() {
|
|
|
|
- return new CraftPlayerProfile(this.getProfile());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
|
|
public InetSocketAddress getAddress() {
|
2024-04-24 04:21:40 +02:00
|
|
|
if (this.getHandle().connection.protocol() == null) return null;
|
2024-10-24 19:29:35 +02:00
|
|
|
@@ -1819,8 +1814,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
private void untrackAndHideEntity(org.bukkit.entity.Entity entity) {
|
2021-11-29 00:46:53 +01:00
|
|
|
// Remove this entity from the hidden player's EntityTrackerEntry
|
2023-06-07 21:54:11 +02:00
|
|
|
- ChunkMap tracker = ((ServerLevel) this.getHandle().level()).getChunkSource().chunkMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
2021-11-29 00:46:53 +01:00
|
|
|
Entity other = ((CraftEntity) entity).getHandle();
|
|
|
|
+ unregisterEntity(other);
|
2022-02-01 14:06:41 +01:00
|
|
|
+
|
|
|
|
+ server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-11-29 00:46:53 +01:00
|
|
|
+ private void unregisterEntity(Entity other) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2023-06-07 21:54:11 +02:00
|
|
|
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level()).getChunkSource().chunkMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
|
|
|
|
if (entry != null) {
|
2021-06-12 18:56:13 +02:00
|
|
|
entry.removePlayer(this.getHandle());
|
2024-10-24 19:29:35 +02:00
|
|
|
@@ -1833,8 +1835,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-12-07 19:52:24 +01:00
|
|
|
this.getHandle().connection.send(new ClientboundPlayerInfoRemovePacket(List.of(otherPlayer.getUUID())));
|
2022-02-01 14:06:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
-
|
2023-10-27 01:34:58 +02:00
|
|
|
- this.server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
|
2022-02-01 14:06:41 +01:00
|
|
|
}
|
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
void resetAndHideEntity(org.bukkit.entity.Entity entity) {
|
2024-10-24 19:29:35 +02:00
|
|
|
@@ -1899,12 +1899,25 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-08-12 16:10:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void trackAndShowEntity(org.bukkit.entity.Entity entity) {
|
|
|
|
+ // Paper start - uuid override
|
|
|
|
+ this.trackAndShowEntity(entity, null);
|
2022-02-01 14:06:41 +01:00
|
|
|
+ }
|
2023-08-12 16:10:09 +02:00
|
|
|
+ private void trackAndShowEntity(org.bukkit.entity.Entity entity, final @Nullable UUID uuidOverride) {
|
|
|
|
+ // Paper end
|
|
|
|
ChunkMap tracker = ((ServerLevel) this.getHandle().level()).getChunkSource().chunkMap;
|
|
|
|
Entity other = ((CraftEntity) entity).getHandle();
|
|
|
|
|
|
|
|
if (other instanceof ServerPlayer) {
|
|
|
|
ServerPlayer otherPlayer = (ServerPlayer) other;
|
|
|
|
+ // Paper start - uuid override
|
|
|
|
+ UUID original = null;
|
|
|
|
+ if (uuidOverride != null) {
|
|
|
|
+ original = otherPlayer.getUUID();
|
|
|
|
+ otherPlayer.setUUID(uuidOverride);
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
this.getHandle().connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(otherPlayer)));
|
|
|
|
+ if (original != null) otherPlayer.setUUID(original); // Paper - uuid override
|
|
|
|
}
|
|
|
|
|
|
|
|
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
|
2024-10-24 19:29:35 +02:00
|
|
|
@@ -1914,6 +1927,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-08-12 16:10:09 +02:00
|
|
|
|
2023-10-27 01:34:58 +02:00
|
|
|
this.server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
|
2023-08-12 16:10:09 +02:00
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
2023-03-07 00:15:25 +01:00
|
|
|
+ @Override
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
|
2023-03-07 00:15:25 +01:00
|
|
|
+ ServerPlayer self = this.getHandle();
|
|
|
|
+ GameProfile gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!self.sentListPacket) {
|
2023-03-07 00:15:25 +01:00
|
|
|
+ self.gameProfile = gameProfile;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return;
|
|
|
|
+ }
|
2023-03-07 00:15:25 +01:00
|
|
|
+ List<ServerPlayer> players = this.server.getServer().getPlayerList().players;
|
|
|
|
+ // First unregister the player for all players with the OLD game profile
|
2021-06-11 14:02:28 +02:00
|
|
|
+ for (ServerPlayer player : players) {
|
2023-03-07 00:15:25 +01:00
|
|
|
+ CraftPlayer bukkitPlayer = player.getBukkitEntity();
|
|
|
|
+ if (bukkitPlayer.canSee(this)) {
|
|
|
|
+ bukkitPlayer.unregisterEntity(self);
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2023-03-23 22:57:03 +01:00
|
|
|
+
|
2023-03-23 17:49:24 +01:00
|
|
|
+ // Set the game profile here, we should have unregistered the entity via iterating all player entities above.
|
|
|
|
+ self.gameProfile = gameProfile;
|
2023-08-12 16:10:09 +02:00
|
|
|
+
|
2023-03-07 00:15:25 +01:00
|
|
|
+ // Re-register the game profile for all players
|
|
|
|
+ for (ServerPlayer player : players) {
|
|
|
|
+ CraftPlayer bukkitPlayer = player.getBukkitEntity();
|
|
|
|
+ if (bukkitPlayer.canSee(this)) {
|
2023-08-12 16:10:09 +02:00
|
|
|
+ bukkitPlayer.trackAndShowEntity(self.getBukkitEntity(), gameProfile.getId());
|
2023-03-07 00:15:25 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
2023-08-12 16:10:09 +02:00
|
|
|
+
|
2023-03-07 00:15:25 +01:00
|
|
|
+ // Refresh misc player things AFTER sending game profile
|
|
|
|
+ this.refreshPlayer();
|
2023-08-12 16:10:09 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2023-03-07 00:15:25 +01:00
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
void resetAndShowEntity(org.bukkit.entity.Entity entity) {
|
2023-08-12 16:10:09 +02:00
|
|
|
// SPIGOT-7312: Can't show/hide self
|
2024-10-24 19:29:35 +02:00
|
|
|
@@ -1925,6 +1971,34 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-03-14 19:59:51 +01:00
|
|
|
this.trackAndShowEntity(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
|
|
|
|
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this).clone();
|
|
|
|
+ }
|
|
|
|
+
|
2023-03-07 00:15:25 +01:00
|
|
|
+ private void refreshPlayer() {
|
|
|
|
+ ServerPlayer handle = this.getHandle();
|
|
|
|
+ Location loc = this.getLocation();
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ ServerGamePacketListenerImpl connection = handle.connection;
|
|
|
|
+
|
|
|
|
+ //Respawn the player then update their position and selected slot
|
2023-06-08 00:12:41 +02:00
|
|
|
+ ServerLevel worldserver = handle.serverLevel();
|
2023-12-28 00:22:44 +01:00
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundRespawnPacket(handle.createCommonSpawnInfo(worldserver), net.minecraft.network.protocol.game.ClientboundRespawnPacket.KEEP_ALL_DATA));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ handle.onUpdateAbilities();
|
2024-10-22 23:30:51 +02:00
|
|
|
+ connection.internalTeleport(net.minecraft.world.entity.PositionMoveRotation.of(this.getHandle()), java.util.Collections.emptySet());
|
2023-12-28 00:22:44 +01:00
|
|
|
+ net.minecraft.server.players.PlayerList playerList = handle.server.getPlayerList();
|
|
|
|
+ playerList.sendPlayerPermissionLevel(handle, false);
|
|
|
|
+ playerList.sendLevelInfo(handle, worldserver);
|
|
|
|
+ playerList.sendAllPlayerInfo(handle);
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
2023-04-07 01:21:33 +02:00
|
|
|
+ // Resend their XP and effects because the respawn packet resets it
|
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundSetExperiencePacket(handle.experienceProgress, handle.totalExperience, handle.experienceLevel));
|
|
|
|
+ for (net.minecraft.world.effect.MobEffectInstance mobEffect : handle.getActiveEffects()) {
|
2024-04-25 22:34:46 +02:00
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket(handle.getId(), mobEffect, false));
|
2023-04-07 01:21:33 +02:00
|
|
|
+ }
|
2023-03-07 00:15:25 +01:00
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2023-03-14 19:59:51 +01:00
|
|
|
|
2021-12-04 02:33:56 +01:00
|
|
|
public void onEntityRemove(Entity entity) {
|
2023-03-14 19:59:51 +01:00
|
|
|
this.invertedVisibilityEntities.remove(entity.getUUID());
|
2022-12-20 19:56:33 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
2024-10-21 00:06:54 +02:00
|
|
|
index 91c6721201b095eb32c5fd5a1aaf2cbcf3ee196d..b85223ebff4dbb8aa74b501663afc87ef11e2a96 100644
|
2022-12-20 19:56:33 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
2024-10-21 00:06:54 +02:00
|
|
|
@@ -467,6 +467,13 @@ public class Commodore {
|
2022-12-20 19:56:33 +01:00
|
|
|
}
|
2024-04-24 04:21:40 +02:00
|
|
|
// Paper end - Rewrite plugins
|
2022-12-20 19:56:33 +01:00
|
|
|
|
|
|
|
+ // Paper start - Rewrite plugins
|
2022-12-26 13:34:23 +01:00
|
|
|
+ if ((owner.equals("org/bukkit/OfflinePlayer") || owner.equals("org/bukkit/entity/Player")) && name.equals("getPlayerProfile") && desc.equals("()Lorg/bukkit/profile/PlayerProfile;")) {
|
2022-12-20 19:56:33 +01:00
|
|
|
+ super.visitMethodInsn(opcode, owner, name, "()Lcom/destroystokyo/paper/profile/PlayerProfile;", itf);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
2024-01-14 10:46:04 +01:00
|
|
|
+
|
|
|
|
if (modern) {
|
|
|
|
if (owner.equals("org/bukkit/Material") || (instantiatedMethodType != null && instantiatedMethodType.getDescriptor().startsWith("(Lorg/bukkit/Material;)"))) {
|
|
|
|
switch (name) {
|