refactor: formatted Lobby files properly

This commit is contained in:
Yannik Bretschneider 2021-06-07 01:58:25 +02:00
parent c24121b6d9
commit 16c425c507
9 changed files with 90 additions and 83 deletions

View File

@ -30,9 +30,9 @@ public class Lobby {
private final TurnTimer turnTimer;
/**
* The {@link Lobby} is where the magic happens.
* In this class is a whole {@link GameInstance game} is processed.
* To initialize the game it gets the following parameters
* The {@link Lobby} is where the magic happens. In this class is a whole {@link GameInstance game} is processed. To
* initialize the game it gets the following parameters
*
* @param gameID a String to identify the game
* @param connection the Connection to the {@link uulm.teamname.marvelous.server.lobbymanager.LobbyManager}
* @param partyConfig declared in Editor
@ -84,6 +84,7 @@ public class Lobby {
/**
* Called by {@link LobbyConnection} to handle requests
*
* @param requests to be processed
* @param source the player executing the requests
*/
@ -118,8 +119,8 @@ public class Lobby {
}
/**
* This method is called at the end of receiveRequests, to start a timer.
* The active player has now a specific amount of time to do his moves.
* This method is called at the end of receiveRequests, to start a timer. The active player has now a specific
* amount of time to do his moves.
*/
void updateTimer() {
var currentActiveCharacterType = game.state.getActiveCharacter().type;
@ -151,6 +152,7 @@ public class Lobby {
/**
* If the player executed a false request the request gets rejected.
*
* @param source the executing player
*/
private void reject(Participant source) {
@ -161,8 +163,7 @@ public class Lobby {
connection.removeParticipant(source);
if (connection.hasPlayer1()) {
generateWin(connection.getPlayer1());
}
else if(connection.hasPlayer2()) {
} else if (connection.hasPlayer2()) {
generateWin(connection.getPlayer2());
}
}
@ -170,6 +171,7 @@ public class Lobby {
/**
* Warns the player he get timeouted soon.
*
* @param source soon to be timeouted player
*/
public synchronized void soonTimeout(Participant source) {
@ -180,6 +182,7 @@ public class Lobby {
/**
* If a player times out the other player automatically wins.
*
* @param source is the timeouted player
*/
public synchronized void timeout(Participant source) {
@ -190,11 +193,9 @@ public class Lobby {
if (connection.hasPlayer1() && !connection.hasPlayer2()) {
generateWin(connection.getPlayer1());
}
else if(!connection.hasPlayer1() && connection.hasPlayer2()) {
} else if (!connection.hasPlayer1() && connection.hasPlayer2()) {
generateWin(connection.getPlayer2());
}
else {
} else {
throw new IllegalStateException("Spectator was time-outed which is impossible");
}
}
@ -208,8 +209,8 @@ public class Lobby {
}
/**
* The method generates a Win event for a {@link Participant}.
* Afterwards it sends a Disconnect to everyone, and terminates the connection.
* The method generates a Win event for a {@link Participant}. Afterwards it sends a Disconnect to everyone, and
* terminates the connection.
*
* @param winner is the {@link Participant} that won
*/

View File

@ -34,6 +34,7 @@ public class TurnTimer {
/**
* This method checks if the participant is not a spectator. Otherwise it won't start a timer.
*
* @param participant the timer is for
*/
public void startTurnTimer(Participant participant) {
@ -44,7 +45,10 @@ public class TurnTimer {
clear();
Logger.debug("Starting turn timer for participant '{}' with role {}",
participant.name, participant.type);
current = timer.schedule(() -> {callback.accept(participant); return participant;},
current = timer.schedule(() -> {
callback.accept(participant);
return participant;
},
maxRoundTime,
TimeUnit.SECONDS);
}

View File

@ -10,8 +10,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link DisconnectSegment} handles requests of {@link RequestType} DisconnectRequest.
* Therefore it removes the disconnecting player-connection from the {@link Lobby}.
* The {@link DisconnectSegment} handles requests of {@link RequestType} DisconnectRequest. Therefore it removes the
* disconnecting player-connection from the {@link Lobby}.
*/
public class DisconnectSegment implements Segment {
@ -31,8 +31,7 @@ public class DisconnectSegment implements Segment {
if (packet.getOrigin().type != ParticipantType.Spectator) {
if (parent.getConnection().hasPlayer1()) {
parent.generateWin(parent.getConnection().getPlayer1());
}
else if(parent.getConnection().hasPlayer2()) {
} else if (parent.getConnection().hasPlayer2()) {
parent.generateWin(parent.getConnection().getPlayer2());
}
}

View File

@ -12,8 +12,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link GameStateSegment} handles all {@link GameInstance game} relevant {@link Request Requests}.
* Therefore it updates the game with the matching request.
* The {@link GameStateSegment} handles all {@link GameInstance game} relevant {@link Request Requests}. Therefore it
* updates the game with the matching request.
*/
public class GameStateSegment implements Segment {
private GameInstance game;

View File

@ -7,8 +7,8 @@ import uulm.teamname.marvelous.server.lobbymanager.Participant;
import java.util.*;
/**
* The {@link Packet} contains all {@link Request Requests} and the belonging {@link Participant}.
* You can add and remove {@link Request Requests} at will.
* The {@link Packet} contains all {@link Request Requests} and the belonging {@link Participant}. You can add and
* remove {@link Request Requests} at will.
*/
public class Packet extends ArrayList<Request> {
@ -21,6 +21,7 @@ public class Packet extends ArrayList<Request> {
/**
* This method checks if a {@link RequestType} is part of the {@link Packet} or not
*
* @param requiredType RequestType to check.
* @return boolean
*/
@ -35,6 +36,7 @@ public class Packet extends ArrayList<Request> {
/**
* This method removes all {@link Request Requests} of given {@link RequestType types} from the {@link Packet}.
*
* @param types RequestType(s) to remove
*/
public void removeRequestsOfTypes(RequestType... types) {
@ -43,7 +45,9 @@ public class Packet extends ArrayList<Request> {
}
/**
* This method removes all {@link Request Requests} except of given {@link RequestType types} from the {@link Packet}.
* This method removes all {@link Request Requests} except of given {@link RequestType types} from the {@link
* Packet}.
*
* @param types RequestType(s) to not remove
*/
public void removeRequestsNotOfTypes(RequestType... types) {

View File

@ -22,9 +22,7 @@ public class PauseSegment implements Segment {
paused = false;
}
/**
* This method pauses the game if it is not already paused.
*/
/** This method pauses the game if it is not already paused.*/
public void pauseGame() {
if (!paused) {
paused = true;
@ -48,8 +46,8 @@ public class PauseSegment implements Segment {
/**
* Pipelining method to process a set of requests.
* The list of requests will be processed according to the following rules:
* Pipelining method to process a set of requests. The list of requests will be processed according to the following
* rules:
* <ul>
* <li>If there is a PauseStartRequest, the paused value will be set to true</li>
* <li>Any CharacterRequests will be removed from the requests if the game is paused. These include:

View File

@ -9,8 +9,8 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link Pipeline} class pipelines {@link Request Requests} through {@link Segment Segments} to
* create {@link Event Events}. To add functionality without dabbling in the game library, create a new {@link Segment}.
* The {@link Pipeline} class pipelines {@link Request Requests} through {@link Segment Segments} to create {@link Event
* Events}. To add functionality without dabbling in the game library, create a new {@link Segment}.
*/
public class Pipeline {
@ -25,17 +25,17 @@ public class Pipeline {
}
/**
* Pipeline the {@link Request Requests} through all {@link Segment Segments} that are in the pipeline.
* The {@link Request Requests} are declared as the <b>Packet</b>. The {@link Request Requests} are filtered
* by each {@link Segment segment}, whereby each {@link Segment segment} takes (and thereby removes) all
* {@link Event events} relevant to the {@link Segment segment}. The {@link Event Events} are returned at the
* end of the pipeline.
* Pipeline the {@link Request Requests} through all {@link Segment Segments} that are in the pipeline. The {@link
* Request Requests} are declared as the <b>Packet</b>. The {@link Request Requests} are filtered by each {@link
* Segment segment}, whereby each {@link Segment segment} takes (and thereby removes) all {@link Event events}
* relevant to the {@link Segment segment}. The {@link Event Events} are returned at the end of the pipeline.
*
* @param requests are the requests that are being pipelined through the pipeline
* @return a {@link Optional}<{@link Event}[]>, whereby the state of the {@link Optional} declares whether the
* execution of the {@link Pipeline} was successful. <b>If the optional is empty, the input requests were
* invalid, and an error message can be sent to the client</b>. To get the {@link Event Events}
* out of the {@link Optional}, first check whether the {@link Optional} is empty by doing
* {@link Optional#isEmpty()} or {@link Optional#isPresent()}, and act accordingly.
* execution of the {@link Pipeline} was successful. <b>If the optional is empty, the input requests were invalid,
* and an error message can be sent to the client</b>. To get the {@link Event Events} out of the {@link Optional},
* first check whether the {@link Optional} is empty by doing {@link Optional#isEmpty()} or {@link
* Optional#isPresent()}, and act accordingly.
*/
public Optional<List<Event>> processRequests(Request[] requests, Participant origin) {
Logger.trace("Pipeline started RequestProcessing");
@ -65,10 +65,11 @@ public class Pipeline {
}
/**
* Adds a segment to the pipeline. Note that <b>ORDER MATTERS!</b> The first segment added will be the
* first segment to process events. Also note that segments <b>cannot be removed once added</b>. This is by
* design, as removing segments would give the pipeline runtime customizability, which it is not supposed to
* possess in the first place.
* Adds a segment to the pipeline. Note that <b>ORDER MATTERS!</b> The first segment added will be the first segment
* to process events. Also note that segments <b>cannot be removed once added</b>. This is by design, as removing
* segments would give the pipeline runtime customizability, which it is not supposed to possess in the first
* place.
*
* @param toAdd is the segment that will be added to the pipeline
* @return the pipeline itself for chaining
*/

View File

@ -11,8 +11,8 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* The {@link RequestGameStateSegment} handles requests of {@link RequestType} Req.
* Therefore it sends the active gamestate and clears the {@link Packet} afterwards.
* The {@link RequestGameStateSegment} handles requests of {@link RequestType} Req. Therefore it sends the active
* gamestate and clears the {@link Packet} afterwards.
*/
public class RequestGameStateSegment implements Segment {

View File

@ -8,18 +8,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
public interface Segment {
/**
* Pipelining method to process a set of requests.
* The list of requests will be processed according to some set of rules. Hereby,
* the {@link Request Requests} in the packet will be filtered out as appropriate,
* whereby the resulting {@link Event Events} are appended to the carrier.
* @param packet is a {@link List} of {@link Request Requests} that is filtered
* by the {@link Segment} as appropriate
* @param carrier is a {@link List} of {@link Event Events} that is appended to
* if new requests are generated from the execution of the {@link Segment}
* @param abort is an {@link AtomicBoolean} describing whether an error has occurred during the execution of
* the {@link Segment} Note that <b>error</b> here does <b>not describe an execution error</b>
* of the segment, but instead an error in the events passed to it, like for example moving into a Rock.
* The conventional way of setting this boolean is to write {@code abort.set(true); return;}
* Pipelining method to process a set of requests. The list of requests will be processed according to some set of
* rules. Hereby, the {@link Request Requests} in the packet will be filtered out as appropriate, whereby the
* resulting {@link Event Events} are appended to the carrier.
*
* @param packet is a {@link List} of {@link Request Requests} that is filtered by the {@link Segment} as
* appropriate
* @param carrier is a {@link List} of {@link Event Events} that is appended to if new requests are generated from
* the execution of the {@link Segment}
* @param abort is an {@link AtomicBoolean} describing whether an error has occurred during the execution of the
* {@link Segment} Note that <b>error</b> here does <b>not describe an execution error</b> of the
* segment, but instead an error in the events passed to it, like for example moving into a Rock. The
* conventional way of setting this boolean is to write {@code abort.set(true); return;}
*/
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort);
}