How do I do this?

Discussion in 'Plugin Development' started by football70500, Mar 15, 2015.

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

    football70500

    Well i bet this is pretty simple but, how do I make it so everything after like /b player is sent in a message? This is going to be a report command so like they type, for example, /b football70500 i think might be cheating. How would I get a message to be sent that says like Football70500 has been reported for "i think might be cheating"
     
  2. Offline

    8jy89hui

    You can compile all the arguments into a single string, using the onCommand(String[] args)
     
  3. Offline

    nverdier

    @football70500
    1) Create a StringBuilder
    2) Iterate through an array of the arguments split at the spaces
    3) Append to to StringBuilder after each iteration.
    4) Yeah.
     
  4. Offline

    football70500

    @nverdier @8jy89hui Then what am i doing wrong here? My command wont even run. Nothing happens when i do /report football70500 hacking or whatever i put

    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, Player player){
       
            Player target = null;  
            target = Bukkit.getServer().getPlayer(args [0]);
            String message = "";
           // for(int i = 1; i != args.length; i++)
             //   message += args[i] + " ";
            if(cmd.getName().equalsIgnoreCase("report")){
                sender.sendMessage(ChatColor.GREEN + "Reported. Thank you.");
                if(player.hasPermission("hr.getmessage")){
                    Bukkit.broadcastMessage(ChatColor.BLUE + "[Report] " + ChatColor.RED + target.getDisplayName() + " has been reported for " + ChatColor.GREEN + message);
                }else if(!player.hasPermission("hr.getmessage")){
                    return false;
                }
                }
            return false;
        }
    }
    I stamped out stuff trying to fix it
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Offline

    Zombie_Striker

    try this
    Code:
        
          Player target = Bukkit.getServer().getPlayer(args [0]);
            String message = "";
            for(int i = 1; i <= args.length; i++)
               message = message +" "+ args[i] + " ";
            if(cmd.getName().equalsIgnoreCase("report")){
                sender.sendMessage(ChatColor.GREEN + "Reported. Thank you.");
                if(player.hasPermission("hr.getmessage")){
                    Bukkit.broadcastMessage(ChatColor.BLUE + "[Report] " + ChatColor.RED + target.getDisplayName() + " has been reported; " + ChatColor.GREEN + message);
                }
                }
            return false;
        }
    
     
Thread Status:
Not open for further replies.

Share This Page