From f8ce5bbbeb7472083818c7cf963f261a812dd575 Mon Sep 17 00:00:00 2001 From: nostalgic853 Date: Sun, 20 Nov 2022 00:21:10 +0800 Subject: [PATCH] Player Skull API --- patches/api/0007-Player-Skull-API.patch | 43 ++++++++++++++++ patches/server/0021-Player-Skull-API.patch | 57 ++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 patches/api/0007-Player-Skull-API.patch create mode 100644 patches/server/0021-Player-Skull-API.patch diff --git a/patches/api/0007-Player-Skull-API.patch b/patches/api/0007-Player-Skull-API.patch new file mode 100644 index 0000000..5d9d883 --- /dev/null +++ b/patches/api/0007-Player-Skull-API.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: nostalgic853 +Date: Sun, 20 Nov 2022 00:20:01 +0800 +Subject: [PATCH] Player Skull API + + +diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java +index 5ed16b78c39de21eff18a4824f84457a7c70fb58..fda61b6b550ab58d3a6ca0c4981ebf37885983b8 100644 +--- a/src/main/java/org/bukkit/entity/Player.java ++++ b/src/main/java/org/bukkit/entity/Player.java +@@ -3,6 +3,9 @@ package org.bukkit.entity; + import java.net.InetSocketAddress; + import java.util.Collection; + import java.util.UUID; ++import java.util.concurrent.CompletableFuture; ++import java.util.concurrent.Future; ++ + import com.destroystokyo.paper.ClientOption; // Paper + import com.destroystokyo.paper.Title; // Paper + import net.kyori.adventure.text.Component; +@@ -3020,4 +3023,22 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM + */ + void sendDeathScreen(@NotNull Component message, @Nullable Entity killer); + // Purpur end ++ ++ // KeYi start ++ /** ++ * Get a skull item of a player. ++ * This method runs on main thread, which may freeze the server. ++ * ++ * @return A ItemStack of the skull of the player ++ */ ++ ItemStack getSkull(); ++ ++ /** ++ * Get a skull item of a player. ++ * This method runs on main thread, which may freeze the server. ++ * ++ * @return A CompletableFuture the of ItemStack of the skull of the player ++ */ ++ CompletableFuture getSkullAsynchronously(); ++ // KeYi end + } diff --git a/patches/server/0021-Player-Skull-API.patch b/patches/server/0021-Player-Skull-API.patch new file mode 100644 index 0000000..f30b4fe --- /dev/null +++ b/patches/server/0021-Player-Skull-API.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: nostalgic853 +Date: Sun, 20 Nov 2022 00:20:00 +0800 +Subject: [PATCH] Player Skull API + + +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index 2400d9d488259f73f4ae02fe06b107e5c470a7dd..cc98f5aca737bcf226626029f83b7ddae51b87cb 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -26,6 +26,9 @@ import java.util.Optional; + import java.util.Set; + import java.util.UUID; + import java.util.WeakHashMap; ++import java.util.concurrent.CompletableFuture; ++import java.util.concurrent.ExecutorService; ++import java.util.concurrent.Executors; + import java.util.logging.Level; + import java.util.logging.Logger; + import javax.annotation.Nullable; +@@ -144,6 +147,7 @@ import org.bukkit.event.player.PlayerUnregisterChannelEvent; + import org.bukkit.inventory.EquipmentSlot; + import org.bukkit.inventory.InventoryView.Property; + import org.bukkit.inventory.ItemStack; ++import org.bukkit.inventory.meta.SkullMeta; + import org.bukkit.map.MapCursor; + import org.bukkit.map.MapView; + import org.bukkit.metadata.MetadataValue; +@@ -3103,4 +3107,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + this.getHandle().connection.send(packet); + } + // Purpur end ++ ++ // KeYi start ++ @Override ++ public ItemStack getSkull() { ++ ItemStack skull = new ItemStack(Material.PLAYER_HEAD, 1); ++ SkullMeta meta = (SkullMeta) skull.getItemMeta(); ++ ++ meta.setOwningPlayer(this); ++ ++ skull.setItemMeta(meta); ++ ++ return skull; ++ } ++ ++ @Override ++ public CompletableFuture getSkullAsynchronously() { ++ ExecutorService executorService = Executors.newCachedThreadPool(); ++ ++ CompletableFuture future = (CompletableFuture) executorService.submit(() -> getSkull()); ++ executorService.shutdown(); ++ ++ return future; ++ } ++ // KeYi end + }