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 @EventHandler public void onSoupGUI(PlayerInteractEvent e) { Player p = e.getPlayer(); if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; if ((e.getClickedBlock().getState() instanceof Sign)) { Sign s = (Sign)e.getClickedBlock().getState(); Inventory soups = Bukkit.createInventory(null, 54, ChatColor.RED + "Soup Refill"); if (s.getLine(1).equalsIgnoreCase(ChatColor.RED + "Soup")) { ItemStack soup = new ItemStack(Material.MUSHROOM_SOUP); ItemMeta soupmeta = soup.getItemMeta(); soupmeta.setDisplayName(ChatColor.RED + "Soup"); soup.setItemMeta(soupmeta); soups.setItem(0, soup); soups.setItem(1, soup); soups.setItem(2, soup); soups.setItem(3, soup); soups.setItem(4, soup); soups.setItem(5, soup); soups.setItem(6, soup); soups.setItem(7, soup); soups.setItem(8, soup); soups.setItem(9, soup); soups.setItem(10, soup); soups.setItem(11, soup); soups.setItem(12, soup); soups.setItem(13, soup); soups.setItem(14, soup); soups.setItem(15, soup); soups.setItem(16, soup); soups.setItem(17, soup); soups.setItem(18, soup); soups.setItem(19, soup); soups.setItem(20, soup); soups.setItem(21, soup); soups.setItem(22, soup); soups.setItem(23, soup); soups.setItem(24, soup); soups.setItem(25, soup); soups.setItem(26, soup); soups.setItem(27, soup); soups.setItem(28, soup); soups.setItem(29, soup); soups.setItem(30, soup); soups.setItem(31, soup); soups.setItem(32, soup); soups.setItem(33, soup); soups.setItem(34, soup); soups.setItem(35, soup); soups.setItem(36, soup); soups.setItem(37, soup); soups.setItem(38, soup); soups.setItem(39, soup); soups.setItem(40, soup); soups.setItem(41, soup); soups.setItem(42, soup); soups.setItem(43, soup); soups.setItem(44, soup); soups.setItem(45, soup); soups.setItem(46, soup); soups.setItem(47, soup); soups.setItem(48, soup); soups.setItem(49, soup); soups.setItem(50, soup); soups.setItem(51, soup); soups.setItem(52, soup); soups.setItem(53, soup); } p.openInventory(soups); } }
Fhbgsdhkfbl Not sure what is wrong, but you should really use a for loop to make it not look so messy. http://en.wikipedia.org/wiki/Don't_repeat_yourself
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); }
Fhbgsdhkfbl Your attempting to open the inventory 53 times. Move the openInventory method outside the for loop.
adam753 Code:java @EventHandlerpublic void onSoupGUI(PlayerInteractEvent e) {Player p = e.getPlayer();Inventory soups = Bukkit.createInventory(null, 54, ChatColor.RED + "Soup Refill");if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;if ((e.getClickedBlock().getState() instanceof Sign)) {Sign s = (Sign)e.getClickedBlock().getState();if (s.getLine(1).equalsIgnoreCase(ChatColor.RED + "Soup")) {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);}p.openInventory(soups);}}} It's not opening the "Soups" inventory anymore. Edit: Fixed. It's not adding the soups though.. http://gyazo.com/8c13dc56653db3fb9b5ca99fe480005c
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.
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); } }
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?