Paper/patches/server/0174-Add-setPlayerProfile-API-for-Skulls.patch

128 lines
5.4 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: Fri, 19 Jan 2018 00:36:25 -0500
Subject: [PATCH] Add setPlayerProfile API for Skulls
This allows you to create already filled textures on Skulls to avoid texture lookups
which commonly cause rate limit issues with Mojang API
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
index 6ac03706a584e4cb07300cf6e34969a8c4595c58..0be71d9d06f34e9ac58da3bbef954b2786cee53b 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
@@ -102,7 +102,22 @@ public class CraftSkull extends CraftBlockEntityState<SkullBlockEntity> implemen
2021-06-11 14:02:28 +02:00
}
}
+ // Paper start
@Override
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
2021-06-11 14:02:28 +02:00
+ Preconditions.checkNotNull(profile, "profile");
+ this.profile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
2021-06-11 14:02:28 +02:00
+ }
+
2021-06-12 18:56:13 +02:00
+ @javax.annotation.Nullable
2021-06-11 14:02:28 +02:00
+ @Override
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
+ return profile != null ? com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitCopy(profile) : null;
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
+ @Override
+ @Deprecated // Paper
public PlayerProfile getOwnerProfile() {
if (!this.hasOwner()) {
return null;
@@ -112,11 +127,12 @@ public class CraftSkull extends CraftBlockEntityState<SkullBlockEntity> implemen
}
2021-06-11 14:02:28 +02:00
@Override
+ @Deprecated // Paper
public void setOwnerProfile(PlayerProfile profile) {
if (profile == null) {
this.profile = null;
} else {
- this.profile = CraftPlayerProfile.validateSkullProfile(((CraftPlayerProfile) profile).buildGameProfile());
+ this.profile = CraftPlayerProfile.validateSkullProfile(((com.destroystokyo.paper.profile.SharedPlayerProfile) profile).buildGameProfile()); // Paper
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
index eda37a7622748feef782b54235070c04f3c714f8..9f72e1623fc85301c4ca8751a7e03877a7745948 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
@@ -4,10 +4,6 @@ import com.google.common.collect.ImmutableMap.Builder;
2021-06-11 14:02:28 +02:00
import com.mojang.authlib.GameProfile;
import java.util.Map;
import java.util.UUID;
-import net.minecraft.nbt.CompoundTag;
-import net.minecraft.nbt.NbtUtils;
-import net.minecraft.nbt.Tag;
-import net.minecraft.world.level.block.entity.SkullBlockEntity;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@@ -20,6 +16,11 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers;
2021-06-11 14:02:28 +02:00
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.profile.PlayerProfile;
2021-06-11 14:02:28 +02:00
+import javax.annotation.Nullable;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.NbtUtils;
+import net.minecraft.nbt.Tag;
+import net.minecraft.world.level.block.entity.SkullBlockEntity;
@DelegateDeserialization(SerializableMeta.class)
class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
@@ -151,6 +152,19 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
2021-06-12 18:56:13 +02:00
return this.hasOwner() ? this.profile.getName() : null;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
+ @Override
+ public void setPlayerProfile(@Nullable com.destroystokyo.paper.profile.PlayerProfile profile) {
+ setProfile((profile == null) ? null : com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile));
2021-06-11 14:02:28 +02:00
+ }
+
+ @Nullable
+ @Override
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
+ return profile != null ? com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitCopy(profile) : null;
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
+
@Override
public OfflinePlayer getOwningPlayer() {
2021-06-12 18:56:13 +02:00
if (this.hasOwner()) {
@@ -201,6 +215,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
}
@Override
+ @Deprecated // Paper
public PlayerProfile getOwnerProfile() {
if (!this.hasOwner()) {
return null;
@@ -210,11 +225,12 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
}
@Override
+ @Deprecated // Paper
public void setOwnerProfile(PlayerProfile profile) {
if (profile == null) {
this.setProfile(null);
} else {
- this.setProfile(CraftPlayerProfile.validateSkullProfile(((CraftPlayerProfile) profile).buildGameProfile()));
+ this.setProfile(CraftPlayerProfile.validateSkullProfile(((com.destroystokyo.paper.profile.SharedPlayerProfile) profile).buildGameProfile())); // Paper
}
}
@@ -251,7 +267,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
Builder<String, Object> serialize(Builder<String, Object> builder) {
super.serialize(builder);
if (this.hasOwner()) {
- return builder.put(SKULL_OWNER.BUKKIT, new CraftPlayerProfile(this.profile));
+ return builder.put(SKULL_OWNER.BUKKIT, new com.destroystokyo.paper.profile.CraftPlayerProfile(this.profile)); // Paper
}
return builder;
}