11package sc .server .gaming ;
22
3- import java .util .HashMap ;
4- import java .util .Map ;
5- import java .util .UUID ;
6-
73import org .slf4j .Logger ;
84import org .slf4j .LoggerFactory ;
9-
105import sc .api .plugins .exceptions .RescuableClientException ;
116import sc .server .network .Client ;
127
13- public final class ReservationManager
14- {
8+ import java .util .HashMap ;
9+ import java .util .Map ;
10+ import java .util .UUID ;
11+
12+ public final class ReservationManager {
1513
1614 private static Logger logger = LoggerFactory .getLogger (ReservationManager .class );
17- private static Map <String , PlayerSlot > reservations = new HashMap <String , PlayerSlot >();
15+ private static Map <String , PlayerSlot > reservations = new HashMap <String , PlayerSlot >();
1816
1917 /** create Object as singleton */
20- private ReservationManager ()
21- {
18+ private ReservationManager () {
2219 // singleton
2320 }
2421
2522 /**
2623 * If reservation code is valid register client to playerslot and start game if all clients connected
27- * @param client to fill a slot
24+ *
25+ * @param client to fill a slot
2826 * @param reservation code which will redeem the reservation
27+ *
2928 * @return newly filled PlayerSlot
29+ *
3030 * @throws RescuableClientException will be thrown if slot cannot be filled or reservation is unknown
3131 */
3232 public static synchronized PlayerSlot redeemReservationCode (Client client ,
33- String reservation ) throws RescuableClientException
34- {
33+ String reservation ) throws RescuableClientException {
3534 PlayerSlot result = reservations .remove (reservation );
3635
37- if (result == null )
38- {
36+ if (result == null ) {
3937 throw new UnknownReservationException ();
40- }
41- else
42- {
38+ } else {
4339 logger .info ("Reservation {} was redeemed." , reservation );
4440 result .getRoom ().fillSlot (result , client );
4541 return result ;
@@ -48,14 +44,15 @@ public static synchronized PlayerSlot redeemReservationCode(Client client,
4844
4945 /**
5046 * Reserve a specific slot
47+ *
5148 * @param playerSlot the slot, that is supposed to be reserved
49+ *
5250 * @return the reservation code
51+ *
5352 * @throws RuntimeException if the slot is already reserved
5453 */
55- public synchronized static String reserve (PlayerSlot playerSlot )
56- {
57- if (reservations .containsValue (playerSlot ))
58- {
54+ public synchronized static String reserve (PlayerSlot playerSlot ) {
55+ if (reservations .containsValue (playerSlot )) {
5956 throw new RuntimeException ("This slot is already reserved." );
6057 }
6158
@@ -66,14 +63,13 @@ public synchronized static String reserve(PlayerSlot playerSlot)
6663
6764 /**
6865 * Generate a uniqe String ID
66+ *
6967 * @return the unique ID
7068 */
71- private synchronized static String generateUniqueId ()
72- {
69+ private synchronized static String generateUniqueId () {
7370 String key = UUID .randomUUID ().toString ();
7471
75- while (reservations .containsKey (key ))
76- {
72+ while (reservations .containsKey (key )) {
7773 key = UUID .randomUUID ().toString ();
7874 }
7975
@@ -82,10 +78,10 @@ private synchronized static String generateUniqueId()
8278
8379 /**
8480 * Remove reservation with given redeem code and free that slot
81+ *
8582 * @param reservation the redeem code
8683 */
87- public static synchronized void freeReservation (String reservation )
88- {
84+ public static synchronized void freeReservation (String reservation ) {
8985 PlayerSlot slot = reservations .remove (reservation );
9086 slot .free ();
9187 }
0 commit comments