package net.crankedpvp.spawners.items; import de.tr7zw.nbtapi.NBTCompound; import de.tr7zw.nbtapi.NBTItem; import net.crankedpvp.crankedutils.utils.CC; import net.crankedpvp.crankedutils.utils.EntityUtils; import net.crankedpvp.spawners.SpawnerPlugin; import net.crankedpvp.spawners.utils.ConfigManager; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import java.util.Arrays; import java.util.UUID; public class ItemSpawner { public static ItemStack getItem(EntityType creatureType, int amount) { ItemStack item = new ItemStack(Material.MOB_SPAWNER); ItemMeta meta = item.getItemMeta(); meta.setDisplayName(CC.translate("&c&l" + EntityUtils.getEntityName(creatureType) + " &f&lSpawner &7(" + amount + "x)")); meta.setLore(Arrays.asList( CC.translate("&8Stacked Spawner"), CC.translate(""), CC.translate("&4&lSpawner Info"), CC.translate("&4┇ &cType: &7" + EntityUtils.getEntityName(creatureType)), CC.translate("&4┇ &cAmount: &7" + amount), CC.translate("&4┖") )); item.setItemMeta(meta); NBTItem nbtItem = new NBTItem(item); NBTCompound compound = nbtItem.addCompound("spawnerData"); compound.setString("spawnerType", creatureType.name()); compound.setInteger("amount", amount); compound.setString("uuid", UUID.randomUUID().toString()); return nbtItem.getItem(); } public static EntityType getEntityTypeFromItem(ItemStack item) { if (item == null || item.getType() != Material.MOB_SPAWNER) { return null; } NBTItem wrapper = new NBTItem(item); if (!wrapper.hasKey("spawnerData")) { return null; } NBTCompound compound = wrapper.getCompound("spawnerData"); return EntityType.valueOf(compound.getString("spawnerType")); } public static int getSpawnerAmount(ItemStack item) { if (item == null || item.getType() != Material.MOB_SPAWNER) { return -1; } NBTItem wrapper = new NBTItem(item); if (!wrapper.hasKey("spawnerData")) { return -1; } NBTCompound compound = wrapper.getCompound("spawnerData"); return compound.getInteger("amount"); } public static int getSpawnerLimit() { return SpawnerPlugin.getInstance().getConfigManager().getConfig(ConfigManager.ConfigFile.PRIMARY).getInt("spawners.max-stack-size"); } }