Solved How to get the player from an itemstack

Discussion in 'Plugin Development' started by bowlerguy66, Nov 7, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    bowlerguy66

    Ok, so the Item is in the player's inventory. But I want to find the player object from the itemstack in a separate loop. How would I do this?
     
  2. Offline

    Scimiguy

    Store the reference to the player somewhere else
     
  3. Offline

    bowlerguy66

    Alright. I already figured out a way to do this anyways, for future reference heres this method:
    Code:
        public Player getOwner(ItemStack i) {
            for(Player p : Bukkit.getWorld("guncraft").getPlayers()) {
               
                Inventory inv = p.getInventory();
               
                for(int a = 0; a <= p.getInventory().getSize(); a++) {
                   
                    ItemStack b = inv.getItem(a);
                   
                    if(b.equals(i)) {
                        return p;
                    } else {
                        continue;
                    }
                   
                }
               
                continue;
               
            }
           
            return null;
           
        }
    
     
Thread Status:
Not open for further replies.

Share This Page