diff --git a/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java b/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java index 931dd22b3..19ad103da 100644 --- a/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java +++ b/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java @@ -43,11 +43,13 @@ import net.sourceforge.kolmafia.request.ClanFortuneRequest.Buff; public class FortuneCommand extends AbstractCommand { + static final String separator = "--"; + public FortuneCommand() { - this.usage = " - buff mus|mys|mox|familiar|meat|item [word1 word2 word3] | [word1 word2 word3] - get a buff or an item, " - + "using preference-defined words if none are specified." - + "\nIf playername has spaces, cannot specify words, and does not support playernames with 3 spaces"; + this.usage = " - buff mus|mys|mox|familiar|meat|item [word1 word2 word3] | [" + this.separator + + "] [word1 word2 word3] - get a buff or an item, using preference-defined words if none are specified." + + "\nplayername must be followed by " + this.separator + " if has 3 spaces, or if it has any spaces and you want to specify words"; } @Override @@ -124,14 +126,66 @@ public class FortuneCommand KoLmafia.updateDisplay( MafiaState.ERROR, "You already consulted with a clanmate 3 times today." ); return; } - if ( params.length == 4 ) + + final String[] params_long = parameters.split( "\\s" + this.separator + "\\s" ); + if ( params_long.length == 2 ) + { + // Both player name and words present + + final String playerName = params_long[0]; + final String[] words = params_long[1].split( "\\s" ); + + if ( words.length == 3) + { + RequestThread.postRequest( new ClanFortuneRequest( playerName, words[0], words[1], words[2] ) ); + } + else + { + KoLmafia.updateDisplay( MafiaState.ERROR, "You need to choose all 3 words or none of the words for your compatibility test." ); + return; + } + } + else if ( params_long.length == 1 ) { - RequestThread.postRequest( new ClanFortuneRequest( params[0], params[1], params[2], params[3] ) ); + // Separator is leading, trailing or absent. In either case we can reuse previous split on whitespace. + + final Integer separatorIndex = parameters.indexOf( this.separator ); + if ( separatorIndex == parameters.length() - this.separator.length() ) + { + // Trailing this.separator i.e. just a (possibly long) player name + final String playerName = parameters.substring( 0, separatorIndex ).trim(); + RequestThread.postRequest( new ClanFortuneRequest( playerName ) ); + } + else if ( separatorIndex < 0 ) + { + // No this.separator i.e. the old syntax. + if ( params.length == 4 ) + { + RequestThread.postRequest( new ClanFortuneRequest( params[0], params[1], params[2], params[3] ) ); + } + else + { + // If not 4 parameters, assume a name with spaces + RequestThread.postRequest( new ClanFortuneRequest( parameters ) ); + } + } + else if ( separatorIndex == 0 ) + { + // Leading this.separator i.e. words without player name + KoLmafia.updateDisplay( MafiaState.ERROR, "You must provide a player name" ); + return; + } + else + { + // Somehow this.separator is in the middle after all. This should not be possible. + KoLmafia.updateDisplay( MafiaState.ERROR, "Separator found mid-params but was not split on" ); + return; + } } else { - // If not 4 parameters, assume a name with spaces - RequestThread.postRequest( new ClanFortuneRequest( parameters ) ); + KoLmafia.updateDisplay( MafiaState.ERROR, "Multiple " + this.separator + " this.separators found" ); + return; } } }