Checking skulls in inventory

Discussion in 'Spigot Plugin Development' started by Digital, Jul 8, 2015.

  1. redacted
     
    #1 Digital, Jul 8, 2015
    Last edited: May 1, 2021
  2. Why check the inventory if you just want to remove the skull use this:

    Code (Text):

                        ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1 ,(short) 3);
                        SkullMeta meta = (SkullMeta) skull.getItemMeta();
                        meta.setOwner("DigitalSniperz");
                        skull.setItemMeta(meta);
                        player.getInventory().removeItem(skull))
     
     
  3. Check if the inventory contains a skull item and get the owner of that skull.
    Code (Text):

    if (plr.getInventory().contains(Material.SKULL_ITEM, 1, (short) 3)
            && plr.getInventory().getItem().getOwner().equals("DigitalSniperz")){
                //Whatever you'r trying to do
     
    Don't copy paste that, that is just kind of an idea of where to go, I don't know what your working with exactly here, event wise or other. You do need to get the owner of the skull though, You may have to play with that a little but once you figure out where to getOwner from, it should all come together. That code above is surely way off, just kind of off the top of my head and I just woke up, but the getOwner part is what you need there. You shouldn't need the item stack if you're looking for a skull that is already in the inventory, just need that owner part. Than you can remove it or whatever you are trying to do with it. The more I look at that the more I think about how horrid it looks, hopefully you get the idea though. If not, I will try to better that solution once I have some coffee.