Hey guys, recently I made a thread about something similar. And It worked what they told me to do. However, I changed up my code a bit, and now it does not work again. Basically, I want to send the player a message if they do not have enough coins to buy the rank. And a message saying they already have this rank, if they already have it. This is what my code looks like: Code (Text): private void sqlCheck(Player player, String rank) { if (SQL.getValue(player.getName(), "coins") >= 15000) { SQL.buyRank(player.getName()); McMyths.chat().sendMessage(player, "You bought the §" + rank + " §7rank!"); Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "removemoney " + player + " 15000"); } else { player.sendMessage("§7You need 15000 coins to buy this rank!"); } } } And the click event: Code (Text): if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Farmer")) { e.setCancelled(true); e.getWhoClicked().teleport(e.getWhoClicked().getWorld().getSpawnLocation()); if (e.getWhoClicked().hasPermission("rank.farmer")) e.getWhoClicked().sendMessage("You already have this rank!"); sqlCheck((Player) e.getWhoClicked(), "Farmer"); return; } else /* * SECOND */ I do it for all 5 ranks, thats why there is an else Thanks in advance
Can you try to test it by having 25000 coins and then have the permission "rank.farmer" at the same time? Doubt it would only send the already have a rank message
It didn't send both messages, but after I bought it and clicked it again, it didn't say I already have the rank
Did you do it while having the permission? Hmm, i thought it should only send this according to the code you have here Code (Text): if (e.getWhoClicked().hasPermission("rank.farmer")) e.getWhoClicked().sendMessage("You already have this rank!");
Code (Text): if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Farmer")) { e.setCancelled(true); e.getWhoClicked().teleport(e.getWhoClicked().getWorld().getSpawnLocation()); if (e.getWhoClicked().hasPermission("rank.farmer")) e.getWhoClicked().sendMessage("You already have this rank!"); *else* sqlCheck((Player) e.getWhoClicked(), "Farmer"); return; } else /* * SECOND */ sqlCheck() was being run regardless of if the player already had the rank. i'm not sure if this is the problem, but this is a big problem. try adding in the else there.
Hmm in this case, try to debug, *I usually use remote debugging* add some breakpoint to see what has been executed in SQLcheck() and the EH
well in your original post its missing it, i modified the code in the quote in my post to show what i mean. sorry for not being clear.
I would just change this: Code (Text): if (e.getWhoClicked().hasPermission("rank.farmer")) e.getWhoClicked().sendMessage("You already have this rank!"); sqlCheck((Player) e.getWhoClicked(), "Farmer"); To this: Code (Text): if (!e.getWhoClicked().hasPermission("rank.farmer")) { sqlCheck((Player) e.getWhoClicked(), "Farmer"); } else { e.getWhoClicked().sendMessage("You already have this rank!"); } Something like that anyway. The way your code is now its always going to call the sqlCheck method regardless of if they have already purchased the rank or not. Another option would be to move the permission check to the sqlCheck method as well.
Hmm well I think that works, just its not adding the perm, if I do it through my code. If i do it by hand it works. This is how i am adding it through my code Code (Text): Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "pex user " + player + " add" + " " + "rank." + rank.toLowerCase()); Its saying it was added but its not adding
Very stupid mistake on my part Now, if I wanted to make each rank a separate price, would I be able to do that in the SQLcheck method? I would like to keep it as organized as possible. Thanks!
Easy fix. Code (Text): if (e.getCurrentItem().getItemMeta().getDisplayName().contains("Farmer")) { e.setCancelled(true); e.getWhoClicked().teleport(e.getWhoClicked().getWorld().getSpawnLocation()); if (e.getWhoClicked().hasPermission("rank.farmer")){ e.getWhoClicked().sendMessage("You already have this rank!"); sqlCheck((Player) e.getWhoClicked(), "Farmer"); return; } else /* * SECOND */