Solved SkullOwner and InventoryClickEvent issues

Discussion in 'Plugin Development' started by ItsMas_, Jan 22, 2016.

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

    ItsMas_

    Issue 1:
    I am trying to add a skull with a player's skin to an inventory. When I try and do it, it just adds a steve/alex head.
    Code:
    Code:
    //Method:
        private ItemStack addSkull(ItemStack item, String owner){
            SkullMeta meta = (SkullMeta) item.getItemMeta();
            meta.setOwner(owner);
            meta.setDisplayName(ChatColor.YELLOW + owner);
            item.setItemMeta(meta);
           
            return item;
    }
    
    //Adding the item:
    onlineStaff.addItem(addSkull(new ItemStack(Material.SKULL_ITEM, 1, (byte) 3), pl.getName().toString()));
    

    Issue 2:
    I have it set so when a player clicks on a skull in the inventory, it cancels the event and places the skull back.
    It is not working, and I don't know why:
    Code:
    Code:
        public void onInventoryClick(InventoryClickEvent e){
            Inventory inventory = e.getInventory();
            if (inventory == onlineStaff){
                    e.setCancelled(true);
            }
               
        }
    
    Could someone tell me how to fix this? Thanks :)
     
  2. Offline

    Zombie_Striker

    @ItsMas_
    Issue 1: This has been a well documented issue. You must place the head down in order for the skins to work.

    Issue 2:
    '==' compares memory space. What you're thinking of is .equals which compares the values.
     
  3. Offline

    ShowbizLocket61

    @ItsMas_
    I'll address your second issue. What is onlineStaff? Also, "==" checks if they are the same object, which I'm pretty certain they aren't. To check if they have the same properties and such, use the .equals() method.
     
  4. Offline

    ItsMas_

    Okay, I will change it to .equals() and see if it works!

    onlineStaff is an inventory, and when someone types /staff, it clears the inventory, loops through all players, and if they are staff, adds their head to the inventory, then opens the inventory to the player.

    Are you sure the head needs to be placed?
    I am sure I have seen plugins which display the player's head in a menu :/
     
  5. Offline

    Zombie_Striker

    @ItsMas_
    That is because the head has been placed for a tick or so somewhere around the world. When the player loads the skin for that block ,it loads the skin for the item as well.
     
  6. Offline

    ShowbizLocket61

    @ItsMas_
    Yes, in that case you should use .equals(). However, comparing the title is always more convenient.
     
  7. Offline

    ItsMas_

    Okay, thanks :)

    Okay, could you give me a link to some example code to show how to do this?
     
  8. Offline

    Zombie_Striker

    @ShowbizLocket61
    Except if another plugin uses the same title/ he did not input a title.

    @ItsMas_
    Code:
    Set<Strings>  all player's names; // CAN ALSO BE AN ARRAY
    Scheduler.schedulesynchrepeatingtask(JavaPlugin instance, new Runnable(){
    
     int id = 0;
     Material originalblockMaterial;
     short orginalbockData;
     public void run(){
    
     //Get block 2 blocks under player
    
     if(id== 0){
       Material = the materal;
       Data = the block's duribilty/data.
      }
      //set the block to be a skull.
      SkullMeta.setOwner(allplayersnames.get(id));
      id++;
      if(id >= allplayersnames.size /lenth){
       //Set the blocks material to be the original material and data to be original data.
       //cancel the runnable.
       }
     }
    },1,1);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 22, 2016
  9. Offline

    ItsMas_

    Tried it with title and .equals(), still doesn't work :(

    EDIT: I think the problem is that it is not recognising the InventoryClickEvent. I have registered the event, so why else could this not be working?
     
  10. Offline

    Zombie_Striker

    @ItsMas_
    Can you post your full current code (which contains what you tried)? Can you show us what onlinestaff is equal to?
     
  11. Offline

    ItsMas_

    The world's stupidest human award goes to... Me!

    Forgot to use @EventHandler......
     
  12. Offline

    sgavster

    If your problem is solved please mark the thread as solved.
    Also: Try player.updateInventory(); works for me!
     
  13. Offline

    ItsMas_

    What would player.updateInventory(); do? If it's supposed to render the skull skins, it doesn't work.
     
  14. Offline

    ShowbizLocket61

    @ItsMas_ @sgavster @Zombie_Striker
    I was wondering, since updateInventory() was deprecated, does that mean it's unnecessary? Does the player inventory update itself automatically?
     
  15. Offline

    Zombie_Striker

    @ShowbizLocket61
    No, the method is still necessarily in some occasions, and the inventory updates at specific events. The reason is is deprecated (if I remember correctly) was to raise awareness to not use ".setType(Material.AIR)" (since although updating the inventory it would remove the itemstack, it would be updating the whole inventory.)
     
Thread Status:
Not open for further replies.

Share This Page