diff --git a/pom.xml b/pom.xml index 9d98f8f..fff89d4 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ org.spigotmc - spigot-api + spigot 1.14-R0.1-SNAPSHOT provided diff --git a/src/main/java/net/seanomik/energeticstorage/Skulls.java b/src/main/java/net/seanomik/energeticstorage/Skulls.java index 22783b0..c47b797 100644 --- a/src/main/java/net/seanomik/energeticstorage/Skulls.java +++ b/src/main/java/net/seanomik/energeticstorage/Skulls.java @@ -1,11 +1,19 @@ package net.seanomik.energeticstorage; import de.tr7zw.changeme.nbtapi.NBTCompound; +import de.tr7zw.changeme.nbtapi.NBTGameProfile; import de.tr7zw.changeme.nbtapi.NBTItem; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import org.bukkit.inventory.meta.SkullMeta; + +import java.lang.reflect.Field; +import java.util.UUID; + public enum Skulls { LeftGreenArrow("LeftGreenArrow", 0, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZTRjNDE3NDZhZjU1N2EyNGJlOGEwOTAzNjlhNTkxYWU2M2Q1Y2U5YzRiZjQwNWQzNTQyNDdkODEwYzdjNyJ9fX0=", "5da5509d-136d-4716-bc2d-d04f82058e91"), @@ -21,26 +29,25 @@ public enum Skulls { this.texture = texture; this.name = name; this.uuid = uuid; - item = createSkull(uuid, name); + item = createSkull(); } - private ItemStack createSkull (String url, String name) { + private ItemStack createSkull() { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3); - if (url.isEmpty()) return head; + SkullMeta meta = (SkullMeta) head.getItemMeta(); + GameProfile profile = new GameProfile(UUID.randomUUID(), null); - NBTItem headNBT = new NBTItem(head); - String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + profile.getProperties().put("textures", new Property("textures", texture)); - NBTCompound ownerNBT; - if (version.startsWith("v1_16")) { - ownerNBT = headNBT.addCompound("SkullOwner"); - } else { - ownerNBT = headNBT.addCompound("Owner"); + try { + Field profileField = meta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + profileField.set(meta, profile); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); } - ownerNBT.addCompound("Properties").getCompoundList("textures").addCompound().setString("Value", texture); - ownerNBT.setString("Id", uuid); - head = headNBT.getItem(); + head.setItemMeta(meta); return head; } diff --git a/src/main/java/net/seanomik/energeticstorage/utils/ItemConstructor.java b/src/main/java/net/seanomik/energeticstorage/utils/ItemConstructor.java index aeed970..010170b 100644 --- a/src/main/java/net/seanomik/energeticstorage/utils/ItemConstructor.java +++ b/src/main/java/net/seanomik/energeticstorage/utils/ItemConstructor.java @@ -15,7 +15,7 @@ import java.util.UUID; public class ItemConstructor { - private static Material DRIVE_MATERIAL = Material.BLUE_DYE; + private static final Material DRIVE_MATERIAL = Material.BLUE_DYE; public static ItemStack createSystemBlock() { ItemStack systemBlock = Skulls.Computer.getItemStack(); diff --git a/src/main/java/net/seanomik/energeticstorage/utils/Utils.java b/src/main/java/net/seanomik/energeticstorage/utils/Utils.java index 61d465c..7477e10 100644 --- a/src/main/java/net/seanomik/energeticstorage/utils/Utils.java +++ b/src/main/java/net/seanomik/energeticstorage/utils/Utils.java @@ -1,6 +1,7 @@ package net.seanomik.energeticstorage.utils; import de.tr7zw.changeme.nbtapi.NBTCompound; +import de.tr7zw.changeme.nbtapi.NBTListCompound; import org.jetbrains.annotations.Nullable; import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NBTTileEntity; @@ -141,7 +142,18 @@ public static boolean isBlockASystem(Block block) { ownerNBT = blockNBT.getCompound("Owner"); } - return ownerNBT.getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture()); + if (ownerNBT != null && ownerNBT.getCompound("Properties") != null) { + + //return ownerNBT.getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture()); + for (NBTListCompound list : ownerNBT.getCompound("Properties").getCompoundList("textures")) { + if (list.getString("Value").equals(Skulls.Computer.getTexture())) { + return true; + } + } + return false; + } + + return false; } public static boolean isItemADrive(ItemStack item) {