public static ItemStack getSkull(String url) { ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); if (url.isEmpty()) return head; SkullMeta headMeta = (SkullMeta) head.getItemMeta(); GameProfile profile = new GameProfile(UUID.randomUUID(), null); byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes()); profile.getProperties().put("textures", new Property("textures", new String(encodedData))); Field profileField = null; try { profileField = headMeta.getClass().getDeclaredField("profile"); profileField.setAccessible(true); profileField.set(headMeta, profile); } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } head.setItemMeta(headMeta); return head; }
public static void setItemStackSkin(ItemStack itemStack, String skin) { final ItemMeta meta = itemStack.getItemMeta(); if (!(meta instanceof SkullMeta)) { return; } String newSkin = skin; if (newSkin.contains("textures.minecraft.net")) { if (!newSkin.startsWith("http://")) { newSkin = "http://" + newSkin; } try { final Class<?> cls = createClass("org.bukkit.craftbukkit.VERSION.inventory.CraftMetaSkull"); final Object real = cls.cast(meta); final Field field = real.getClass().getDeclaredField("profile"); field.setAccessible(true); field.set(real, getNonPlayerProfile(newSkin)); itemStack.setItemMeta(SkullMeta.class.cast(real)); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException | ClassNotFoundException e) { Bukkit.getLogger().log(Level.WARNING, "Failed to set url of itemstack.", e); } } else { ((SkullMeta) meta).setOwner(skin); itemStack.setItemMeta(meta); } }
public static ItemStack createHeadPlayer(String displayname, String username, List<String> lore) { ItemStack playerHead = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta sm = (SkullMeta)playerHead.getItemMeta(); sm.setOwner(username); ArrayList<String> colorLore = new ArrayList<>(); if (lore != null) { lore.forEach(str -> colorLore.add(Utils.colorize(str))); sm.setLore(colorLore); } sm.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_UNBREAKABLE); sm.setDisplayName(Utils.colorize(displayname)); playerHead.setItemMeta(sm); return playerHead; }
private ItemStack createPlayerHead(Player player) { AbstractPlayerData playerData = SamaGamesAPI.get().getPlayerManager().getPlayerData(player.getUniqueId()); ItemStack stack = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal()); SkullMeta meta = (SkullMeta) stack.getItemMeta(); meta.setOwner(player.getName()); meta.setDisplayName(PlayerUtils.getFullyFormattedPlayerName(player)); List<String> lore = new ArrayList<>(); lore.add(ChatColor.GRAY + "Pièces : " + ChatColor.GOLD + NumberUtils.format(playerData.getCoins())); lore.add(ChatColor.GRAY + "Perles : " + ChatColor.GREEN + NumberUtils.format(this.hub.getInteractionManager().getGraouManager().getPlayerPearls(player.getUniqueId()).size())); lore.add(ChatColor.GRAY + "Poussière d'" + ChatColor.AQUA + "\u272F" + ChatColor.GRAY + " : " + ChatColor.AQUA + NumberUtils.format(playerData.getPowders())); meta.setLore(lore); stack.setItemMeta(meta); return stack; }
public static ItemStack createSkullItemStack(String uuid, String textureValue, String textureSignature) { WrappedGameProfile wrappedProfile = new WrappedGameProfile(UUID.fromString(uuid), null); wrappedProfile.getProperties().put("textures", new WrappedSignedProperty("textures", textureValue, textureSignature)); ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal()); SkullMeta sm = (SkullMeta) skull.getItemMeta(); Field profileField = null; try { profileField = sm.getClass().getDeclaredField("profile"); profileField.setAccessible(true); profileField.set(sm, wrappedProfile.getHandle()); } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) { e1.printStackTrace(); } skull.setItemMeta(sm); return skull; }
public static BaseComponent getNameComponent(ItemStack item) { if (item == null) throw new IllegalArgumentException(); if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) return new TextComponent(item.getItemMeta().getDisplayName()); Material type = item.getType(); if (type == Material.SKULL_ITEM && item.getDurability() == 3) { SkullMeta meta = (SkullMeta) item.getItemMeta(); if (meta.hasOwner()) { return new TranslatableComponent("item.skull.player.name", meta.getOwner()); } else { return new TranslatableComponent("item.skull.char.name"); } } else { return new TranslatableComponent(getUnlocalizedName(item)); } }
public static ItemStack activateHeadByURL(String skinUrl, ItemStack itemStack) { if (itemStack.getType() == Material.SKULL_ITEM) { SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); try { final Class<?> cls = ReflectionLib.getClassFromName("org.bukkit.craftbukkit.VERSION.inventory.CraftMetaSkull"); final Object real = cls.cast(meta); final Field field = real.getClass().getDeclaredField("profile"); field.setAccessible(true); field.set(real, getNonPlayerProfile(skinUrl)); meta = SkullMeta.class.cast(real); itemStack.setItemMeta(meta); itemStack = new ItemStackBuilder(itemStack).setDisplayName("TMP"); } catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { Bukkit.getLogger().log(Level.WARNING, "Failed to set url of itemstack.", e); } } return itemStack; }
/** * Drop player head on kill * * @param event Event */ @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta skullMeta = (SkullMeta)head.getItemMeta(); skullMeta.setOwner(event.getEntity().getName()); skullMeta.setDisplayName(ChatColor.AQUA + "Tête de " + event.getEntity().getName()); head.setItemMeta(skullMeta); event.getDrops().add(head); List<PotionEffect> effectList = new ArrayList<>(); effectList.addAll(event.getEntity().getActivePotionEffects()); this.effects.put(event.getEntity().getName(), effectList); }
/** * Give old player enchants on head eating * * @param event Event */ @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { if (event.getItem() == null || event.getItem().getType() != Material.SKULL_ITEM || event.getItem().getDurability() != 3 || (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) return; SkullMeta skullMeta = (SkullMeta)event.getItem().getItemMeta(); List<PotionEffect> effectList = this.effects.get(skullMeta.getOwner()); if (effectList != null) { effectList.forEach(event.getPlayer()::addPotionEffect); this.effects.remove(skullMeta.getOwner()); event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.BURP, 1F, 1F); } }
@Subcommand("gui") @CommandPermission("%admin") public void gui(@Nonnull User sender) { if (editMode.contains(sender.getUuid())) { PagedInventory inventory = inventoryHandler.createInventory(PagedInventory.class, sender, Lang.legacy(LangKey.INV_MARKER), 9); Map<ItemStack, BiConsumer<ItemStack, User>> content = new HashMap<>(); mapHandler.getMarkerDefinitions().forEach(markerDefinition -> { ItemStack is = new ItemBuilder(Material.SKULL_ITEM).durability(3).name(markerDefinition.getPrefix()) .meta((itemMeta -> ((SkullMeta) itemMeta).setOwner(markerDefinition.getPrefix()))).build(); content.put(is, (item, user) -> user.getPlayer().performCommand("editmode skull " + is.getItemMeta().getDisplayName())); }); inventory.autoConstructPages(content.keySet().toArray(new ItemStack[content.size()])); content.forEach(inventory::addClickAction); inventory.open(); } else { Lang.msg(sender, LangKey.EDITMODE_NOT_ENABLED); } }
public static SkullMeta applyTextureToMeta(Object meta, Object profile) throws Exception { if (meta == null) { throw new IllegalArgumentException("meta cannot be null"); } if (profile == null) { throw new IllegalArgumentException("profile cannot be null"); } Object baseNBTTag = NBTTagCompound.newInstance(); Object ownerNBTTag = NBTTagCompound.newInstance(); GameProfileSerializerMethodResolver.resolve(new ResolverQuery("serialize", NBTTagCompound, GameProfile)).invoke(null, ownerNBTTag, profile); NBTTagCompoundMethodResolver.resolve(new ResolverQuery("set", String.class, NBTBase)).invoke(baseNBTTag, "SkullOwner", ownerNBTTag); SkullMeta newMeta = (SkullMeta) CraftMetaSkullConstructorResolver.resolve(new Class[]{NBTTagCompound}).newInstance(baseNBTTag); Field profileField = CraftMetaSkullFieldResolver.resolve("profile"); profileField.set(meta, profile); profileField.set(newMeta, profile); return newMeta; }
public static ItemStack createHeadPlayer(String displayname, String username, List<String> lore) { ItemStack playerHead = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta sm = (SkullMeta) playerHead.getItemMeta(); sm.setOwner(username); ArrayList<String> colorLore = new ArrayList<>(); if (lore != null) { lore.forEach(str -> colorLore.add(Utils.colorize(str))); sm.setLore(colorLore); } sm.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_DESTROYS, ItemFlag.HIDE_ENCHANTS, ItemFlag.HIDE_PLACED_ON, ItemFlag.HIDE_UNBREAKABLE); sm.setDisplayName(Utils.colorize(displayname)); playerHead.setItemMeta(sm); return playerHead; }
public static ItemStack getSkullFromURL(String url, String name) throws Exception { ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta sm = (SkullMeta) skull.getItemMeta(); sm.setOwner("NacOJerk"); skull.setItemMeta(sm); url = Base64Coder.encodeString("{textures:{SKIN:{url:\"" + url + "\"}}}"); GameProfile gp = new GameProfile(UUID.randomUUID(), name); gp.getProperties().put("textures", new Property("textures", url)); Object isskull = asNMSCopy(skull); Object nbt = getNMS("NBTTagCompound").getConstructor().newInstance(); Method serialize = getNMS("GameProfileSerializer").getMethod( "serialize", getNMS("NBTTagCompound"), GameProfile.class); serialize.invoke(null, nbt, gp); Object nbtr = isskull.getClass().getMethod("getTag").invoke(isskull); nbtr.getClass().getMethod("set", String.class, getNMS("NBTBase")) .invoke(nbtr, "SkullOwner", nbt); isskull.getClass().getMethod("setTag", getNMS("NBTTagCompound")) .invoke(isskull, nbtr); skull = asBukkitCopy(isskull); return skull; }
@Override public SkullMeta setSkullTexture(SkullMeta meta, String skinUrl) { if (meta == null) { return meta; } GameProfile profile = new GameProfile(UUID.randomUUID(), null); profile.getProperties().put("textures", new Property("textures", new String(Utils.getSkullTexture(skinUrl)))); try { Field profileField = meta.getClass().getDeclaredField("profile"); profileField.setAccessible(true); profileField.set(meta, profile); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } return meta; }
public static List<Inventory> createMemberMenu(Clans clan){ Clan clanProfile = new Clan(clan); List<Inventory> pages = new ArrayList<Inventory>(); int page = 1; pages.add(Bukkit.createInventory(null, 54, "Page "+page)); List<ca.damocles.accountsystem.Character> clansmen = clanProfile.getClansmen(); for(ca.damocles.accountsystem.Character members : clansmen){ ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)SkullType.PLAYER.ordinal()); SkullMeta meta = (SkullMeta) skull.getItemMeta(); meta.setOwningPlayer(Bukkit.getOfflinePlayer(members.uuid)); skull.setItemMeta(meta); if(pages.get(pages.size()-1).firstEmpty() == -1){ page = page+1; pages.add(Bukkit.createInventory(null, 54, "Page "+page)); pages.get(pages.size()-1).addItem(skull); }else{ pages.get(pages.size()-1).addItem(skull); } members.getPlayer().updateInventory(); } return pages; }
public static SkullMeta applyTextureToMeta(SkullMeta meta, Object profile) throws Exception { if (meta == null) { throw new IllegalArgumentException("meta cannot be null"); } if (profile == null) { throw new IllegalArgumentException("profile cannot be null"); } Object baseNBTTag = NBTTagCompound.newInstance(); Object ownerNBTTag = NBTTagCompound.newInstance(); GameProfileSerializerMethodResolver.resolve(new ResolverQuery("serialize", NBTTagCompound, GameProfile)).invoke(null, ownerNBTTag, profile); NBTTagCompoundMethodResolver.resolve(new ResolverQuery("set", String.class, NBTBase)).invoke(baseNBTTag, "SkullOwner", ownerNBTTag); SkullMeta newMeta = (SkullMeta) CraftMetaSkullConstructorResolver.resolve(new Class[] { NBTTagCompound }).newInstance(baseNBTTag); Field profileField = CraftMetaSkullFieldResolver.resolve("profile"); profileField.set(meta, profile); profileField.set(newMeta, profile); return newMeta; }
public SpectatorMenu(final Minigame minigame, String[] alive, String title, ItemStack backItem, ItemStack nextItem) { super(minigame, title, backItem, nextItem, new EventListener<InventoryClickEvent>() { public void onEvent(InventoryClickEvent event) { ItemStack item = event.getCurrentItem(); if (item != null && item.getType() == Material.SKULL_ITEM) { HumanEntity human = event.getWhoClicked(); // only works for spectators if (!(human instanceof Player) || minigame.isAlive(((Player) human))) return; SkullMeta meta = (SkullMeta) item.getItemMeta(); Player target = Bukkit.getPlayer(meta.getOwner()); human.teleport(target); } }; }, getHeadsForPlayers(alive)); }
private void spawnTracker() { Player p = (Player) getTarget(); ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta sm = (SkullMeta) skull.getItemMeta(); sm.setOwner(playerWithTrackerHead); skull.setItemMeta(sm); World w = p.getWorld(); armorStand = w.spawnEntity(p.getLocation(), EntityType.ARMOR_STAND); /*slime = w.spawnEntity(p.getLocation(), EntityType.SLIME); ((Slime) slime).setInvulnerable(true); ((Slime) slime).setAI(false); ((Slime) slime).setSize(2); slime.setPassenger(armorStand);*/ p.setPassenger(armorStand); ((ArmorStand) armorStand).setHelmet(skull); ((ArmorStand) armorStand).setVisible(false); ((ArmorStand) armorStand).setSmall(true); ((ArmorStand) armorStand).setBodyPose(new EulerAngle(0.0, 3.57, 0.0)); }
public static ItemMeta parse(Element xml, ItemMeta source) { if (source instanceof BannerMeta) { return parseBanner(xml, (BannerMeta) source); } else if (source instanceof BookMeta) { return parseBook(xml, (BookMeta) source); } else if (source instanceof EnchantmentStorageMeta) { return parseEnchantmentStorage(xml, (EnchantmentStorageMeta) source); } else if (source instanceof FireworkMeta) { return parseFirework(xml, (FireworkMeta) source); } else if (source instanceof FireworkEffectMeta) { return parseFireworkEffect(xml, (FireworkEffectMeta) source); } else if (source instanceof LeatherArmorMeta) { return parseLeatherArmor(xml, (LeatherArmorMeta) source); } else if (source instanceof MapMeta) { return parseMap(xml, (MapMeta) source); } else if (source instanceof PotionMeta) { return parsePotion(xml, (PotionMeta) source); } else if (source instanceof SkullMeta) { return parseSkull(xml, (SkullMeta) source); } else if (source instanceof SpawnEggMeta) { return parseSpawnEgg(xml, (SpawnEggMeta) source); } return source; }
/** * Returns the ItemStack at the specified Path * * @param path The path in the Config File * @return The ItemStack at that Path */ public ItemStack getItem(String path) { ItemStack item = config.getItemStack(path); if (item == null) return null; try { if (item.hasItemMeta() && item.getItemMeta() instanceof SkullMeta) { if (config.contains(path + "_extra.custom-skull")) item = CustomSkull.getItem((ItemStack) item, config.getString(path + "_extra.custom-skull")); if (config.contains(path + "_extra.custom-skullOwner") && !((ItemStack) item).getItemMeta().hasDisplayName()) { ItemMeta im = ((ItemStack) item).getItemMeta(); im.setDisplayName("�r" + config.getString(path + "_extra.custom-skullOwner") + "'s Head"); ((ItemStack) item).setItemMeta(im); } } else { config.set(path + "_extra.custom-skull", null); config.set(path + "_extra.custom-skullOwner", null); } } catch (Exception e) { e.printStackTrace(); } return item; }
public static void setInventory(Player p){ p.getInventory().clear(); ItemStack skull = ItemUtils.createItemstack(Material.SKULL_ITEM, 1, (byte)3, "&aJouw Profiel &3(Rechter Klik)", "&7&oTODO"); //TODO: MAKE LORE SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); skullMeta.setOwner(p.getName()); skull.setItemMeta(skullMeta); ItemUtils.createInventoryDisplay(p, skull, 1); ItemUtils.createInventoryDisplay(p, Material.MINECART, 1, (byte)0, "&aAttracties &3(Rechter Klik)", "&7&oTODO", 2); //TODO: MAKE LORE if(p.hasPermission("pretparkcore.controlrides")) { ItemUtils.createInventoryDisplay(p, Material.COMMAND_MINECART, 1, (byte) 0, "&aAttractie Besturing &3(Rechter Klik)", "&7&oTODO", 3); //TODO: MAKE LORE } ItemUtils.createInventoryDisplay(p, Material.CHEST, 1, (byte) 0, "&aSwag Menu &3(Rechter Klik)", "&7Upgrade je swag naar &lOVER 9000!", 9); //TODO: MAKE LORE p.getInventory().setHelmet(new ItemStack(Vars.helmet.get(p.getName()))); p.getInventory().setChestplate(new ItemStack(Vars.chest.get(p.getName()))); p.getInventory().setLeggings(new ItemStack(Vars.legs.get(p.getName()))); p.getInventory().setBoots(new ItemStack(Vars.boots.get(p.getName()))); }
/** * Gets the skull for this player UUID * @param playerUUID * @return Player skull item */ private ItemStack getSkull(UUID playerUUID) { String playerName = plugin.getPlayers().getName(playerUUID); if (DEBUG) plugin.getLogger().info("DEBUG: name of warp = " + playerName); ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); if (playerName == null) { if (DEBUG) plugin.getLogger().warning("Warp for Player: UUID " + playerUUID.toString() + " is unknown on this server, skipping..."); return null; //playerName = playerUUID.toString().substring(0, 10); } SkullMeta meta = (SkullMeta) playerSkull.getItemMeta(); meta.setOwner(playerName); meta.setDisplayName(ChatColor.WHITE + playerName); playerSkull.setItemMeta(meta); return playerSkull; }
public boolean commandUse(CommandSender sender, String[] args) { Variables var = Necessities.getVar(); if (args.length == 0) { sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You must enter a player to get their head."); return true; } if (sender instanceof Player) { Player p = (Player) sender; ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3); SkullMeta meta = (SkullMeta) skull.getItemMeta(); meta.setOwner(args[0]); skull.setItemMeta(meta); p.getInventory().addItem(skull); p.sendMessage(var.getMessages() + "You have been given 1 head of " + var.getObj() + args[0]); } else sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You do not have an inventory."); return true; }
@SuppressWarnings("deprecation") public void onPlayerInteract(final PlayerInteractEvent event) { final Player player = event.getPlayer(); if (player.hasPermission("customplugin.voodoo")) { ItemStack i = player.getItemInHand(); if (i.getTypeId() == 397 && i.getDurability() == (byte) 3) { SkullMeta skull = (SkullMeta)i.getItemMeta(); Player p = Bukkit.getPlayer(skull.getOwner()); if (p != null) { if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { p.setVelocity(player.getLocation().getDirection().multiply(-1)); } else { p.setVelocity(player.getLocation().getDirection()); } } } } }
public void voteNo(Player player) { removePlayer(player); ItemStack head = new ItemStack(Material.SKULL_ITEM); head.setDurability((short)3); SkullMeta skull = (SkullMeta) head.getItemMeta(); skull.setOwner(player.getName()); head.setItemMeta(skull); ItemMeta im = head.getItemMeta(); im.setDisplayName(ChatColor.DARK_RED + player.getName()); ArrayList<String> lore = new ArrayList<String>(); lore.add("Voting NO"); im.setLore(lore); head.setItemMeta(im); getChest().setItem(getNextNoSlot(), head); player.openInventory(getChest()); }
public void voteYes(Player player) { removePlayer(player); ItemStack head = new ItemStack(Material.SKULL_ITEM); head.setDurability((short)3); SkullMeta skull = (SkullMeta) head.getItemMeta(); skull.setOwner(player.getName()); head.setItemMeta(skull); ItemMeta im = head.getItemMeta(); im.setDisplayName(ChatColor.GREEN + player.getName()); ArrayList<String> lore = new ArrayList<String>(); lore.add("Voting YES"); im.setLore(lore); head.setItemMeta(im); getChest().setItem(getNextYesSlot(), head); player.openInventory(getChest()); }
public void onPlayerJoinEvent(PlayerJoinEvent event) { if (event.getPlayer().hasPermission("customplugin.staffvote")) { for (ItemStack item : getChest().getContents()) { if (item != null && item.getType().equals(Material.SKULL_ITEM)) { SkullMeta skull = (SkullMeta) item.getItemMeta(); if (skull.getOwner().equals(event.getPlayer().getName())) return; } } event.getPlayer().sendMessage(ChatColor.BLUE + "STAFFVOTE: " + ChatColor.RED + "You have yet to vote!"); Sign sign = (Sign) Bukkit.getWorld("Survival").getBlockAt(60, 71, 171).getState(); Sign sign2 = (Sign) Bukkit.getWorld("Survival").getBlockAt(60, 71, 170).getState(); String title = sign.getLine(1) + " " + sign.getLine(2) + " " + sign.getLine(3) + " " + sign2.getLine(1) + " " + sign2.getLine(2) + " " + sign2.getLine(3); event.getPlayer().sendMessage(ChatColor.GREEN + title); } }
public boolean handlePlayer(BytecraftPlayer player, String[] args) { if(!player.getRank().canSpawnHeads()){ player.sendMessage(getInvalidPermsMessage()); return true; } if (args.length == 1) { ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); SkullMeta itemMeta = (SkullMeta) item.getItemMeta(); itemMeta.setOwner(args[0]); itemMeta.setDisplayName(ChatColor.YELLOW + args[0] + "'s head"); item.setItemMeta(itemMeta); PlayerInventory inventory = player.getInventory(); inventory.addItem(item); player.sendMessage(ChatColor.YELLOW + "You received the head of " + args[0]); } else { player.sendMessage(ChatColor.RED + "Type /head <player>"); } return true; }
@Override public boolean handlePlayer(TregminePlayer player, String args[]) { if (player.getRank().canGetPlayerHead()){ if (args.length == 1) { ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); SkullMeta itemMeta = (SkullMeta) item.getItemMeta(); itemMeta.setOwner(args[0]); itemMeta.setDisplayName(ChatColor.YELLOW + args[0] + "'s head"); item.setItemMeta(itemMeta); PlayerInventory inventory = player.getInventory(); inventory.addItem(item); player.sendMessage(ChatColor.YELLOW + "You received the head of " + args[0]); } else { player.sendMessage(ChatColor.RED + "Type /head <player>"); } } else { player.sendMessage(ChatColor.RED + "Only admins can use this command!"); } return true; }
/** * Gets a String representing all special meta of this ItemStack, if any. * * @param is the ItemStack * @param separators the separators * * @return a String representing this ItemStack's special meta or an empty String * * @throws InventoryUtilException if something goes wrong */ public static String getSpecialMetaString(final ItemStack is, final String[] separators) throws InventoryUtilException { final ItemMeta meta = is.getItemMeta(); if (meta instanceof BookMeta) { return getBookMetaString((BookMeta)meta); } else if (meta instanceof EnchantmentStorageMeta) { return getEnchantmentStorageMetaString((EnchantmentStorageMeta)meta, separators); } else if (meta instanceof FireworkEffectMeta) { return getFireworkEffectMetaString((FireworkEffectMeta)meta); } else if (meta instanceof FireworkMeta) { return getFireworkMetaString((FireworkMeta)meta, separators); } else if (meta instanceof LeatherArmorMeta) { return getLeatherArmorMetaString((LeatherArmorMeta)meta); } else if (meta instanceof MapMeta) { return getMapMetaString((MapMeta)meta); } else if (meta instanceof PotionMeta) { return getPotionMetaString((PotionMeta)meta, separators); } else if (meta instanceof SkullMeta) { return getSkullMetaString((SkullMeta)meta); } else { throw new InventoryUtilException("Unknown Meta type '" + meta.getClass().getName() + "', please report this to the author (Ribesg)!"); } }
private void turnSkelToNpc(Skeleton skel, String player) { ItemStack head = new ItemStack(Material.SKULL_ITEM); head.setDurability((short)3); SkullMeta meta = (SkullMeta) head.getItemMeta(); meta.setOwner(player); head.setItemMeta(meta); head.setAmount(1); skel.getEquipment().setHelmet(head); skel.getEquipment().setHelmetDropChance(0); ItemStack chestplate = new ItemStack(Material.IRON_CHESTPLATE); chestplate.setAmount(1); skel.getEquipment().setChestplate(chestplate); skel.getEquipment().setChestplateDropChance(0); ItemStack leggings = new ItemStack(Material.IRON_LEGGINGS); leggings.setAmount(1); skel.getEquipment().setLeggings(leggings); skel.getEquipment().setLeggingsDropChance(0); ItemStack shoes = new ItemStack(Material.IRON_BOOTS); skel.getEquipment().setBoots(shoes); skel.getEquipment().setBootsDropChance(0); skel.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 30)); skel.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 30)); skel.setCustomName(player); skel.setCustomNameVisible(true); }
@EventHandler public void signRightClickhead(PlayerInteractEvent s) { if(s.getAction() == Action.RIGHT_CLICK_BLOCK) { if(s.getClickedBlock().getState().getType() == Material.SIGN || s.getClickedBlock().getState().getType() == Material.SIGN_POST || s.getClickedBlock().getState().getType() == Material.WALL_SIGN) { //log.info("This is a sign..."); Sign sign = (Sign) s.getClickedBlock().getState(); if(sign.getLine(0).contains("[GetYourHead]")) { //log.info("Launching dispatch command...."); ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short)3); SkullMeta skullmeta = (SkullMeta)skull.getItemMeta(); skullmeta.setOwner(s.getPlayer().getName()); skull.setItemMeta(skullmeta); skull.setAmount(1); if(s.getPlayer().getItemInHand().getType() == Material.AIR) { s.getPlayer().getInventory().setItemInHand(skull); sendMessage(s.getPlayer(), ChatColor.GOLD + "[GetYourHead] " + ChatColor.GREEN + "your head has been added in your hand!"); } else { sendMessage(s.getPlayer(), ChatColor.GOLD + "[GetYourHead] " + ChatColor.RED + "your hands need to be empty!"); } s.setCancelled(true); } } } }
@Override public void onDeath(ZvPPlayer player, PlayerDeathEvent event) { super.onDeath(player, event); this.playerDrops.put(player, new ArrayList<ItemStack>(event.getDrops())); event.getDrops().clear(); Entity entitiy = getArena().getWorld().spawnEntity(player.getLocation(), EntityType.ZOMBIE); if (entitiy != null) { getArena().getDifficultyTool().customizeEntity(entitiy); } ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM); playerSkull.setDurability((short) 3); SkullMeta meta = (SkullMeta) playerSkull.getItemMeta(); meta.setOwner(player.getName()); playerSkull.setItemMeta(meta); Zombie z = (Zombie) entitiy; z.setBaby(false); z.getEquipment().setHelmet(playerSkull); z.setMaxHealth(2 * 20); getArena().updatePlayerBoards(); }
@Override public void onZombieKill(ZvPPlayer attacker, Entity zombie, EntityDeathEvent event) { super.onZombieKill(attacker, zombie, event); Zombie z = (Zombie) zombie; if (z.getEquipment().getHelmet().getType() == Material.SKULL_ITEM) { if (z.getEquipment().getHelmet().hasItemMeta() && z.getEquipment().getHelmet().getItemMeta() instanceof SkullMeta) { SkullMeta meta = (SkullMeta) z.getEquipment().getHelmet().getItemMeta(); if (meta.hasOwner()) { ZvPPlayer player = GameManager.getManager().getPlayer(meta.getOwner()); if (player != null) { if (this.playerDrops.containsKey(player)) { event.getDrops().clear(); event.getDrops().addAll(this.playerDrops.get(player)); this.playerDrops.remove(player); } } } } } }
public static boolean isCustomHeadItem(ItemStack item) { if (item == null) return false; if (item.getType() != Material.SKULL_ITEM) { return false; } if (item.getDurability() != SkullType.PLAYER.ordinal()) { return false; } ItemMeta meta = item.getItemMeta(); if (meta instanceof SkullMeta) { SkullMeta skullMeta = (SkullMeta) meta; if (skullMeta.hasOwner() && skullMeta.getOwner() == null) { // custom head items usually don't have a valid owner return true; } } return false; }
public static ItemStack head(String playerName, String displayName, String... lore) { ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3); SkullMeta meta = (SkullMeta) item.getItemMeta(); meta.setOwner(playerName); meta.setDisplayName(displayName); meta.setLore(Arrays.asList(lore)); item.setItemMeta(meta); return item; }
@Override public void processMeta(Player player, ItemMeta m) { super.processMeta(player, m); SkullMeta meta = (SkullMeta) m; if(skullOwner != null) meta.setOwner(skullOwner.resolve(player, getPlaceholders())); }
public static ItemStack getPlayerSkull(String name) { ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal()); SkullMeta meta = (SkullMeta) skull.getItemMeta(); meta.setOwner(name); skull.setItemMeta(meta); return skull; }
private static ItemStack activateHead(String name, ItemStack itemStack) { try { if (itemStack.getItemMeta() instanceof SkullMeta) { final SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); meta.setOwner(name); itemStack.setItemMeta(meta); } } catch (final Exception e) { PetBlocksPlugin.logger().log(Level.WARNING, e.getMessage()); } return itemStack; }