[1.13] Skull block profile api (#1308)

Adds #1307
This commit is contained in:
Brokkonaut 2018-08-06 07:24:55 +02:00 committed by Daniel Ennis
parent a57facb10c
commit d5eb80049c
2 changed files with 82 additions and 7 deletions

View file

@ -1,11 +1,45 @@
From 0a29a32a10268a1478ad045924aa706d7da5685a Mon Sep 17 00:00:00 2001 From 55e3e61db93e7dba8a19a6f2094fccf3b2fcab2f Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Fri, 19 Jan 2018 00:29:28 -0500 Date: Fri, 19 Jan 2018 00:29:28 -0500
Subject: [PATCH] Add SkullMeta.setPlayerProfile API Subject: [PATCH] Add setPlayerProfile API for Skulls
This allows you to create already filled textures on Skulls to avoid texture lookups This allows you to create already filled textures on Skulls to avoid texture lookups
which commonly cause rate limit issues with Mojang API which commonly cause rate limit issues with Mojang API
diff --git a/src/main/java/org/bukkit/block/Skull.java b/src/main/java/org/bukkit/block/Skull.java
index 92363d33..b83df2f7 100644
--- a/src/main/java/org/bukkit/block/Skull.java
+++ b/src/main/java/org/bukkit/block/Skull.java
@@ -4,6 +4,8 @@ import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.SkullType;
import org.bukkit.block.data.BlockData;
+import com.destroystokyo.paper.profile.PlayerProfile;
+import javax.annotation.Nullable;
/**
* Represents a captured state of a skull block.
@@ -55,6 +57,20 @@ public interface Skull extends BlockState {
*/
public void setOwningPlayer(OfflinePlayer player);
+ // Paper start
+ /**
+ * Sets this skull to use the supplied Player Profile, which can include textures already prefilled.
+ * @param profile The profile to set this Skull to use, may not be null
+ */
+ void setPlayerProfile(PlayerProfile profile);
+
+ /**
+ * If the skull has an owner, per {@link #hasOwner()}, return the owners {@link PlayerProfile}
+ * @return The profile of the owner, if set
+ */
+ @Nullable PlayerProfile getPlayerProfile();
+ // Paper end
+
/**
* Gets the rotation of the skull in the world
*
diff --git a/src/main/java/org/bukkit/inventory/meta/SkullMeta.java b/src/main/java/org/bukkit/inventory/meta/SkullMeta.java diff --git a/src/main/java/org/bukkit/inventory/meta/SkullMeta.java b/src/main/java/org/bukkit/inventory/meta/SkullMeta.java
index 15c1dfd9..a458000f 100644 index 15c1dfd9..a458000f 100644
--- a/src/main/java/org/bukkit/inventory/meta/SkullMeta.java --- a/src/main/java/org/bukkit/inventory/meta/SkullMeta.java
@ -43,5 +77,5 @@ index 15c1dfd9..a458000f 100644
* Gets the owner of the skull. * Gets the owner of the skull.
* *
-- --
2.18.0 2.16.1.windows.1

View file

@ -1,13 +1,54 @@
From df8ebfaa4210ab08be4e6555bd8ebd08353a8a39 Mon Sep 17 00:00:00 2001 From 72c9d4a3673cc9e9bff91d550b9fd598b38df04f Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Fri, 19 Jan 2018 00:36:25 -0500 Date: Fri, 19 Jan 2018 00:36:25 -0500
Subject: [PATCH] Add SkullMeta.setPlayerProfile API Subject: [PATCH] Add setPlayerProfile API for Skulls
This allows you to create already filled textures on Skulls to avoid texture lookups This allows you to create already filled textures on Skulls to avoid texture lookups
which commonly cause rate limit issues with Mojang API 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 f113da713..fdfe101ae 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java
@@ -1,5 +1,7 @@
package org.bukkit.craftbukkit.block;
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
+import com.destroystokyo.paper.profile.PlayerProfile;
import com.google.common.base.Preconditions;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;
@@ -13,6 +15,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Skull;
import org.bukkit.block.data.Rotatable;
+import javax.annotation.Nullable;
public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implements Skull {
@@ -99,6 +102,20 @@ public class CraftSkull extends CraftBlockEntityState<TileEntitySkull> implement
this.profile = new GameProfile(player.getUniqueId(), player.getName());
}
+ // Paper start
+ @Override
+ public void setPlayerProfile(PlayerProfile profile) {
+ Preconditions.checkNotNull(profile, "profile");
+ this.profile = CraftPlayerProfile.asAuthlibCopy(profile);
+ }
+
+ @Nullable
+ @Override
+ public PlayerProfile getPlayerProfile() {
+ return profile != null ? CraftPlayerProfile.asBukkitCopy(profile) : null;
+ }
+ // Paper end
+
@Override
public BlockFace getRotation() {
return ((Rotatable) getBlockData()).getRotation();
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
index 7984c68cb0..14d8dd65ac 100644 index 7984c68cb..14d8dd65a 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
@@ -2,6 +2,8 @@ package org.bukkit.craftbukkit.inventory; @@ -2,6 +2,8 @@ package org.bukkit.craftbukkit.inventory;
@ -49,5 +90,5 @@ index 7984c68cb0..14d8dd65ac 100644
public OfflinePlayer getOwningPlayer() { public OfflinePlayer getOwningPlayer() {
if (hasOwner()) { if (hasOwner()) {
-- --
2.18.0 2.16.1.windows.1