Paper/patches/server/0180-Player.setPlayerProfile-API.patch

219 lines
12 KiB
Diff
Raw Normal View History

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.
== AT ==
public-f net.minecraft.world.entity.player.Player gameProfile
2023-03-14 19:59:51 +01:00
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-12-05 23:12:48 +01:00
index 9aa8c643d0a338afefeb8ff6a1f016cc0ffdb00f..520de61cd21d71f8c77175977987091e3caa0be9 100644
2023-03-14 19:59:51 +01:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2023-12-05 23:12:48 +01:00
@@ -1465,7 +1465,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-03-14 19:59:51 +01:00
this.internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet());
}
- private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) {
+ public void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) { // Paper
// CraftBukkit start
if (Float.isNaN(f)) {
f = 0;
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
2023-12-05 23:12:48 +01:00
index 827774b02136ec1862bc9ffabc76ba3a4eb87716..96ae1fd95956f5e5a1542dcce3fbd9d4b83d49ba 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
2023-12-05 23:12:48 +01:00
@@ -289,11 +289,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2021-06-11 14:02:28 +02:00
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;
2022-03-01 06:43:03 +01:00
// Paper start
- com.destroystokyo.paper.profile.PlayerProfile profile = org.bukkit.Bukkit.createProfile(uniqueId, playerName);
2023-09-22 06:05:18 +02:00
+ com.destroystokyo.paper.profile.PlayerProfile profile = com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(gameprofile);
2022-03-01 06:43:03 +01:00
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
2021-06-11 14:02:28 +02:00
server.getPluginManager().callEvent(asyncEvent);
2022-03-01 06:43:03 +01:00
profile = asyncEvent.getPlayerProfile();
- profile.complete();
+ profile.complete(true); // Paper - setPlayerProfileAPI
2023-09-22 06:05:18 +02:00
gameprofile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
playerName = gameprofile.getName();
uniqueId = gameprofile.getId();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index 477d3245facb5ae59c786d4f696f64226cb540a6..e8490a58dd4d9bc39a5bb2f9fc109526e031b971 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
Updated Upstream (Bukkit/CraftBukkit) (#9485) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 82af5dc6 SPIGOT-7396: Add PlayerSignOpenEvent 3f0281ca SPIGOT-7063, PR-763: Add DragonBattle#initiateRespawn with custom EnderCrystals f83c8df4 PR-873: Add PlayerRecipeBookClickEvent 14560d39 SPIGOT-7435: Add TeleportCause#EXIT_BED 2cc6db92 SPIGOT-7422, PR-887: Add API to set sherds on decorated pots 36022f02 PR-883: Add ItemFactory#getSpawnEgg 12eb5c46 PR-881: Update Scoreboard Javadocs, remove explicit exception throwing f6d8d44a PR-882: Add modern time API methods to ban API 21a7b710 Upgrade some Maven plugins to reduce warnings 11fd1225 PR-886: Deprecate the SmithingRecipe constructor as it now does nothing dbd1761d SPIGOT-7406: Improve documentation for getDragonBattle CraftBukkit Changes: d548daac2 SPIGOT-7446: BlockState#update not updating a spawner's type to null 70e0bc050 SPIGOT-7447: Fix --forceUpgrade 6752f1d63 SPIGOT-7396: Add PlayerSignOpenEvent 847b4cad5 SPIGOT-7063, PR-1071: Add DragonBattle#initiateRespawn with custom EnderCrystals c335a555f PR-1212: Add PlayerRecipeBookClickEvent 4be756ecb SPIGOT-7445: Fix opening smithing inventory db70bd6ed SPIGOT-7441: Fix issue placing certain items in creative/op f7fa6d993 SPIGOT-7435: Add TeleportCause#EXIT_BED b435e8e8d SPIGOT-7349: Player#setDisplayName not working when message/format unmodified a2fafdd1d PR-1232: Re-add fix for player rotation 7cf863de1 PR-1233: Remove some old MC bug fixes now fixed in vanilla 08ec344ad Fix ChunkGenerator#generateCaves never being called 5daeb502a SPIGOT-7422, PR-1228: Add API to set sherds on decorated pots 52faa6b32 PR-1224: Add ItemFactory#getSpawnEgg 01cae71b7 SPIGOT-7429: Fix LEFT_CLICK_AIR not working for passable entities and spectators a94277a18 PR-1223: Remove non-existent scoreboard display name/prefix/suffix limits 36b107660 PR-1225: Add modern time API methods to ban API 59ead25bc Upgrade some Maven plugins to reduce warnings 202fc5c4e Increase outdated build delay ce545de57 SPIGOT-7398: TextDisplay#setInterpolationDuration incorrectly updates the line width Spigot Changes: b41c46db Rebuild patches 3374045a SPIGOT-7431: Fix EntityMountEvent returning opposite entities 0ca4eb66 Rebuild patches
2023-08-06 02:21:59 +02:00
@@ -81,8 +81,8 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
}
@Override
- public PlayerProfile getPlayerProfile() {
- return new CraftPlayerProfile(this.profile);
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() { // Paper
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this.profile); // Paper
}
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
2023-12-06 20:46:49 +01:00
index 352c16b89f0e33aefef141fea0bf8067208cffcf..f4a6a3f9c6c8972f482a53ee434dc8631d32632d 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
2023-12-06 20:46:49 +01:00
@@ -279,11 +279,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2023-10-27 01:34:58 +02:00
return this.server.getPlayer(this.getUniqueId()) != null;
}
- @Override
- public PlayerProfile getPlayerProfile() {
- return new CraftPlayerProfile(this.getProfile());
- }
-
@Override
public InetSocketAddress getAddress() {
if (this.getHandle().connection == null) return null;
2023-12-06 20:46:49 +01:00
@@ -1700,8 +1695,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) {
// 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
Entity other = ((CraftEntity) entity).getHandle();
+ unregisterEntity(other);
+
+ server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
2021-06-11 14:02:28 +02: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());
2023-12-06 20:46:49 +01:00
@@ -1714,8 +1716,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())));
}
}
-
2023-10-27 01:34:58 +02:00
- this.server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
}
2023-03-14 19:59:51 +01:00
void resetAndHideEntity(org.bukkit.entity.Entity entity) {
2023-12-06 20:46:49 +01:00
@@ -1780,12 +1780,25 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
private void trackAndShowEntity(org.bukkit.entity.Entity entity) {
+ // Paper start - uuid override
+ this.trackAndShowEntity(entity, null);
+ }
+ 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());
2023-12-06 20:46:49 +01:00
@@ -1795,6 +1808,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2023-10-27 01:34:58 +02:00
this.server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
}
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
+
+ // Set the game profile here, we should have unregistered the entity via iterating all player entities above.
+ self.gameProfile = gameProfile;
+
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)) {
+ bukkitPlayer.trackAndShowEntity(self.getBukkitEntity(), gameProfile.getId());
2023-03-07 00:15:25 +01:00
+ }
+ }
+
2023-03-07 00:15:25 +01:00
+ // Refresh misc player things AFTER sending game profile
+ this.refreshPlayer();
+ }
+ // 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) {
// SPIGOT-7312: Can't show/hide self
2023-12-06 20:46:49 +01:00
@@ -1806,6 +1852,36 @@ 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-09-22 04:31:59 +02:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundRespawnPacket(new net.minecraft.network.protocol.game.CommonPlayerSpawnInfo(worldserver.dimensionTypeId(), worldserver.dimension(), net.minecraft.world.level.biome.BiomeManager.obfuscateSeed(worldserver.getSeed()), handle.gameMode.getGameModeForPlayer(), handle.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), handle.getLastDeathLocation(), handle.getPortalCooldown()), net.minecraft.network.protocol.game.ClientboundRespawnPacket.KEEP_ALL_DATA));
2021-06-11 14:02:28 +02:00
+ handle.onUpdateAbilities();
2023-03-14 19:59:51 +01:00
+ connection.internalTeleport(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet());
2021-06-11 14:02:28 +02:00
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().sendAllPlayerInfo(handle);
+
+ // 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()) {
+ connection.send(new net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket(handle.getId(), mobEffect));
+ }
+
2021-06-11 14:02:28 +02:00
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
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
public void onEntityRemove(Entity entity) {
2023-03-14 19:59:51 +01:00
this.invertedVisibilityEntities.remove(entity.getUUID());
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
2023-12-05 23:12:48 +01:00
index 3720fa451cfd82d1df6461b88d12d2f53b364c92..afa93af41bf9b45dd7e49378b7fea088087993d5 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
2023-12-05 23:12:48 +01:00
@@ -341,6 +341,12 @@ public class Commodore
return;
}
+ // Paper start - Rewrite plugins
+ if ((owner.equals("org/bukkit/OfflinePlayer") || owner.equals("org/bukkit/entity/Player")) && name.equals("getPlayerProfile") && desc.equals("()Lorg/bukkit/profile/PlayerProfile;")) {
+ super.visitMethodInsn(opcode, owner, name, "()Lcom/destroystokyo/paper/profile/PlayerProfile;", itf);
+ return;
+ }
+ // Paper end
if ( modern )
{
if ( owner.equals( "org/bukkit/Material" ) )