@@ -384,6 +384,23 @@ public List<PlayerSlot> getSlots() {
384384 return Collections .unmodifiableList (this .playerSlots );
385385 }
386386
387+ public void ensureOpenSlots (int count ) throws TooManyPlayersException {
388+ if (count > getMaximumPlayerCount ()) {
389+ throw new TooManyPlayersException ();
390+ }
391+ while (playerSlots .size () < count ) {
392+ this .playerSlots .add (new PlayerSlot (this ));
393+ }
394+ }
395+
396+ /** Set descriptors of PlayerSlots. */
397+ public void openSlots (SlotDescriptor [] descriptors ) throws TooManyPlayersException {
398+ ensureOpenSlots (descriptors .length );
399+ for (int i = 0 ; i < descriptors .length ; i ++) {
400+ this .playerSlots .get (i ).setDescriptor (descriptors [i ]);
401+ }
402+ }
403+
387404 /**
388405 * Threadsafe method to reserve all PlayerSlots.
389406 *
@@ -538,20 +555,6 @@ public void onPaused(Player nextPlayer) {
538555 observerBroadcast (new RoomPacket (getId (), new GamePausedEvent (nextPlayer )));
539556 }
540557
541- /** Set descriptors of PlayerSlots. */
542- public void openSlots (SlotDescriptor [] descriptors )
543- throws TooManyPlayersException {
544- if (descriptors .length > getMaximumPlayerCount ()) {
545- throw new TooManyPlayersException ();
546- }
547- this .playerSlots .add (new PlayerSlot (this ));
548- this .playerSlots .add (new PlayerSlot (this ));
549-
550- for (int i = 0 ; i < descriptors .length ; i ++) {
551- this .playerSlots .get (i ).setDescriptor (descriptors [i ]);
552- }
553- }
554-
555558 /** Return true if GameStatus is OVER. */
556559 public boolean isOver () {
557560 return getStatus () == GameStatus .OVER ;
0 commit comments