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

105 lines
4.7 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
2023-10-27 01:34:58 +02:00
index 6c40bb4e06322bcce31561f5cfb9dc53f266f062..ba063a4e52a841a4365efb1cf78415b04b2bcc4c 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
@@ -111,7 +111,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;
@@ -121,11 +136,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 062594cebbe8cc0a0c94ecf7c8da4ee349a27521..b2bab2d79c969bc81b160312a996fb9cd87d0f95 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
@@ -187,6 +187,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(@org.jetbrains.annotations.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
+ }
+
+ @org.jetbrains.annotations.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
public OfflinePlayer getOwningPlayer() {
2021-06-12 18:56:13 +02:00
if (this.hasOwner()) {
@@ -237,6 +250,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
}
@Override
+ @Deprecated // Paper
public PlayerProfile getOwnerProfile() {
if (!this.hasOwner()) {
return null;
@@ -246,11 +260,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
}
}
@@ -305,7 +320,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
Builder<String, Object> serialize(Builder<String, Object> builder) {
super.serialize(builder);
if (this.profile != null) {
2023-10-27 01:34:58 +02:00
- return builder.put(CraftMetaSkull.SKULL_OWNER.BUKKIT, new CraftPlayerProfile(this.profile));
+ return builder.put(CraftMetaSkull.SKULL_OWNER.BUKKIT, new com.destroystokyo.paper.profile.CraftPlayerProfile(this.profile)); // Paper
}
NamespacedKey namespacedKeyNB = this.getNoteBlockSound();
if (namespacedKeyNB != null) {