Heres my code for the command I am making Code: if(label.equalsIgnoreCase("rawmsg")) { if(args.length == 0) { p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2); p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " " + colorize(plugin.getConfig().getString("nosyntax")) + " §4</rawmsg [player] [message]>"); } if(args.length == 1) { for(Player o : Bukkit.getOnlinePlayers()) { if(o.getName().equalsIgnoreCase(args[0])) { if(args.length > 1) { String msg = " "; for(String message : args) { msg = (msg + message + " "); } o.sendMessage("" + ChatColor.translateAlternateColorCodes('&', msg)); } else { p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2); p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " " + colorize(plugin.getConfig().getString("nosyntax")) + " §4</rawmsg [player] [message]>"); } } else { p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2); p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " §4Player not found."); } } } } When I type in the [message] part of it nothing pops up... I don't know what went wrong, otherwise the command is working. Gives me the errors for syntax and stuff.
@JarFile Your checking for 1 argument. That means you can only message one word, but if you check for 1 or more arguments it will work if you combine the arguments correctly.
@Skionz Ok so here is what I did Code: if(args.length >= 1) { for(Player o : Bukkit.getOnlinePlayers()) { if(o.getName().equalsIgnoreCase(args[0])) { if(args.length > 1) { String msg = " "; for(String message : args) { msg = (msg + message + " "); } o.sendMessage("" + ChatColor.translateAlternateColorCodes('&', msg)); } else { p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2); p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " " + colorize(plugin.getConfig().getString("nosyntax")) + " §4</rawmsg [player] [message]>"); } } else { p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2); p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " §4Player not found."); } } } Since it is >= is will include the player's name they typed in, but it also does the message now.
@JarFile You're also going to want to skip over the first argument (arg[0]) as the message will contain the players name if you don't. If this is solved, please update your title with the prefix "Solved".
Code: int argsTillMessage = 0; for(String message : args) { if(argsTillMessage < 2){ argsTillMessage++; }else{ msg = (msg + message + " "); } }