Solved code doesn't work

Discussion in 'Plugin Development' started by JustMe999, Dec 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    JustMe999

    I'm making a plugin where you can warn people, but the code doesn't work. it go
    wrong by checking if the player can be warned i think but i don't know what is going wrong :( .
    sorry for bad english and bad translation.




    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. if (cmd.getName().equalsIgnoreCase("warn")) {
    3. if (!sender.hasPermission("warn.warn")) {
    4. sender.sendMessage(ChatColor.RED + "you haven't got the permission to warn someone!");
    5. return true;
    6. }
    7. if (args.length < 2) {
    8. sender.sendMessage(ChatColor.RED + "/warn <player> <reason>");
    9. return true;
    10. }
    11.  
    12. final Player target = Bukkit.getServer().getPlayer(args[0]);
    13.  
    14. if (target == null) {
    15. sender.sendMessage(ChatColor.RED + "Can't find player " + args[0]);
    16. return true;
    17. }
    18.  
    19. if(!target.hasPermission("waarschuw.cancel")){
    20. sender.sendMessage(ChatColor.RED + "You don't have the permissions to warn " + ChatColor.GRAY + target.getName());
    21. return true;
    22. }
    23.  
    24. String msg = "";
    25. for (int i = 1; i < args.length; i++) {
    26. msg += args[i] + " ";
    27. }
    28.  
    29. target.sendMessage(ChatColor.DARK_RED +"[Warning] " + ChatColor.RED + msg);
    30. sender.sendMessage(ChatColor.GREEN + "You have succesfull warned " + ChatColor.GRAY + target.getName();
    31. }
    32. return true;
    33. }
    34. }
    35. [/i]
     
  2. Offline

    Maulss

    Change the last 'return true;' to 'return false'.
     
  3. Offline

    JustMe999

    doesn't work.....
    it keep saying: You don't have the permissions to warn player.
     
  4. Offline

    Freelix2000

    On line 19, you want to cancel it if the target does have that permission. With the ! before it, you have made it so that the warning is cancelled if the target doesn't have that permission. Just remove the !, and that should fix it.
     
  5. Offline

    JustMe999

    thanks!
     
Thread Status:
Not open for further replies.

Share This Page