mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-09 06:50:32 +08:00
Player.setPlayerProfile API
This can be useful for changing name or skins after a player has logged in.
This commit is contained in:
parent
fb02c91835
commit
c2933f8106
41
Spigot-API-Patches/0090-Player.setPlayerProfile-API.patch
Normal file
41
Spigot-API-Patches/0090-Player.setPlayerProfile-API.patch
Normal file
@ -0,0 +1,41 @@
|
||||
From dbee4791c374b48bb95668084b14f29c58fda4d6 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sun, 18 Mar 2018 12:28:55 -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/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
||||
index a882323d..eac8195f 100644
|
||||
--- a/src/main/java/org/bukkit/entity/Player.java
|
||||
+++ b/src/main/java/org/bukkit/entity/Player.java
|
||||
@@ -3,6 +3,7 @@ package org.bukkit.entity;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import com.destroystokyo.paper.Title;
|
||||
+import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import org.bukkit.Achievement;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Effect;
|
||||
@@ -1713,6 +1714,18 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
|
||||
* was {@link org.bukkit.event.player.PlayerResourcePackStatusEvent.Status#SUCCESSFULLY_LOADED}
|
||||
*/
|
||||
boolean hasResourcePack();
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a copy of this players profile
|
||||
+ * @return The players profile object
|
||||
+ */
|
||||
+ PlayerProfile getPlayerProfile();
|
||||
+
|
||||
+ /**
|
||||
+ * Changes the PlayerProfile for this player. This will cause all
|
||||
+ * @param profile
|
||||
+ */
|
||||
+ void setPlayerProfile(PlayerProfile profile);
|
||||
// Paper end
|
||||
|
||||
// Spigot start
|
||||
--
|
||||
2.16.2
|
||||
|
92
Spigot-Server-Patches/0277-Player.setPlayerProfile-API.patch
Normal file
92
Spigot-Server-Patches/0277-Player.setPlayerProfile-API.patch
Normal file
@ -0,0 +1,92 @@
|
||||
From 8e31a909319ac13bcacf35a8cc6c89c05b69c246 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.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
||||
index 4b82e43a8..35fde8b23 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
||||
@@ -59,7 +59,7 @@ public abstract class EntityHuman extends EntityLiving {
|
||||
protected int bS;
|
||||
protected float bT = 0.02F;
|
||||
private int f;
|
||||
- private final GameProfile g;
|
||||
+ private GameProfile g; public void setProfile(GameProfile profile) { this.g = profile; } // Paper - OBFHELPER
|
||||
private ItemStack bV;
|
||||
private final ItemCooldown bW;
|
||||
@Nullable
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
index 21631c588..f0e3c2cff 100644
|
||||
--- 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;
|
||||
@@ -1092,8 +1094,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
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());
|
||||
@@ -1134,8 +1142,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
}
|
||||
hiddenPlayers.remove(player.getUniqueId());
|
||||
|
||||
- EntityTracker tracker = ((WorldServer) entity.world).tracker;
|
||||
+ // Paper start
|
||||
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
||||
+ }
|
||||
+ private void registerPlayer(EntityPlayer other) {
|
||||
+ EntityTracker tracker = ((WorldServer) entity.world).tracker;
|
||||
+ // Paper end
|
||||
|
||||
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
|
||||
|
||||
@@ -1144,6 +1156,25 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
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() {
|
||||
+ return CraftPlayerProfile.asBukkitCopy(getHandle().getProfile());
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
public void removeDisconnectingPlayer(Player player) {
|
||||
hiddenPlayers.remove(player.getUniqueId());
|
||||
--
|
||||
2.16.2
|
||||
|
Loading…
Reference in New Issue
Block a user