Soup sign

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Nov 27, 2014.

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

    Fhbgsdhkfbl

    Hey bukkit forums, I'm currently working on a GUI that will open up and have soups in it, I get the GUI to open, but it's not adding the soups into it. Yes my events are registered.

    Code:java
    1. @EventHandler
    2. public void onSoupGUI(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
    5. if ((e.getClickedBlock().getState() instanceof Sign)) {
    6. Sign s = (Sign)e.getClickedBlock().getState();
    7. Inventory soups = Bukkit.createInventory(null, 54, ChatColor.RED + "Soup Refill");
    8. if (s.getLine(1).equalsIgnoreCase(ChatColor.RED + "Soup")) {
    9. ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP);
    10. ItemMeta soupmeta = soup.getItemMeta();
    11. soupmeta.setDisplayName(ChatColor.RED + "Soup");
    12. soup.setItemMeta(soupmeta);
    13. soups.setItem(0, soup);
    14. soups.setItem(1, soup);
    15. soups.setItem(2, soup);
    16. soups.setItem(3, soup);
    17. soups.setItem(4, soup);
    18. soups.setItem(5, soup);
    19. soups.setItem(6, soup);
    20. soups.setItem(7, soup);
    21. soups.setItem(8, soup);
    22. soups.setItem(9, soup);
    23. soups.setItem(10, soup);
    24. soups.setItem(11, soup);
    25. soups.setItem(12, soup);
    26. soups.setItem(13, soup);
    27. soups.setItem(14, soup);
    28. soups.setItem(15, soup);
    29. soups.setItem(16, soup);
    30. soups.setItem(17, soup);
    31. soups.setItem(18, soup);
    32. soups.setItem(19, soup);
    33. soups.setItem(20, soup);
    34. soups.setItem(21, soup);
    35. soups.setItem(22, soup);
    36. soups.setItem(23, soup);
    37. soups.setItem(24, soup);
    38. soups.setItem(25, soup);
    39. soups.setItem(26, soup);
    40. soups.setItem(27, soup);
    41. soups.setItem(28, soup);
    42. soups.setItem(29, soup);
    43. soups.setItem(30, soup);
    44. soups.setItem(31, soup);
    45. soups.setItem(32, soup);
    46. soups.setItem(33, soup);
    47. soups.setItem(34, soup);
    48. soups.setItem(35, soup);
    49. soups.setItem(36, soup);
    50. soups.setItem(37, soup);
    51. soups.setItem(38, soup);
    52. soups.setItem(39, soup);
    53. soups.setItem(40, soup);
    54. soups.setItem(41, soup);
    55. soups.setItem(42, soup);
    56. soups.setItem(43, soup);
    57. soups.setItem(44, soup);
    58. soups.setItem(45, soup);
    59. soups.setItem(46, soup);
    60. soups.setItem(47, soup);
    61. soups.setItem(48, soup);
    62. soups.setItem(49, soup);
    63. soups.setItem(50, soup);
    64. soups.setItem(51, soup);
    65. soups.setItem(52, soup);
    66. soups.setItem(53, soup);
    67. }
    68. p.openInventory(soups);
    69. }
    70. }
     
  2. Offline

    Skionz

  3. Offline

    adam753

    Could be that an itemstack can't belong to two inventory slots at once. Try this (as Skionz suggested):
    Code:
    for(int i=0; i<54; i++) {
        ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP);
        ItemMeta soupmeta = soup.getItemMeta();
        soupmeta.setDisplayName(ChatColor.RED + "Soup");
        soup.setItemMeta(soupmeta);
        soups.setItem(i, soup);
    }
     
    Skionz likes this.
  4. Offline

    Skionz

    Fhbgsdhkfbl Your attempting to open the inventory 53 times. Move the openInventory method outside the for loop.
     
  5. Offline

    Fhbgsdhkfbl

    adam753
    Code:java
    1. @EventHandler
    2. public void onSoupGUI(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. Inventory soups = Bukkit.createInventory(null, 54, ChatColor.RED + "Soup Refill");
    5. if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
    6. if ((e.getClickedBlock().getState() instanceof Sign)) {
    7. Sign s = (Sign)e.getClickedBlock().getState();
    8. if (s.getLine(1).equalsIgnoreCase(ChatColor.RED + "Soup")) {
    9. for(int i=0; i<54; i++) {
    10. ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP);
    11. ItemMeta soupmeta = soup.getItemMeta();
    12. soupmeta.setDisplayName(ChatColor.RED + "Soup");
    13. soup.setItemMeta(soupmeta);
    14. soups.setItem(i, soup);
    15. }
    16. p.openInventory(soups);
    17. }
    18. }
    19. }
    20.  

    It's not opening the "Soups" inventory anymore.

    Edit: Fixed. It's not adding the soups though..
    http://gyazo.com/8c13dc56653db3fb9b5ca99fe480005c
     
  6. Offline

    adam753

    Well, based on that, it sounds like this line of code is returning false:
    Code:
    if (s.getLine(1).equalsIgnoreCase(ChatColor.RED + "Soup")) {
    So you've probably just made a mistake on the sign. Keep in mind the sign lines are from 0, so getLine(1) will return the second line.
     
  7. Offline

    Fhbgsdhkfbl

    The inventory opens, its just not adding the Soup to it.
     
  8. Offline

    adam753

    Which is it?
     
    Skionz likes this.
  9. Offline

    Fhbgsdhkfbl

    Not adding the soup to the inventory when I right click the sign and it opens the inventory.
     
  10. Offline

    xepisolonxx

    Fhbgsdhkfbl Example use of my code
    Code:
    public static void createcrate(Player p){
    Inventory inventory = Bukkit.getServer().createInventory(null, 54,ChatColor.BOLD + "" + ChatColor.DARK_GRAY + "Crate");
     
    for(int i = 0; i < inventory.getSize(); i++){
      inventory.addItem(new ItemStack(Material.MUSHROOM_SOUP));
                                      }
    p.openInventory(inventory);
                             }
                      }
     
  11. Offline

    adam753

    Fhbgsdhkfbl
    Right, it's just, in your op code you had the openInventory outside of the sign check, so it would only add the soups if the sign line was correct, but it would still open the inventory anyway.
    Code:
    if (s.getLine(1).equalsIgnoreCase(ChatColor.RED + "Soup")) {
        //add 54 soup items...
    }
    p.openInventory(soups);
    But in the second code sample you posted, you moved the openInventory line to inside that if-statement, and claimed it wasn't opening the imventory at all anymore.

    Could you humour me and double-check your sign logic?
     
  12. Offline

    Skionz

    Fhbgsdhkfbl The first line on a sign is line number 0 so this may be your problem.
     
Thread Status:
Not open for further replies.

Share This Page