diff --git a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoarmor/proxy/v1_15_R1/Skull.java b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoarmor/proxy/v1_15_R1/Skull.java new file mode 100644 index 0000000..4b9766f --- /dev/null +++ b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/ecoarmor/proxy/v1_15_R1/Skull.java @@ -0,0 +1,41 @@ +package com.willfp.ecoarmor.proxy.v1_15_R1; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.willfp.ecoarmor.proxy.proxies.SkullProxy; +import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +public class Skull implements SkullProxy { + /** + * Cached method to set the gameProfile. + */ + private Method setProfile = null; + + @Override + public void setTalismanTexture(@NotNull final SkullMeta meta, + @NotNull final String base64) { + try { + if (setProfile == null) { + setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class); + setProfile.setAccessible(true); + } + + UUID uuid = new UUID( + base64.substring(base64.length() - 20).hashCode(), + base64.substring(base64.length() - 10).hashCode() + ); + + GameProfile profile = new GameProfile(uuid, "talismans"); + profile.getProperties().put("textures", new Property("textures", base64)); + + setProfile.invoke(meta, profile); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R1/Skull.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R1/Skull.java new file mode 100644 index 0000000..9c9b0fa --- /dev/null +++ b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R1/Skull.java @@ -0,0 +1,41 @@ +package com.willfp.ecoarmor.proxy.v1_16_R1; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.willfp.ecoarmor.proxy.proxies.SkullProxy; +import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +public class Skull implements SkullProxy { + /** + * Cached method to set the gameProfile. + */ + private Method setProfile = null; + + @Override + public void setTalismanTexture(@NotNull final SkullMeta meta, + @NotNull final String base64) { + try { + if (setProfile == null) { + setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class); + setProfile.setAccessible(true); + } + + UUID uuid = new UUID( + base64.substring(base64.length() - 20).hashCode(), + base64.substring(base64.length() - 10).hashCode() + ); + + GameProfile profile = new GameProfile(uuid, "talismans"); + profile.getProperties().put("textures", new Property("textures", base64)); + + setProfile.invoke(meta, profile); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R2/Skull.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R2/Skull.java new file mode 100644 index 0000000..9ae7270 --- /dev/null +++ b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R2/Skull.java @@ -0,0 +1,41 @@ +package com.willfp.ecoarmor.proxy.v1_16_R2; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.willfp.ecoarmor.proxy.proxies.SkullProxy; +import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +public class Skull implements SkullProxy { + /** + * Cached method to set the gameProfile. + */ + private Method setProfile = null; + + @Override + public void setTalismanTexture(@NotNull final SkullMeta meta, + @NotNull final String base64) { + try { + if (setProfile == null) { + setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class); + setProfile.setAccessible(true); + } + + UUID uuid = new UUID( + base64.substring(base64.length() - 20).hashCode(), + base64.substring(base64.length() - 10).hashCode() + ); + + GameProfile profile = new GameProfile(uuid, "talismans"); + profile.getProperties().put("textures", new Property("textures", base64)); + + setProfile.invoke(meta, profile); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R3/Skull.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R3/Skull.java new file mode 100644 index 0000000..75973df --- /dev/null +++ b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoarmor/proxy/v1_16_R3/Skull.java @@ -0,0 +1,41 @@ +package com.willfp.ecoarmor.proxy.v1_16_R3; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.willfp.ecoarmor.proxy.proxies.SkullProxy; +import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.UUID; + +public class Skull implements SkullProxy { + /** + * Cached method to set the gameProfile. + */ + private Method setProfile = null; + + @Override + public void setTalismanTexture(@NotNull final SkullMeta meta, + @NotNull final String base64) { + try { + if (setProfile == null) { + setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class); + setProfile.setAccessible(true); + } + + UUID uuid = new UUID( + base64.substring(base64.length() - 20).hashCode(), + base64.substring(base64.length() - 10).hashCode() + ); + + GameProfile profile = new GameProfile(uuid, "talismans"); + profile.getProperties().put("textures", new Property("textures", base64)); + + setProfile.invoke(meta, profile); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java index ad5f64a..4400bb0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java @@ -1,12 +1,14 @@ package com.willfp.ecoarmor.sets; import com.willfp.eco.common.recipes.lookup.RecipePartUtils; +import com.willfp.eco.util.ProxyUtils; import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.recipe.EcoShapedRecipe; import com.willfp.ecoarmor.config.EcoArmorConfigs; import com.willfp.ecoarmor.effects.Effect; import com.willfp.ecoarmor.effects.Effects; +import com.willfp.ecoarmor.proxy.proxies.SkullProxy; import lombok.Getter; import org.bukkit.Color; import org.bukkit.Material; @@ -16,6 +18,7 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.bukkit.potion.PotionEffectType; @@ -125,6 +128,12 @@ public class ArmorSet { assert meta != null; + if (material == Material.PLAYER_HEAD) { + String base64 = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".skull-texture"); + + ProxyUtils.getProxy(SkullProxy.class).setTalismanTexture((SkullMeta) meta, base64); + } + if (material.toString().toLowerCase().contains("leather")) { String colorString = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".leather-color"); diff --git a/eco-core/core-proxy/src/main/java/com/willfp/ecoarmor/proxy/proxies/SkullProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/ecoarmor/proxy/proxies/SkullProxy.java new file mode 100644 index 0000000..fbb5336 --- /dev/null +++ b/eco-core/core-proxy/src/main/java/com/willfp/ecoarmor/proxy/proxies/SkullProxy.java @@ -0,0 +1,16 @@ +package com.willfp.ecoarmor.proxy.proxies; + +import com.willfp.eco.util.proxy.AbstractProxy; +import org.bukkit.inventory.meta.SkullMeta; +import org.jetbrains.annotations.NotNull; + +public interface SkullProxy extends AbstractProxy { + /** + * Set the texture of a skull from base64. + * + * @param meta The meta to modify. + * @param base64 The base64 texture. + */ + void setTalismanTexture(@NotNull SkullMeta meta, + @NotNull String base64); +}