Skip to content

Commit

Permalink
Now actually update for 1.16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanOMik committed Apr 4, 2021
1 parent e2f530a commit f6c1426
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<artifactId>spigot</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Expand Down
33 changes: 20 additions & 13 deletions src/main/java/net/seanomik/energeticstorage/Skulls.java
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/net/seanomik/energeticstorage/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f6c1426

Please sign in to comment.