Quick question about my bank accounts plugin..

Discussion in 'Spigot Plugin Development' started by ProGaming848, Jun 16, 2016.

  1. Hello everyone, i got a quick question about my bank accounts plugin:
    Because the upper part of my code works (so the take money and give a block part),
    but the code below that (give money and take a block) doesn't work. My question: Why does that not work??

    Code (Text):
            case GOLD_NUGGET:
                if (econ.getBalance(player) >= 1) {
                    if (event.getSlot() == 7) {
                        EconomyResponse r = econ.withdrawPlayer(player, 1.00);
                        if (r.transactionSuccess()) {
                            ItemStack goldnugget = new ItemStack(Material.GOLD_NUGGET, 1);
                            player.getInventory().addItem(goldnugget);
                            player.sendMessage(ChatColor.GRAY + "Je hebt een gold nugget succesvol opgenomen!");
                            break;
                        }
                    }
                }
                ItemStack goldnugget = new ItemStack(Material.GOLD_NUGGET, 1);
                if (event.getSlot() == 52) {
                    if (player.getInventory().contains(goldnugget)) {
                        EconomyResponse r2 = econ.depositPlayer(player, 1);
                        if (r2.transactionSuccess()) {
                            player.getInventory().remove(goldnugget);
                            player.sendMessage(ChatColor.GRAY + "Je hebt een gold nugget succesvol gestort!");
                            break;
                        } else {
                            player.sendMessage(ChatColor.RED + "Er is geen gold nugget in je invenory gevonden!");
                        }
                    }
                }
                break;
    Code (Text):
    ItemStack goldnugget = new ItemStack(Material.GOLD_NUGGET, 1);
                if (event.getSlot() == 52) {
                    if (player.getInventory().contains(goldnugget)) {
                        EconomyResponse r2 = econ.depositPlayer(player, 1);
                        if (r2.transactionSuccess()) {
                            player.getInventory().remove(goldnugget);
                            player.sendMessage(ChatColor.GRAY + "Je hebt een gold nugget succesvol gestort!");
                            break;
                        } else {
                            player.sendMessage(ChatColor.RED + "Er is geen gold nugget in je invenory gevonden!");
                        }
                    }
                }
     
  2. One of your if-statements must not be working as intended. Put messages after each if-statement to see how far down the chain you get to make sure they are setup correctly.
     
  3. Did this:

    Code (Text):
                ItemStack goldnugget = new ItemStack(Material.GOLD_NUGGET, 1);
                if (event.getSlot() == 52) {
                    player.sendMessage("event.getslot");
                    if (player.getInventory().contains(goldnugget)) {
                        player.sendMessage("event.getInventory.contains");
                        EconomyResponse r2 = econ.depositPlayer(player, 1);
                        if (r2.transactionSuccess()) {
                            player.sendMessage("r2.transactionSucces");
                            player.getInventory().remove(goldnugget);
                            player.sendMessage(ChatColor.GRAY + "Je hebt een gold nugget succesvol gestort!");
                            break;
                        } else {
                            player.sendMessage(ChatColor.RED + "Er is geen gold nugget in je invenory gevonden!");
                        }
                    }
                }
    It returns event.getslot
     
  4. So that means this line: if (player.getInventory().contains(goldnugget)) {

    is giving you your problems.
     
  5. k, do you have any idea how to fix that?
     
  6. Try printing out the player's inventory contents (using a loop) before that line. It seems that statement is returning false, so the contents of your player's inventory are not what you expected them to be.
     
  7. Loop through their inventory and check to see if any of the items have the Material of a gold nugget. In this case it might be better to not compare ItemStacks because ItemStacks hold a lot more data and there is a much greater chance for two very similar looking ItemStacks to not equal each other.