Solved Can you make 2 guis in 1 class?

Discussion in 'Spigot Plugin Development' started by WeedMan420, Nov 15, 2019.

  1. i tried doing this, both gui's have setcancelled on them, but only the first gui works, the second gui for some reason "works" but the set cancelled on them does not, so i can just grab the items.
  2. SteelPhoenix


    Yea we can't exactly guess the error without seeing any code and if possible stack traces.
  3. Please post your code and any errors you get.
    Put it in a code block. ->
    Click the little plus and hit code. Paste it in there.
  4. Code (Java):
        public void onInvClick(InventoryClickEvent e) {
    Code (Java):
        private void createMenu2(Player player) {
            Inventory particleInv2 = Bukkit.getServer().createInventory(null, 54, "§8§l-=-§6§lParticle Inventory 2§8§l-=-");

            ItemStack item29 = new ItemStack(Material.GRAVEL);
            ItemMeta meta29 = item29.getItemMeta();
            ArrayList<String> item29Lore = new ArrayList<>();
            meta29.setDisplayName("§7§lLarge Smoke Particle");
            item29Lore.add(ChatColor.RED + "");
            particleInv2.setItem(10, item29);
    Code (Java):
        public void openSecondPage(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
            if (!e.getInventory().getName().equalsIgnoreCase("§8§l-=-§6§lParticle Inventory 2§8§l-=-")) {

            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§7§lLarge Smoke Particle"))
    this is the second page of the gui. which is the one in which event.setCancelled does not seem to work. its layed out exactly the same way the first page is so i cant see what the problem is.
  5. You need to have a condition which chooses between the 2 options.
    As your onInvClick(InventoryClickEvent e) will immediatly process openFirstPage(e); and then openSecondPage(e);

    Thus seemingly ignoring openFirstPage(e);
  6. this is how i choose between the 2 guis:
    Code (Java):
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            Player player = (Player) sender;
            if (command.getName().equalsIgnoreCase("particle")) {

            return super.onCommand(sender, command, label, args);
    Code (Java):
     private void createMenu(Player player) {
            Inventory particleInv = Bukkit.getServer().createInventory(null, 54, "§8§l -=-§6§lParticle Inventory§8§l-=-");

            ItemStack nextItem1 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 5);
            ItemMeta nextMeta1 = nextItem1.getItemMeta();
            nextMeta1.setDisplayName("§a§lNext Page");
            particleInv.setItem(53, nextItem1);
    Code (Text):
        public void openFirstPage(InventoryClickEvent e) {
            Player player = (Player) e.getWhoClicked();
            if (!e.getInventory().getName().equalsIgnoreCase("§8§l -=-§6§lParticle Inventory§8§l-=-")) {

            if (e.getCurrentItem().getItemMeta().getDisplayName().contains("§a§lNext Page"))
  7. your logic makes sense, but i need the inventoryclickevent on the second page as well how do i split them apart from the same method yet still make it work.
  8. Where’s the @EventHandler annotation on the second event?
  9. well im stupid... thanks, i did not know you need to add @EventHandler to even child methods of an event.