My plugin displays messages wrong??

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

  1. Why does my plugin display messages wrong?

    Code (Text):
            case DIAMOND_BLOCK:
                if (econ.getBalance(player) >= 5000) {
                    if (event.getSlot() == 1) {
                        EconomyResponse r = econ.withdrawPlayer(player, 5000.00);
                        if (r.transactionSuccess()) {
                            ItemStack dia = new ItemStack(Material.DIAMOND_BLOCK, 1);
                            player.getInventory().addItem(dia);
                            player.sendMessage(ChatColor.GRAY + "Je hebt een diamond block succesvol opgenomen!");
                            break;
                        } else {
                            player.sendMessage(
                                    ChatColor.RED + "Er is iets misgegeen tijdens het opnemen van een diamond block!");
                        }
                    } else {
                        player.sendMessage(
                                ChatColor.RED + "Er is iets misgegaan tijdens het opnemen van een diamond block!");
                    }
                } else {
                    player.sendMessage(ChatColor.RED + "Je hebt hiervoor niet genoeg geld op je bankrekening staan!");
                }

                ItemStack dia = new ItemStack(Material.DIAMOND_BLOCK, 1);
                if (event.getSlot() == 46) {
                    if (player.getInventory().contains(Material.DIAMOND_BLOCK)) {
                        EconomyResponse r2 = econ.depositPlayer(player, 5000);
                        if (r2.transactionSuccess()) {
                            player.getInventory().removeItem(dia);
                            player.sendMessage(ChatColor.GRAY + "Je hebt een diamond block succesvol gestort!");
                            break;
                        } else {
                            player.sendMessage(
                                    ChatColor.RED + "Er is iets misgegaan tijdens het storten van een diamond block!");
                        }
                    } else {
                        player.sendMessage(ChatColor.RED + "Er is geen diamond block in je invenory gevonden!");
                    }
                } else {
                    player.sendMessage(ChatColor.RED + "Er is iets misgegaan tijdens het storten van een diamond block!");
                }
                break;
    The problem is when i trigger the lower part of the code (so the "remove a block" and "give money" part.), it triggers a message from the upper part.. How can i fix that?
     
  2. Seems like you need help understanding basic logic flow. Its the hardest part for new developers, whether they want to acknowledge it or not.

    https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html
    http://www.wideskills.com/java-tutorial/java-control-flow-statements
    http://www.tutorialspoint.com/java/java_decision_making.htm

    It is advised to read as many tutorials and do as many "hello world" app tutorials as you can. It will greatly increase your fundamental understanding of not only the Java language, but of basic programming logics found in every language. ;)
     
  3. But i still do not understand where the error in the code is.. And yes, i have read the text on the websites.