GUI ClickEvent [SOLVED]

Discussion in 'Programming' started by zPlex, Apr 17, 2017.

  1. Code:
    Code (Text):
    public static Economy econ = null;

        @EventHandler
        public void onClick(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            EconomyResponse r100 = econ.withdrawPlayer(p, 100.00);
            EconomyResponse r75 = econ.withdrawPlayer(p, 75.00);
            EconomyResponse r300 = econ.withdrawPlayer(p, 300.00);
            EconomyResponse r80 = econ.withdrawPlayer(p, 80.00);
            EconomyResponse r225 = econ.withdrawPlayer(p, 225.00);
            if (e.getInventory().getName().equalsIgnoreCase("§6BuzzShop")) {
                ItemStack clicked = e.getCurrentItem();
                if (clicked == null || !clicked.hasItemMeta()) {
                    e.setCancelled(true);
                    return;
                }
                e.setCancelled(true);
                if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Grass Block")) {
                    if (r100.transactionSuccess()) {
                        p.getInventory().addItem(new ItemStack(Material.GRASS, 16));
                    } else {
                        p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
                    }
                    if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Dirt")) {
                        if (r75.transactionSuccess()) {
                            p.getInventory().addItem(new ItemStack(Material.DIRT, 16));
                        } else {
                            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
                        }
                        if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Gravel")) {
                            if (r100.transactionSuccess()) {
                                p.getInventory().addItem(new ItemStack(Material.GRAVEL, 16));
                            } else {
                                p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
                            }
                            if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Cobblestone")) {
                                if (r80.transactionSuccess()) {
                                    p.getInventory().addItem(new ItemStack(Material.COBBLESTONE, 16));
                                } else {
                                    p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
                                }
                                if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Moss Stone")) {
                                    if (r300.transactionSuccess()) {
                                        p.getInventory().addItem(new ItemStack(Material.MOSSY_COBBLESTONE, 16));
                                    } else {
                                        p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
                                    }
                                    if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Stone")) {
                                        if (r225.transactionSuccess()) {
                                            p.getInventory().addItem(new ItemStack(Material.STONE, 16));
                                        } else {
                                            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    When I click the frist block (Grass Block) in the GUI everything works fine but when I click the next blocks it won't work and won't say anything in chat or give me the Blocks. Please tell me what to do.
     
  2. Try to use this:

    Code (Text):
    if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Grass Block")) {

        if (r100.transactionSuccess()) {

            p.getInventory().addItem(new ItemStack(Material.GRASS, 16));

        } else {

            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");

        }

    } else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Dirt")) {
        if (r75.transactionSuccess()) {
            p.getInventory().addItem(new ItemStack(Material.DIRT, 16));
        } else {
            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
        }

    } else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Gravel")) {
        if (r100.transactionSuccess()) {
            p.getInventory().addItem(new ItemStack(Material.GRAVEL, 16));
        } else {
            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
        }

    } else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Cobblestone")) {
        if (r80.transactionSuccess()) {
            p.getInventory().addItem(new ItemStack(Material.COBBLESTONE, 16));
        } else {
            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
        }

    } else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Moss Stone")) {
        if (r300.transactionSuccess()) {
            p.getInventory().addItem(new ItemStack(Material.MOSSY_COBBLESTONE, 16));
        } else {
            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
        }

    } else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase("Stone")) {
        if (r225.transactionSuccess()) {
            p.getInventory().addItem(new ItemStack(Material.STONE, 16));
        } else {
            p.sendMessage("§4Error: §cYou don't have enough money to make this purchase!");
        }
    }

     
     
    • Like Like x 1
  3. Thanks for the Help! [THREAD CLOSED]