I have a ban plugin and the command is supposed to work like /ban (player) (reason), I need to know how I would be able to grab the reason and implement it into the kick message.
You'll use a stringbuilder and collect all the args after 0(or 1) Code (Text): StringBuilder message = new StringBuilder(); for (int i = 1; i < args.length; i++) { message.append(args[i] + " "); So the message will be all the args. See that you're getting i all after 1. And adding it to the stringbuilder along with a space.
using the last arguments the player entered. Would be something like this: String reason = ""; for(int arg = 2;arg < args.length;arg++){ reason += args[arg] + " "; }
Here you go. Index is the first argument the messages occurs, and wraps to the end of the arguments. Same as most methods... in a function. Code (Java): public static String messageFromArgs(String[] args, int index) { int maxArgs = args.length; StringBuilder message = new StringBuilder(); for ( int i = index; i < maxArgs; i++ ) { message.append(args[i]); if ( i < maxArgs ) { message.append(" "); } } return message.toString(); }
Code (Text): StringBuilder message = new StringBuilder(); for (int i = 1; i < args.length; i++) { message.append(args[i] + " "); other.kickPlayer(ChatColor.DARK_RED + "You have been banned from MineGird by " + sender.getName() + "/n" + ChatColor.RED + "Reason: " + args.toString(args[2])); } I don't know what you guys mean so what would I do to implement it into the ban message?
Well by that you still have to sort out the beginning arguments then but its an option yes. but actually similar to our methods to be honest
For a quick response to that here: Code (Text): StringBuilder message = new StringBuilder(); for (int i = 1; i < args.length; i++) { message.append(args[i] + " "); } other.kickPlayer(ChatColor.DARK_RED + "You have been banned from MineGird by " + sender.getName() + "/n" + ChatColor.RED + "Reason: " + message.toString());
So, hopefully finishing this thread, this is what you'll do for kicking them Code (Text): player.kickPlayer(ChatColor.RED + "You have been kicked" + "\n" + ChatColor.GREEN + "For: " + ChatColor.YELLOW + message.toString() The message is the reason.
@ No I mean how would I show the reason the moderator put into the player what he did wrong according to what the moderator said