3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/patches/server/0182-Player.setPlayerProfile-API.patch
Nassim Jahnke 9df2066642
Updated Upstream (Bukkit/CraftBukkit)
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:
dfe1fb48 PR-906: Add missing MinecraftExperimental annotation to Bundles
825ab30d PR-905: Add missing MapCursor.Type and update documentation
e03d10e6 PR-903: Make BARRIER Waterlogged
1961ead6 PR-898: Use Java Consumer instead of Bukkit Consumer

CraftBukkit Changes:
f71a799f0 Make BARRIER Waterlogged
172f76a45 Upgrade specialsource-maven-plugin
f0702775c SPIGOT-7486: Alternate approach to null profile names
069495671 SPIGOT-7485: Allow air entity items since required for Vanilla logic
5dfd33dc2 SPIGOT-7484: Cancelling PlayerEditBookEvent does not update client's book contents
02d490788 PR-1250: Standardize and centralize Bukkit / Minecraft registry conversion
9024a09b9 PR-1251: Use Java Consumer instead of Bukkit Consumer
6d4b25bf1 Increase diff stability
2023-09-23 12:21:59 +10:00

219 Zeilen
12 KiB
Diff

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
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 4ba7ed0a4ff52caa21632f69ab087564fb3a5eb7..5b8425b17ea322bb1141b1c94ee3c259d3950ca0 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1437,7 +1437,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
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;
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 41de3c342f1dae9fc6af1b4938a676d337bcf5fa..f870c20ecce27ebd893107a35e1b8f15e462ff85 100644
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -293,11 +293,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;
// Paper start
- 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);
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
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();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index 498b14ca0e45b76259450d9a0c8206b1e9f25e70..c1ef6c8c8e5f030e18b6066a509350ee1e195987 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
@@ -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() {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 9920a3d81c44972cba742d67764b5066362f79aa..e864252e4fcd0927275d6b9009cdde78d3e289eb 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -271,11 +271,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return server.getPlayer(getUniqueId()) != null;
}
- @Override
- public PlayerProfile getPlayerProfile() {
- return new CraftPlayerProfile(this.getProfile());
- }
-
@Override
public InetSocketAddress getAddress() {
if (this.getHandle().connection == null) return null;
@@ -1690,8 +1685,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private void untrackAndHideEntity(org.bukkit.entity.Entity entity) {
// Remove this entity from the hidden player's EntityTrackerEntry
- ChunkMap tracker = ((ServerLevel) this.getHandle().level()).getChunkSource().chunkMap;
+ // Paper start
Entity other = ((CraftEntity) entity).getHandle();
+ unregisterEntity(other);
+
+ server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
+ }
+ private void unregisterEntity(Entity other) {
+ // Paper end
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level()).getChunkSource().chunkMap;
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
if (entry != null) {
entry.removePlayer(this.getHandle());
@@ -1704,8 +1706,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.getHandle().connection.send(new ClientboundPlayerInfoRemovePacket(List.of(otherPlayer.getUUID())));
}
}
-
- server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
}
void resetAndHideEntity(org.bukkit.entity.Entity entity) {
@@ -1770,12 +1770,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());
@@ -1785,6 +1798,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
}
+ // Paper start
+ @Override
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
+ ServerPlayer self = this.getHandle();
+ GameProfile gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
+ if (!self.sentListPacket) {
+ self.gameProfile = gameProfile;
+ return;
+ }
+ List<ServerPlayer> players = this.server.getServer().getPlayerList().players;
+ // First unregister the player for all players with the OLD game profile
+ for (ServerPlayer player : players) {
+ CraftPlayer bukkitPlayer = player.getBukkitEntity();
+ if (bukkitPlayer.canSee(this)) {
+ bukkitPlayer.unregisterEntity(self);
+ }
+ }
+
+ // Set the game profile here, we should have unregistered the entity via iterating all player entities above.
+ self.gameProfile = gameProfile;
+
+ // 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());
+ }
+ }
+
+ // Refresh misc player things AFTER sending game profile
+ this.refreshPlayer();
+ }
+ // Paper end
void resetAndShowEntity(org.bukkit.entity.Entity entity) {
// SPIGOT-7312: Can't show/hide self
@@ -1796,6 +1842,36 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.trackAndShowEntity(entity);
}
}
+ // Paper start
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this).clone();
+ }
+
+ private void refreshPlayer() {
+ ServerPlayer handle = this.getHandle();
+ Location loc = this.getLocation();
+
+ ServerGamePacketListenerImpl connection = handle.connection;
+
+ //Respawn the player then update their position and selected slot
+ ServerLevel worldserver = handle.serverLevel();
+ 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));
+ handle.onUpdateAbilities();
+ connection.internalTeleport(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet());
+ 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));
+ }
+
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
+ }
+ // Paper end
public void onEntityRemove(Entity entity) {
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
index 44b73939c465398c8cfda5dbea3280392f194add..aba415ab7203a21e916eadb923cb02c03b679f65 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
@@ -338,6 +338,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" ) )