package net.crankedpvp.crankedpets; import de.tr7zw.nbtapi.NBTCompound; import de.tr7zw.nbtapi.NBTItem; import net.crankedpvp.crankedpets.struct.Pet; import net.crankedpvp.crankedpets.struct.PetsRegister; import net.crankedpvp.crankedutils.utils.items.ItemBuilder; import net.crankedpvp.crankedutils.utils.items.ItemUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class CrankedPetsAPI { public static boolean isPet(ItemStack itemStack) { if (!ItemUtils.isSkull(itemStack)) return false; NBTItem nbtItem = new NBTItem(itemStack); if (!nbtItem.hasKey("cosmicType")) return false; return nbtItem.getString("cosmicType").equals("pet"); } public static Pet getPetFromItem(ItemStack itemStack) { NBTItem nbtItem = new NBTItem(itemStack); NBTCompound compound = nbtItem.getCompound("cosmicData"); String petId = compound.getString("petType"); return PetsRegister.getInstance().getPetFromID(petId); } public static boolean hasPetInInventory(Player player, Pet pet) { for (ItemStack item : player.getInventory().getContents()) { if (isPet(item)) { Pet foundPet = getPetFromItem(item); if (foundPet.getID().equals(pet.getID())) { return true; } } } return false; } /* public static boolean isPetOnCooldown(ItemStack item) { Pet pet = getPetFromItem(item); NBTItem nbtItem = new NBTItem(item); NBTCompound compound = nbtItem.getCompound("cosmicData"); long lastUsed = compound.getLong("lastUsed"); return lastUsed+(pet.getCooldownInSeconds()* 1000L) > System.currentTimeMillis(); } public static void enterCooldown(Player player) { NBTItem nbtItem = new NBTItem(player.getItemInHand()); NBTCompound compound = nbtItem.getCompound("cosmicData"); compound.setLong("lastUsed", System.currentTimeMillis()); player.setItemInHand(nbtItem.getItem()); } public static long getTimeLeftMs(ItemStack item) { Pet pet = getPetFromItem(item); NBTItem nbtItem = new NBTItem(item); NBTCompound compound = nbtItem.getCompound("cosmicData"); long lastUsed = compound.getLong("lastUsed"); return lastUsed+(pet.getCooldownInSeconds()* 1000L) - System.currentTimeMillis(); }*/ }