How to stop skulls from stacking

Discussion in 'Plugin Development' started by jrobi230, Jan 1, 2014.

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

    jrobi230

    Hello everyone, i have a plugin where a player uses a command to open a gui then they can click on skulls which will show skulls for every player on the server. But i have two problems, 1. When i open the skulls inventory then close it again it stacks the skulls which i don't want. 2. When there is more than 3 people online the first 2 people skulls work fine but the third and any ones after that just say Head.
    Please Help!

    Code:java
    1. if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Skulls")) {
    2. Player player = (Player) e.getWhoClicked();
    3. e.setCancelled(true);
    4. player.closeInventory();
    5. player.openInventory(sinv);
    6. for (Player p : Bukkit.getOnlinePlayers()) {
    7. ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    8. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    9. meta.setOwner(ChatColor.GOLD + p.getName());
    10. skull.setItemMeta(meta);
    11. sinv.addItem(skull);


    Can anyone help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  2. Offline

    Deleted user

    jrobi230
    Convert it back to an itemstack, then I think you can do .setMaxStackSize(int);
     
  3. Offline

    jrobi230

    @JHGO
    it is saying "The method setMaxStackSize(int) is undefined for the type ItemStack"
     
  4. Offline

    Deleted user

    jrobi230
    Sorry bro, not looking at the api now...I know there IS something for stacksize

    And its a zero not an o in JHG0
     
  5. Offline

    MTN

    Quite sure that is not bukkit, but net.minecraft.server (nms) or craftbukkit code ! It's not that trivial, if you want to avoid nms/craftbukkit code, which you should...
     
  6. Offline

    Bart

    Unfortunately there is a getMaxStackSize but not a setMaxStackSize. I could have sworn there was one though..
     
  7. Offline

    jrobi230

    JHG0 sorry about the name :). Do you know of any alternative methods because every time it open and then i close it it stacks when i open it again and its getting really annoying
     
  8. Offline

    Deleted user

  9. Offline

    MTN

    Believe me, I tried it.
    https://forums.bukkit.org/threads/creating-an-unstackable-item.159534/
    https://forums.bukkit.org/threads/make-something-unstackable.102589/
    https://forums.bukkit.org/threads/make-items-glitchy-and-unstackable.99321/

    What exists is a setMaxStackSize() for inventories, jrobi230 could try that for sinv.
    Also, jrobi, I think your problem would be solved if you don't use sinv.add(skull), but use
    Code:java
    1.  
    2. int currentPlayer= 0;
    3. for (Player p : Bukkit.getOnlinePlayers()) {
    4. (...)
    5. sinv.getInventory().getContents()[currentPlayer] = skull;
    6. currentPlayer++;
    7. }
    8.  

    and maybe rebuild the inventory everytime it gets opened.
     
  10. Offline

    jrobi230

    MTN
    What do you mean by "rebuild" and secondly when i use
    Code:
    sinv.getInventory()
    it gives me an error so i did what eclipse said to do and changed it to
    Code:
    ((HumanEntity) sinv).getInventory() etc.
     
  11. Offline

    jusjus112

    jrobi230
    You can do:
    Code:java
    1. sinv.contains(skull);
    2. sinv.addItem(skull);
     
  12. Offline

    jrobi230

  13. Offline

    jusjus112

    jrobi230
    Use an inventory event?
    Code:java
    1. @EventHandler
    2. public void onItemStack(InventoryPickupItemEvent e) {
    3. if (e.getInventory().contains(skull)) {
    4. e.setCancelled(true);
    5. }
    6. }
     
  14. Offline

    jrobi230

    jusjus112
    im not picking up any skulls when i open and close the inventory then open it gain without taking the skull out it stacks
     
  15. Offline

    jrobi230

    Does Anyone Know The Answer To this??
     
  16. Offline

    MTN

    Everytime it gets opened, you create a new Menu for the player:
    Code:java
    1. player.openInventory(new YourCustomMenu());

    Please share the class that sinv is from. I think it might be sinv.getContents()... directly.
     
Thread Status:
Not open for further replies.

Share This Page