spacepaste

  1.  
  2. diff --git a/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java b/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java
  3. index 931dd22b3..19ad103da 100644
  4. --- a/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java
  5. +++ b/src/net/sourceforge/kolmafia/textui/command/FortuneCommand.java
  6. @@ -43,11 +43,13 @@ import net.sourceforge.kolmafia.request.ClanFortuneRequest.Buff;
  7. public class FortuneCommand
  8. extends AbstractCommand
  9. {
  10. + static final String separator = "--";
  11. +
  12. public FortuneCommand()
  13. {
  14. - this.usage = " - buff mus|mys|mox|familiar|meat|item [word1 word2 word3] | <playername> [word1 word2 word3] - get a buff or an item, "
  15. - + "using preference-defined words if none are specified."
  16. - + "\nIf playername has spaces, cannot specify words, and does not support playernames with 3 spaces";
  17. + this.usage = " - buff mus|mys|mox|familiar|meat|item [word1 word2 word3] | <playername> [" + this.separator
  18. + + "] [word1 word2 word3] - get a buff or an item, using preference-defined words if none are specified."
  19. + + "\nplayername must be followed by " + this.separator + " if has 3 spaces, or if it has any spaces and you want to specify words";
  20. }
  21. @Override
  22. @@ -124,14 +126,66 @@ public class FortuneCommand
  23. KoLmafia.updateDisplay( MafiaState.ERROR, "You already consulted with a clanmate 3 times today." );
  24. return;
  25. }
  26. - if ( params.length == 4 )
  27. +
  28. + final String[] params_long = parameters.split( "\\s" + this.separator + "\\s" );
  29. + if ( params_long.length == 2 )
  30. + {
  31. + // Both player name and words present
  32. +
  33. + final String playerName = params_long[0];
  34. + final String[] words = params_long[1].split( "\\s" );
  35. +
  36. + if ( words.length == 3)
  37. + {
  38. + RequestThread.postRequest( new ClanFortuneRequest( playerName, words[0], words[1], words[2] ) );
  39. + }
  40. + else
  41. + {
  42. + KoLmafia.updateDisplay( MafiaState.ERROR, "You need to choose all 3 words or none of the words for your compatibility test." );
  43. + return;
  44. + }
  45. + }
  46. + else if ( params_long.length == 1 )
  47. {
  48. - RequestThread.postRequest( new ClanFortuneRequest( params[0], params[1], params[2], params[3] ) );
  49. + // Separator is leading, trailing or absent. In either case we can reuse previous split on whitespace.
  50. +
  51. + final Integer separatorIndex = parameters.indexOf( this.separator );
  52. + if ( separatorIndex == parameters.length() - this.separator.length() )
  53. + {
  54. + // Trailing this.separator i.e. just a (possibly long) player name
  55. + final String playerName = parameters.substring( 0, separatorIndex ).trim();
  56. + RequestThread.postRequest( new ClanFortuneRequest( playerName ) );
  57. + }
  58. + else if ( separatorIndex < 0 )
  59. + {
  60. + // No this.separator i.e. the old syntax.
  61. + if ( params.length == 4 )
  62. + {
  63. + RequestThread.postRequest( new ClanFortuneRequest( params[0], params[1], params[2], params[3] ) );
  64. + }
  65. + else
  66. + {
  67. + // If not 4 parameters, assume a name with spaces
  68. + RequestThread.postRequest( new ClanFortuneRequest( parameters ) );
  69. + }
  70. + }
  71. + else if ( separatorIndex == 0 )
  72. + {
  73. + // Leading this.separator i.e. words without player name
  74. + KoLmafia.updateDisplay( MafiaState.ERROR, "You must provide a player name" );
  75. + return;
  76. + }
  77. + else
  78. + {
  79. + // Somehow this.separator is in the middle after all. This should not be possible.
  80. + KoLmafia.updateDisplay( MafiaState.ERROR, "Separator found mid-params but was not split on" );
  81. + return;
  82. + }
  83. }
  84. else
  85. {
  86. - // If not 4 parameters, assume a name with spaces
  87. - RequestThread.postRequest( new ClanFortuneRequest( parameters ) );
  88. + KoLmafia.updateDisplay( MafiaState.ERROR, "Multiple " + this.separator + " this.separators found" );
  89. + return;
  90. }
  91. }
  92. }
  93.