Problems with GUI, Actions duplicated

Discussion in 'Plugin Development' started by woarth, Oct 4, 2015.

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

    woarth

    Hi you all! How are you?

    I feel very sorry, for comming here and take your time. But i need gelp with GUI system... I am making a plugin in which by the use of GUI, when you click an item you will go to another menu or perform a command. My problem is that this actions works twice (i mean: the command and the message sends twice, for example i receive the message duplicated, and the command if it works with an array list it will add me and remove me).

    I would love to know why does this happen. This is part of the code, for example in this case the send message happens twice.

    Code:
        @EventHandler
          public void onInventoryClick(InventoryClickEvent event) {
             
              Player p = (Player)event.getWhoClicked();
    
              if ((event.getInventory().getName().equals("§4Menu Name"))) {
                  if (event.getCurrentItem().getItemMeta().getDisplayName().equals("§6Item Name")) {
                        if (p.hasPermission("sf.submenu") || p.hasPermission("sf.*")) {
    
                          this.SubMenu= p.getPlayer().getServer().createInventory(null, 27, "§4SubMenu Name");
                     
                    ItemStack Heal = new ItemStack(Material.POTION, 1,(short) 8261);
                    ItemMeta HealMeta = Heal.getItemMeta();
                    HealMeta.setDisplayName("§6Heal");
                    ArrayList HealLore = new ArrayList();
                    HealLore.add("§7§o• Click to heal yourself");
                    HealMeta.setLore(HealLore);
                    Heal.setItemMeta(HealMeta);
    
                    this.SubMenu.setItem(10, Heal);
                  p.openInventory(this.SubMenu);
                   event.setCancelled(true);
                    p.sendMessage("Opening SubMenu name");
                  } else {
                    p.closeInventory();
                    p.sendMessage(ChatColor.RED +
                      "You don't have permission to access SubMenu");
                    event.setCancelled(true);
                  }
                }
                 
                }
              }
    Thank you all! And again, sorry for taking your time.
     
  2. Offline

    Protophite

    The event is probably running twice.
    @woarth
     
  3. Offline

    woarth

    Yes i know, but how can i make this event to run once, and not twice?

    Thanks!
     
  4. Offline

    SkyleTyler1337

    which message? @woarth

    Edit: please post full class?
     
  5. Offline

    boomboompower

  6. Offline

    Protophite

    @woarth i would need to see more code to identify the reason
     
Thread Status:
Not open for further replies.

Share This Page