From f193fdb1ab0f2a256e4c6a300c6ee8559bb459ce Mon Sep 17 00:00:00 2001 From: Aikar Date: Fri, 19 Jan 2018 00:38:49 -0500 Subject: [PATCH] Add SkullMeta.setPlayerProfile API This allows you to create already filled textures on Skulls to avoid texture lookups which commonly cause rate limit issues with Mojang API --- ...3-Add-SkullMeta.setPlayerProfile-API.patch | 48 +++++++++++++++++ .../0215-Basic-PlayerProfile-API.patch | 36 ++++++++++--- .../0217-Profile-Lookup-Events.patch | 6 +-- ...5-Add-SkullMeta.setPlayerProfile-API.patch | 53 +++++++++++++++++++ 4 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 Spigot-API-Patches/0083-Add-SkullMeta.setPlayerProfile-API.patch create mode 100644 Spigot-Server-Patches/0265-Add-SkullMeta.setPlayerProfile-API.patch diff --git a/Spigot-API-Patches/0083-Add-SkullMeta.setPlayerProfile-API.patch b/Spigot-API-Patches/0083-Add-SkullMeta.setPlayerProfile-API.patch new file mode 100644 index 0000000000..1749ebc824 --- /dev/null +++ b/Spigot-API-Patches/0083-Add-SkullMeta.setPlayerProfile-API.patch @@ -0,0 +1,48 @@ +From 34a4c1db4e30ccee65528ce7ef69e522bdc9d1d7 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Fri, 19 Jan 2018 00:29:28 -0500 +Subject: [PATCH] Add SkullMeta.setPlayerProfile API + +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/inventory/meta/SkullMeta.java b/src/main/java/org/bukkit/inventory/meta/SkullMeta.java +index c60860e1..3eea5909 100644 +--- a/src/main/java/org/bukkit/inventory/meta/SkullMeta.java ++++ b/src/main/java/org/bukkit/inventory/meta/SkullMeta.java +@@ -1,8 +1,11 @@ + package org.bukkit.inventory.meta; + ++import com.destroystokyo.paper.profile.PlayerProfile; + import org.bukkit.Material; + import org.bukkit.OfflinePlayer; + ++import javax.annotation.Nullable; ++ + /** + * Represents a skull ({@link Material#SKULL_ITEM}) that can have an owner. + */ +@@ -37,6 +40,20 @@ public interface SkullMeta extends ItemMeta { + @Deprecated + boolean setOwner(String owner); + ++ // 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, or null to clear owner ++ */ ++ void setPlayerProfile(@Nullable 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 owner of the skull. + * +-- +2.15.1 + diff --git a/Spigot-Server-Patches/0215-Basic-PlayerProfile-API.patch b/Spigot-Server-Patches/0215-Basic-PlayerProfile-API.patch index 76c144b810..857ec886ea 100644 --- a/Spigot-Server-Patches/0215-Basic-PlayerProfile-API.patch +++ b/Spigot-Server-Patches/0215-Basic-PlayerProfile-API.patch @@ -1,4 +1,4 @@ -From a59807ca537039ab042ad9d452339e8d652cd5fc Mon Sep 17 00:00:00 2001 +From 96b4614b35bf8df7a2d95c91f6b7df1b05641359 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 15 Jan 2018 22:11:48 -0500 Subject: [PATCH] Basic PlayerProfile API @@ -6,10 +6,10 @@ Subject: [PATCH] Basic PlayerProfile API diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java new file mode 100644 -index 000000000..6e9a6a2e6 +index 000000000..6868ee9a4 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java -@@ -0,0 +1,109 @@ +@@ -0,0 +1,133 @@ +package com.destroystokyo.paper.profile; + +import com.mojang.authlib.GameProfile; @@ -40,6 +40,10 @@ index 000000000..6e9a6a2e6 + this.profile = new GameProfile(id, name); + } + ++ public CraftPlayerProfile(GameProfile profile) { ++ this.profile = profile; ++ } ++ + public GameProfile getGameProfile() { + return profile; + } @@ -78,6 +82,13 @@ index 000000000..6e9a6a2e6 + } + + @Override ++ public CraftPlayerProfile clone() { ++ CraftPlayerProfile clone = new CraftPlayerProfile(this.getId(), this.getName()); ++ clone.setProperties(getProperties()); ++ return clone; ++ } ++ ++ @Override + public void setProperty(ProfileProperty property) { + String name = property.getName(); + PropertyMap properties = profile.getProperties(); @@ -109,18 +120,31 @@ index 000000000..6e9a6a2e6 + return new ProfileProperty(property.getName(), property.getValue(), property.getSignature()); + } + -+ public static PlayerProfile from(GameProfile gameProfile) { ++ public static PlayerProfile asBukkitCopy(GameProfile gameProfile) { + PlayerProfile profile = new CraftPlayerProfile(gameProfile.getId(), gameProfile.getName()); + gameProfile.getProperties().values().forEach(property -> profile.setProperty(toBukkit(property))); + return profile; + } + ++ public static PlayerProfile asBukkitMirror(GameProfile profile) { ++ return new CraftPlayerProfile(profile); ++ } ++ + public static Property asAuthlib(ProfileProperty property) { + return new Property(property.getName(), property.getValue(), property.getSignature()); + } ++ public static GameProfile asAuthlibCopy(PlayerProfile profile) { ++ CraftPlayerProfile craft = ((CraftPlayerProfile) profile); ++ return asAuthlib(craft.clone()); ++ } ++ ++ public static GameProfile asAuthlib(PlayerProfile profile) { ++ CraftPlayerProfile craft = ((CraftPlayerProfile) profile); ++ return craft.getGameProfile(); ++ } +} diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java -index 02940d697..f38afb72e 100644 +index 02940d697..4539b5601 100644 --- a/src/main/java/net/minecraft/server/MCUtil.java +++ b/src/main/java/net/minecraft/server/MCUtil.java @@ -1,6 +1,9 @@ @@ -138,7 +162,7 @@ index 02940d697..f38afb72e 100644 } + public static PlayerProfile toBukkit(GameProfile profile) { -+ return CraftPlayerProfile.from(profile); ++ return CraftPlayerProfile.asBukkitMirror(profile); + } + /** diff --git a/Spigot-Server-Patches/0217-Profile-Lookup-Events.patch b/Spigot-Server-Patches/0217-Profile-Lookup-Events.patch index 658e3d4bd5..6e2b485271 100644 --- a/Spigot-Server-Patches/0217-Profile-Lookup-Events.patch +++ b/Spigot-Server-Patches/0217-Profile-Lookup-Events.patch @@ -1,4 +1,4 @@ -From 6b77e6fa3e669dd9e07bee8fa58e5e197b694228 Mon Sep 17 00:00:00 2001 +From b034c0418594d6a49949633b857a6f310f364604 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 17 Jun 2017 17:00:32 -0400 Subject: [PATCH] Profile Lookup Events @@ -8,7 +8,7 @@ profiles that had to be looked up. diff --git a/src/main/java/com/destroystokyo/paper/profile/WrappedGameProfileRepository.java b/src/main/java/com/destroystokyo/paper/profile/WrappedGameProfileRepository.java new file mode 100644 -index 000000000..950fa930d +index 000000000..bffba6a65 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/profile/WrappedGameProfileRepository.java @@ -0,0 +1,70 @@ @@ -71,7 +71,7 @@ index 000000000..950fa930d + + @Override + public void onProfileLookupSucceeded(GameProfile gameProfile) { -+ PlayerProfile from = CraftPlayerProfile.from(gameProfile); ++ PlayerProfile from = CraftPlayerProfile.asBukkitMirror(gameProfile); + new LookupProfileEvent(from).callEvent(); + callback.onProfileLookupSucceeded(gameProfile); + } diff --git a/Spigot-Server-Patches/0265-Add-SkullMeta.setPlayerProfile-API.patch b/Spigot-Server-Patches/0265-Add-SkullMeta.setPlayerProfile-API.patch new file mode 100644 index 0000000000..8e5ae26e15 --- /dev/null +++ b/Spigot-Server-Patches/0265-Add-SkullMeta.setPlayerProfile-API.patch @@ -0,0 +1,53 @@ +From 1da2d5ebec485e442b4faf5e78d1affcdb98d0d9 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Fri, 19 Jan 2018 00:36:25 -0500 +Subject: [PATCH] Add SkullMeta.setPlayerProfile API + +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/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +index e2ea49cd9..4855307b9 100644 +--- a/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; + + import java.util.Map; + ++import com.destroystokyo.paper.profile.CraftPlayerProfile; ++import com.destroystokyo.paper.profile.PlayerProfile; + import net.minecraft.server.GameProfileSerializer; + import net.minecraft.server.NBTBase; + import net.minecraft.server.NBTTagCompound; +@@ -19,6 +21,8 @@ import org.bukkit.inventory.meta.SkullMeta; + import com.google.common.collect.ImmutableMap.Builder; + import com.mojang.authlib.GameProfile; + ++import javax.annotation.Nullable; ++ + @DelegateDeserialization(SerializableMeta.class) + class CraftMetaSkull extends CraftMetaItem implements SkullMeta { + +@@ -119,6 +123,19 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { + return hasOwner() ? profile.getName() : null; + } + ++ // Paper start ++ @Override ++ public void setPlayerProfile(@Nullable PlayerProfile profile) { ++ this.profile = (profile == null) ? null : CraftPlayerProfile.asAuthlibCopy(profile); ++ } ++ ++ @Nullable ++ @Override ++ public PlayerProfile getPlayerProfile() { ++ return profile != null ? CraftPlayerProfile.asBukkitMirror(profile) : null; ++ } ++ // Paper end ++ + @Override + public OfflinePlayer getOwningPlayer() { + if (hasOwner()) { +-- +2.15.1 +