Problem?

Discussion in 'Plugin Development' started by HyrulesLegend, Nov 17, 2013.

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

    HyrulesLegend

    I'm trying to make a ban command, i'm not why it's not working. There's no stacktrace, and nothing happens when I do /ban <player> <reason> in chat, but when I do /ban, it displays the message that I put there. Any ideas?

    Class:
    Code:java
    1. package me.brawl.Commands;
    2.  
    3.  
    4. import me.brawl.Main.Main;
    5. import me.brawl.Main.SettingsManager;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandExecutor;
    11. import org.bukkit.command.CommandSender;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.event.Listener;
    14.  
    15. public class Ban implements CommandExecutor, Listener {
    16.  
    17. SettingsManager settings = SettingsManager.getInstance();
    18.  
    19.  
    20.  
    21.  
    22. @SuppressWarnings("unused")
    23. private Main plugin;
    24. public Ban(Main plugin) {
    25. this.plugin = plugin;
    26. }
    27.  
    28.  
    29.  
    30. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    31. if(cmd.getName().equalsIgnoreCase("ban")){
    32. if(args.length <= 0){
    33. sender.sendMessage(ChatColor.RED + "Please specify a player!");
    34. return true;
    35. }
    36. if(args.length < 0){
    37. Player target = Bukkit.getServer().getPlayer(args[0]);
    38. if(args[0].equalsIgnoreCase(target.getName())){
    39. StringBuilder message2 = new StringBuilder();
    40. message2.append(args[1]);
    41. for (int i = 1; i < args.length; i++) {
    42. message2.append(" ");
    43. target.kickPlayer(" " + message2);
    44. Bukkit.broadcastMessage(ChatColor.RED + sender.getName() + ChatColor.GOLD + " has banned " + target.getName() + " for " + message2);
    45. settings.getData().set(".banned" + target.getName() + ".reason", message2);
    46. target.setBanned(true);
    47. settings.saveData();
    48. return true;
    49.  
    50. }
    51. }
    52. }
    53. }
    54.  
    55.  
    56. return false;
    57. }
    58. }
    59.  
     
  2. Offline

    MayoDwarf

    Did you register the command in plugin.yml?
     
  3. Offline

    HyrulesLegend

    MayoDwarf Yup, like I said, it does say the "Please Specify a player!" when I do /ban, but the next part doesn't work.
     
  4. Offline

    Syd

    Max_The_Link_Fan
    Line 36, you check of args.length is smaller than 0, instead of larger than 0. ;)

    However, you still have a possible ArrayIndexOutOfBoundsException in line 40.
     
    MayoDwarf likes this.
  5. Offline

    Chinwe

    Have you getCommand("ban").setExecutor(new Ban(this)); in your main class?
     
    MayoDwarf likes this.
  6. Offline

    HyrulesLegend

    Chinwe Yes, I do.

    Thanks everyone! Now the ban command works, but now another part isn't working. This is supposed to kick the player if they are in the data file.
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerLoginEvent e) {
    3. Player p = e.getPlayer();
    4. if(settings.getData().contains(".banned" + p.getName())){
    5. p.kickPlayer(ChatColor.RED + "You have been banned for cheating!");
    6. }
    7. }
    8. }
    9. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. Offline

    clutchmasterman

    then do me a flavor and change the prefix to slovled
     
  8. Offline

    MayoDwarf

    Posting just a little snip of code will not help us... Also why is it ".banned"? Why not "banned"?
     
  9. Offline

    HyrulesLegend

    MayoDwarf Look in my code for /ban. It's .banned, that just sorts everything out nicely.
     
Thread Status:
Not open for further replies.

Share This Page