Solved Inventory Help

Discussion in 'Plugin Development' started by Disturbed_Creator, Oct 6, 2013.

Thread Status:
Not open for further replies.
  1. Ok, so I have a little mind probe for you all:
    How would you get all the ItemStacks in an inventory row, and just that row?

    Thank you ahead of time :>
     
  2. Offline

    se1by

    Maybe like this?
    Code:java
    1. Player player = Bukkit.getPlayer("PlayerName");
    2. ItemStack[] is = player.getInventory().getContent();
    3. ItemStack[][] isSorted = new Itemstack[4][9];
    4.  
    5. for(int i = 0; i < 5; i++){
    6. for(int x = 0; x < 10; x++){
    7. isSorted[I][x] = is[(i+1)*(x+1)];[/I]
    8. }
    9. }


    This is untested code, but it may work.
     
  3. se1by

    Doesn't work, or at least not the way I want it too. I am using this in a InventoryClickEvent, and I am trying to check the materials of all the items in the row you clicked in.

    Bump

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

    MrSnare

    Show us your code
     
    timtower likes this.
  5. MrSnare

    Code:java
    1. @EventHandler
    2. public void onClick(InventoryClickEvent e)
    3. {
    4.  
    5. if(!e.getInventory().getTitle().equals("§8Kits/Attributes"))return;
    6.  
    7. if(!e.getCurrentItem().hasItemMeta()){
    8.  
    9. e.setCancelled(true);
    10. return;
    11.  
    12. }
    13.  
    14. if(!e.getCurrentItem().getItemMeta().getDisplayName().contains("§a(UNLOCKED)")){
    15.  
    16. e.setCancelled(true);
    17. return;
    18.  
    19. }
    20.  
    21. Player p = (Player) e.getWhoClicked();
    22. pList = splitter(p.getName());
    23. String owned = "§a(UNLOCKED)";
    24. ItemStack start = e.getCurrentItem();
    25. ItemStack i = e.getCurrentItem().clone();
    26. int slotint = e.getSlot();
    27.  
    28. //Kit List Stuff
    29. String[] s = start.getItemMeta().getDisplayName().split("§a");
    30. String name1 = s[0];
    31. String name2 = name1.replace("§3", " ");
    32. String name3 = name2.trim();
    33.  
    34. ItemMeta iMeta = i.getItemMeta();
    35. iMeta.setDisplayName(start.getItemMeta().getDisplayName().replace(owned, "§b(SELECTED)"));
    36. i.setItemMeta(iMeta);
    37. i.setType(Material.ENCHANTED_BOOK);
    38.  
    39. e.getInventory().setItem(slotint, i);
    40.  
    41. //FINAL HASHMAP STUFFS
    42. pList.add(name3);
    43.  
    44. //ROW STUFFS HERE
    45.  
    46. fixer(p.getName(), pList);
    47.  
    48. e.setCancelled(true);
    49.  
    50. return;
    51.  
    52. }


    Where '//ROW STUFFS HERE' is, I would like to check if any other items in the same row as the item that was clicked contain a certain phrase in their title.
     
  6. Offline

    MrSnare

    I don't currently have access to the api but if you can get this to work it will do the trick.
    Code:java
    1. public ItemStack[] getInventoryRow(Player player, int rowNumber){
    2. int rowMax = 9 * rowNumber; //the last number in the row you are looking for
    3. ItemStack[] playerInventory = player.getInventory().getContent();
    4. ItemStack[] row = new ItemStack[9];//the row you are getting
    5. int rowPosition = 0;
    6. //for every itemstack in the row you chose
    7. for(int i = rowMax - 9; i < rowMax; i++){
    8. row[rowPosition] = playerInventory[i];
    9. rowPosition++;//increment the array position
    10. }
    11. return row;
    12. }[/i]
     
  7. MrSnare

    Me Gusta :>

    Could some explain the [/i] to me? it give me errors.

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

    MrSnare

    remove it. I tried to remove it from my post but it wont go away. Its not supposed to be there
     
  9. MrSnare
    Hahahahahaha, ok. Thank you :>
     
    MrSnare likes this.
Thread Status:
Not open for further replies.

Share This Page