Solved Inventory remove not working? O.o

Discussion in 'Plugin Development' started by ZomBlade_Shadow, May 26, 2015.

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

    ZomBlade_Shadow

    Hey.

    So I have a team plugin, when I do /party list I want to have an inventory with skulls inside (=Skulls are the parties).

    So everything is working quite well, else one little thing.
    When I create my party, and I do /party list, I see 1 skull, normal.
    [​IMG]

    When I invite someone, what is SUPPOSED to happen, is that the lore on my item (_ZomBae) is overwritten by _ZomBae + the invited player.

    [​IMG]

    BUT, as you can see, instead of overwriting the first head and updating the lore, it creates another head, and this, infinitely:

    [​IMG]

    What I tried doing, is removing the head that was there before, and adding an updated one.
    It just doesn't work, removing a head doesn't work, though adding it does:




    When I create a team:
    Code:
    ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
                            SkullMeta meta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM);
                            meta.setOwner(p.getName());
                            meta.setDisplayName(ChatColor.GOLD + p.getName() + ChatColor.AQUA + "'s Party");
                            ArrayList < String > lore = new ArrayList < String > ();
                            lore.add(ChatColor.AQUA + p.getName());
                            pl.partylore.put(args[1].toLowerCase(), lore);
                            meta.setLore(lore);
                            skull.setItemMeta(meta);
                            pl.partinventory.addItem(skull); // ADDING IT TO THE INVENTORY
    pl.myteamskull.put(args[1].toLowerCase(), skull); // SAVING THE SKULL IN ITS STATE TO A HASHMAP, THE KEY IS MY TEAM NAME
    


    When I invite someone else:
    Code:
    String newteam = pl.myteam.get(args[1]); // THE TEAM NAME
                                  pl.myteam.put(p.getName(), newteam); //IGNORE
                                  pl.partinventory.remove(pl.myteamskull.get(newteam)); //REMOVING THE OLDER SKULL FROM THE HASHMAP, WITH MY TEAM NAME
                                  List<String> list = new ArrayList<>();
                                  list.addAll(pl.teamplayers.get(newteam)); // ADDING THE OTHER PLAYERS LORE TO MINE, WORKING
                                  list.add(p.getName());
                                  pl.teamplayers.put(newteam, list);
                                  pl.hasparty.add(p.getName());
                                  ItemStack skull = pl.myteamskull.get(newteam);
                                  SkullMeta meta = (SkullMeta) skull.getItemMeta();
                                  ArrayList < String > lore = pl.partylore.get(newteam);
                                  lore.add(ChatColor.AQUA + p.getName());
                                  meta.setLore(lore);
                                  skull.setItemMeta(meta);
                                  pl.partinventory.addItem(skull); // ADDING IT BACK
     

    For I don't know what reason, it doesn't remove the older skull, just adds one back, I get no errors.

    PLEASE help :)
     
  2. Offline

    I Al Istannen

  3. Offline

    ZomBlade_Shadow

    Thanks for the reply :)
    But for setitem, I need an int, the int number.
    I'll try
    Code:
                                  pl.partinventory.setItem(pl.partinventory.firstEmpty(), skull);
    EDIT:

    Yeah, it still doesn't work :/
    I just need to know how to remove the previous skull, cause it doesn't remove somehow.
     
  4. That won't work since you're setting the item on the first empty slot the same as .addItem(), you have to
    That won't work because you're setting the skull on the first empty slot, right now that method is the same as .addItem(), you have to set the item over the skull, if you're going to display more than one team in a single inventory you have to store somehow skull position or re-create the inventory, after you can do .setItem(position, skull);. If not just set it to slot 0 .
     
  5. Offline

    ZomBlade_Shadow

    Yeah thanks for the reply.
    I know but I need to find a way to get the position of a skull.
    Like there will be alot of different team skulls in the inventory, and on every team invite, I must get the skulls position, I can't set it to 0.
    Please help :)

    EDIT:

    Trying
    Code:
    int count = 0;
                            for(ItemStack i : pl.partinventory.getContents()) {
                            if(i.getType() != Material.AIR) {
                            count++;
                            }else{
                            if(i.getType() == Material.AIR){
                                pl.myteamnumber.put(args[1].toLowerCase(), count);
                                pl.partinventory.setItem(count, skull);
                                break;
                                }
                              }
                            }
     
    Last edited: May 27, 2015
  6. @ZomBlade_Shadow Why are you iterating over the inventory? Just get the item in the inventroy (you know where it will be because you put it there, and you can stop people moving it)... failing that you could not store the inventory, and just store the skull by team. Edit that skull, and then just create an inventory when people try to view the team.
     
  7. Offline

    ZomBlade_Shadow

    I used another method, after tons of trying, works like a charm:

    In the Main, onEnable
    Code:
    int count = 0;
          for(ItemStack slot : pinventory.getContents()){
              pinventory.remove(slot);
              pinventory.setItem(count, packedice);
              count++;
          }
          partinventory.add(0, pinventory);
    The common inventory is now filled with Packed ice = nice backround instead of having air.

    When I create an inventory:

    Code:
          int count = 0;
    
                            for(ItemStack i : pl.partinventory.get(0).getContents()) {
                            if(i.getType() == Material.PACKED_ICE) {
                                pl.myteamnumber.put(args[1].toLowerCase(), count);
                                pl.partinventory.get(0).setItem(count, skull);
                                break;
                            }else{
                            if(i.getType() != Material.PACKED_ICE){
                                count++;
                               }
                            }
     
  8. Man stop doing that on else, after check if the material is air if you do else you don't have to check if the material isn't air.
    Code:
    if(material.equals(Material.AIR)) {
       //If the material is AIR
    } else {
       //If the material isn't AIR
    }
    
     
  9. Offline

    ZomBlade_Shadow

    I have a bad habit even though it's the same lol
     
Thread Status:
Not open for further replies.

Share This Page