Ignoring multi space in command

This commit is contained in:
BrokenFire 2018-01-12 10:15:49 +01:00
parent 316e7b5cbe
commit ecc133fbda

View File

@ -12,29 +12,31 @@ import java.util.Arrays;
*/ */
public class CommandParser { public class CommandParser {
Logger logger = LogManager.getLogger(); private Logger logger = LogManager.getLogger();
public CommandContainer parse(String brt, MessageReceivedEvent e) public CommandContainer parse(String brt, MessageReceivedEvent e)
{ {
ArrayList<String> split =new ArrayList<String>(); ArrayList<String> split =new ArrayList<String>();
String brut =brt; String brut =brt;
String sansTete = brut.replaceFirst("//",""); // on retire l'entete String sansTete = brut.replaceFirst("//","");
String[] splitSansTete = sansTete.split(" "); // on prend l'espace comme separateur cmd/arg String[] splitSansTete = sansTete.split(" ");
for(String s : splitSansTete){ //= pourchaque
split.add(s); // on fait un truc que je comprend pas trop x) for(String s : splitSansTete){
if(s.length()>0)
split.add(s);
} }
String commande = split.get(0); // on recuperre la 1er partie qui correspond a la cmd
String commande = split.get(0);
String[] args = new String[split.size()-1]; String[] args = new String[split.size()-1];
split.subList(1,split.size()).toArray(args); split.subList(1,split.size()).toArray(args);
for(int i=0;i<args.length;i++) for(int i=0;i<args.length;i++)
{
args[i]=args[i].replace('$',' '); args[i]=args[i].replace('$',' ');
}
logger.info("Auteur: "+e.getAuthor().getName()+", Commande: "+commande+", args: "+ Arrays.toString(args)); logger.info("Auteur: "+e.getAuthor().getName()+", Commande: "+commande+", args: "+ Arrays.toString(args));
return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e); //On Save toute les info dans le container return new CommandContainer(brut, sansTete, splitSansTete, commande, args, e);
} }
public class CommandContainer{ public class CommandContainer{