diff --git a/pom.xml b/pom.xml
index 71b067e..db6259d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
4.0.0
de.nononitas
PlotBorder
- 1.9.3
+ 1.9.4_BETA
@@ -75,7 +75,7 @@
org.spigotmc
spigot-api
- 1.17-R0.1-SNAPSHOT
+ 1.20.2-R0.1-SNAPSHOT
provided
@@ -97,7 +97,12 @@
FastAsyncWorldEdit-Core
provided
-
+
+ org.json
+ json
+ 20230227
+ compile
+
\ No newline at end of file
diff --git a/src/main/java/de/nononitas/plotborder/util/Heads.java b/src/main/java/de/nononitas/plotborder/util/Heads.java
index 4c9fcf3..0e70a69 100644
--- a/src/main/java/de/nononitas/plotborder/util/Heads.java
+++ b/src/main/java/de/nononitas/plotborder/util/Heads.java
@@ -9,11 +9,18 @@
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
+import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.profile.PlayerProfile;
+import org.bukkit.profile.PlayerTextures;
+import org.json.JSONObject;
import java.lang.reflect.Field;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Base64;
import java.util.UUID;
public enum Heads {
@@ -31,32 +38,46 @@ public enum Heads {
}
private static ItemStack createSkull(final String URL, String name) {
-
String url = URL;
- if(!url.contains("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv")) {
+ if (!url.contains("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv")) {
url = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv" + url;
}
- ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
-
- SkullMeta headMeta = (SkullMeta) head.getItemMeta();
-
- GameProfile profile = new GameProfile(UUID.randomUUID(), null);
-
- profile.getProperties().put("textures", new Property("textures", url));
-
- try {
- Field profileField = headMeta.getClass().getDeclaredField("profile");
- profileField.setAccessible(true);
- profileField.set(headMeta, profile);
-
- } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
- error.printStackTrace();
+ if (isOldBase64()) {
+
+ ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
+ SkullMeta headMeta = (SkullMeta) head.getItemMeta();
+ GameProfile profile = new GameProfile(UUID.randomUUID(), "null");
+ profile.getProperties().put("textures", new Property("textures", url));
+ try {
+ Field profileField = headMeta.getClass().getDeclaredField("profile");
+ profileField.setAccessible(true);
+ profileField.set(headMeta, profile);
+
+ } catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException error) {
+ error.printStackTrace();
+ }
+ headMeta.setDisplayName(name);
+ head.setItemMeta(headMeta);
+
+
+ return head;
+ } else {
+ ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
+ SkullMeta headMeta = (SkullMeta) head.getItemMeta();
+
+ PlayerProfile profile = Bukkit.createPlayerProfile(UUID.randomUUID());
+ PlayerTextures textures = profile.getTextures();
+ try {
+ textures.setSkin(new URL(base64Convert(url)));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ profile.setTextures(textures);
+ headMeta.setOwnerProfile(profile);
+ head.setItemMeta(headMeta);
+ return head;
}
- headMeta.setDisplayName(name);
- head.setItemMeta(headMeta);
-
- return head;
}
public ItemStack getItemStack() {
@@ -66,5 +87,43 @@ public ItemStack getItemStack() {
public String getName() {
return idTag;
}
+
+ private static String base64Convert(String base64Value) {
+ String jsonString = new String(Base64.getDecoder().decode(base64Value));
+ JSONObject obj = new JSONObject(jsonString);
+ String output = obj.getJSONObject("textures").getJSONObject("SKIN").getString("url");
+ if (output.startsWith("http://textures.minecraft.net/texture/")) {
+ return output;
+ } else return "http://textures.minecraft.net/texture/d5d20330da59c207d78352838e91a48ea1e42b45a9893226144b251fe9b9d535";
+ }
+
+ private static boolean isOldBase64() {
+ String nms = Bukkit.getServer().getClass().getPackage().getName();
+ if (nms.contains("1_8")) {
+ return true;
+ } else if (nms.contains("1_9")) {
+ return true;
+ } else if (nms.contains("1_10")) {
+ return true;
+ } else if (nms.contains("1_11")) {
+ return true;
+ } else if (nms.contains("1_12")) {
+ return true;
+ } else if (nms.contains("1_13")) {
+ return true;
+ } else if (nms.contains("1_14")) {
+ return true;
+ } else if (nms.contains("1_15")) {
+ return true;
+ } else if (nms.contains("1_16")) {
+ return true;
+ } else if (nms.contains("1_17")) {
+ return true;
+ } else if (nms.contains("1_18")) {
+ return true;
+ } else if (nms.contains("1_19")) {
+ return true;
+ } else return nms.contains("1_20_R1");
+ }
}