does not cancel event

Discussion in 'Plugin Development' started by Dekuhhh, Sep 9, 2020.

  1. Offline

    Dekuhhh

    I can't understand why it doesn't work. I need to create a gui with items. When you right or left click a certain item (renamed card) it cancels the event and performs different functions. :(

    Code:
                   Inventory inv = Bukkit.createInventory(null, 36, "&aPacchetti &e&lVIP".replaceAll("&", "§"));
                
                    ItemStack spietato = new ItemStack(Material.PAPER, 1);
                    ItemMeta im = spietato.getItemMeta();
                    @SuppressWarnings({ "rawtypes", "unchecked" })
                    ArrayList<String> lore = new ArrayList();
                    im.setDisplayName ("§e§oCosto §8§o↠ §f§o9.99€");
                    lore.add("");
                    lore.add("§7§oClick Destro per ricevere il link d'acquisto");
                    lore.add("§7§oClick Destro per ricevere maggiori info");
                    im.setLore(lore);
                    spietato.setItemMeta(im);
                    inv.setItem (11, spietato);
                   
                    ItemStack asso = new ItemStack(Material.PAPER, 1);
                    inv.setItem (1, asso);
                    p.openInventory(inv);
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
    
            }



    Code:
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            if (!e.getInventory().getTitle().equals("§aPacchetti §e§lVIP")) {
                Player p = (Player) e.getWhoClicked ();
                if(e.getCurrentItem().getType() == Material.PAPER) {
                    if(e.isLeftClick()){
                        e.setCancelled(true);
                        p.sendMessage("§9Pagina d'acquisto del §e§lVIP §dSpietato: link");
                        p.closeInventory();
                    } else {
                        e.setCancelled(true);
                        p.sendMessage("§7§oCosto pacchetto §8§o(§d§oSpietato§8§o) §7↠  §f9.99€ ");
                        p.sendMessage("");
                        p.closeInventory();
                    }
                }
            }
    
        }
    }
     
  2. Offline

    xelatercero

    maybe this line:
    Code:java
    1.  
    2. if (!e.getInventory().getTitle().equals("§aPacchetti §e§lVIP"))
    3.  


    you are checking if the inventory title is NOT "§aPacchetti §e§lVIP"
     
  3. Offline

    Strahan

    Also you should not be embedding the color character; use the ChatColor enum.
     

Share This Page