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
This commit is contained in:
Aikar
2018-03-18 12:29:48 -04:00
parent 5fb78725e4
commit d0d0b1a21e
5 changed files with 123 additions and 27 deletions

View File

@@ -242,11 +242,11 @@
+
+ // Paper start - Add more fields to AsyncPlayerPreLoginEvent
+ final InetAddress rawAddress = ((InetSocketAddress) this.connection.channel.remoteAddress()).getAddress();
+ 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
+ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, rawAddress, uniqueId, this.transferred, profile, this.connection.hostname);
+ 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();

View File

@@ -709,7 +709,22 @@
return entityplayer1;
}
@@ -524,7 +808,18 @@
@@ -516,15 +800,32 @@
}
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() {
if (++this.sendAllPlayerInfoIn > 600) {
@@ -729,7 +744,7 @@
this.sendAllPlayerInfoIn = 0;
}
@@ -541,6 +836,25 @@
@@ -541,6 +842,25 @@
}
@@ -755,7 +770,7 @@
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
Iterator iterator = this.players.iterator();
@@ -554,7 +868,7 @@
@@ -554,7 +874,7 @@
}
@@ -764,7 +779,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam != null) {
@@ -573,7 +887,7 @@
@@ -573,7 +893,7 @@
}
}
@@ -773,7 +788,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam == null) {
@@ -619,7 +933,7 @@
@@ -619,7 +939,7 @@
}
public void deop(GameProfile profile) {
@@ -782,7 +797,7 @@
ServerPlayer entityplayer = this.getPlayer(profile.getId());
if (entityplayer != null) {
@@ -643,36 +957,51 @@
@@ -643,36 +963,51 @@
player.connection.send(new ClientboundEntityEventPacket(player, b0));
}
@@ -847,7 +862,7 @@
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
double d4 = x - entityplayer.getX();
double d5 = y - entityplayer.getY();
@@ -687,10 +1016,12 @@
@@ -687,10 +1022,12 @@
}
public void saveAll() {
@@ -860,7 +875,7 @@
}
public UserWhiteList getWhiteList() {
@@ -712,15 +1043,19 @@
@@ -712,15 +1049,19 @@
public void reloadWhiteList() {}
public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
@@ -884,7 +899,7 @@
}
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
@@ -729,8 +1064,16 @@
@@ -729,8 +1070,16 @@
public void sendAllPlayerInfo(ServerPlayer player) {
player.inventoryMenu.sendAllDataToRemote();
@@ -902,7 +917,7 @@
}
public int getPlayerCount() {
@@ -786,11 +1129,35 @@
@@ -786,11 +1135,35 @@
}
public void removeAll() {
@@ -940,7 +955,7 @@
public void broadcastSystemMessage(Component message, boolean overlay) {
this.broadcastSystemMessage(message, (entityplayer) -> {
@@ -819,24 +1186,43 @@
@@ -819,24 +1192,43 @@
}
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
@@ -987,7 +1002,7 @@
}
if (flag1 && sender != null) {
@@ -845,20 +1231,27 @@
@@ -845,20 +1237,27 @@
}
@@ -1020,7 +1035,7 @@
Path path = file2.toPath();
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -867,7 +1260,7 @@
@@ -867,7 +1266,7 @@
}
serverstatisticmanager = new ServerStatsCounter(this.server, file1);
@@ -1029,7 +1044,7 @@
}
return serverstatisticmanager;
@@ -875,13 +1268,13 @@
@@ -875,13 +1274,13 @@
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
UUID uuid = player.getUUID();
@@ -1045,7 +1060,7 @@
}
advancementdataplayer.setPlayer(player);
@@ -932,15 +1325,28 @@
@@ -932,15 +1331,28 @@
}
public void reloadResources() {