3232import java .util .List ;
3333import java .util .UUID ;
3434import java .util .function .Consumer ;
35+ import java .util .stream .IntStream ;
3536
3637import static net .minecraft .commands .Commands .argument ;
3738import static net .minecraft .commands .Commands .literal ;
@@ -164,17 +165,13 @@ private static int listTaterzens(CommandContext<CommandSourceStack> context) thr
164165
165166 boolean sel = taterzenNPC == npc ;
166167
167- response
168- .append (
168+ response .append (
169169 Component .literal ("\n " + i + "-> " + name )
170170 .withStyle (sel ? ChatFormatting .BOLD : ChatFormatting .RESET )
171171 .withStyle (sel ? ChatFormatting .GREEN : (i % 2 == 0 ? ChatFormatting .YELLOW : ChatFormatting .GOLD ))
172172 .withStyle (style -> style
173- .withClickEvent (new ClickEvent (ClickEvent .Action .SUGGEST_COMMAND , "/npc select uuid" + taterzenNPC .getUUID ().toString ()))
174- .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , translate (sel ? "taterzens.tooltip.current_selection" : "taterzens.tooltip.new_selection" , name ))
175- )
176- )
177- )
173+ .withClickEvent (new ClickEvent (ClickEvent .Action .SUGGEST_COMMAND , "/npc select uuid " + taterzenNPC .getUUID ().toString ()))
174+ .withHoverEvent (new HoverEvent (HoverEvent .Action .SHOW_TEXT , translate (sel ? "taterzens.tooltip.current_selection" : "taterzens.tooltip.new_selection" , name )))))
178175 .append (
179176 Component .literal (" (" + (console ? taterzenNPC .getStringUUID () : "uuid" ) + ")" )
180177 .withStyle (ChatFormatting .GRAY )
@@ -189,18 +186,17 @@ private static int listTaterzens(CommandContext<CommandSourceStack> context) thr
189186 source .sendSuccess (response , false );
190187 return 1 ;
191188 }
192- private static String [] getAvailableTaterzenIndices () {
193- String [] availableIDs = new String [TATERZEN_NPCS .size ()];
194- for (int i = 0 ; i < TATERZEN_NPCS .size (); i ++) {
195- availableIDs [i ] = Integer .toString (i + 1 );
196- }
197- return availableIDs ;
189+
190+ private static List <String > getAvailableTaterzenIndices () {
191+ return IntStream .range (0 , TATERZEN_NPCS .size ())
192+ .mapToObj (i -> String .valueOf (i + 1 ))
193+ .toList ();
198194 }
199195
200196 private static int selectTaterzenById (CommandContext <CommandSourceStack > context ) throws CommandSyntaxException {
201197 int id = IntegerArgumentType .getInteger (context , "id" );
202198 CommandSourceStack source = context .getSource ();
203- if (id > TATERZEN_NPCS .size ()) {
199+ if (id > TATERZEN_NPCS .size ()) {
204200 source .sendFailure (errorText ("taterzens.error.404.id" , String .valueOf (id )));
205201 } else {
206202 TaterzenNPC taterzen = (TaterzenNPC ) TATERZEN_NPCS .values ().toArray ()[id - 1 ];
@@ -226,20 +222,13 @@ private static int selectTaterzenById(CommandContext<CommandSourceStack> context
226222 return 1 ;
227223 }
228224
229- private static String [] getAvailableTaterzenNames () {
230- String [] availableNames = new String [TATERZEN_NPCS .size ()];
231-
232- int i = 0 ;
233- for (var taterzen : TATERZEN_NPCS .values ()) {
234- availableNames [i ] = taterzen .getName ().getString ();
235- availableNames [i ] = "\" " + availableNames [i ] + "\" " ; // Adds quotation marks to the suggested name, such that
236- // Names containing a whitespace character (ex. the
237- // name is 'Foo Bar') can be completed and correctly
238- // used without the user having to enclose the argument
239- // name with quotation marks themselves.
240- ++i ;
241- }
242- return availableNames ;
225+ private static List <String > getAvailableTaterzenNames () {
226+ // Adds quotation marks to the suggested name, such that
227+ // Names containing a whitespace character (ex. the
228+ // name is 'Foo Bar') can be completed and correctly
229+ // used without the user having to enclose the argument
230+ // name with quotation marks themselves.
231+ return TATERZEN_NPCS .values ().stream ().map (npc -> "\" " + npc .getName ().getString () + "\" " ).toList ();
243232 }
244233
245234 private static int selectTaterzenByName (CommandContext <CommandSourceStack > context ) throws CommandSyntaxException {
0 commit comments