refactor: formatted Lobby files properly
This commit is contained in:
parent
c24121b6d9
commit
16c425c507
@ -30,9 +30,9 @@ public class Lobby {
|
|||||||
private final TurnTimer turnTimer;
|
private final TurnTimer turnTimer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Lobby} is where the magic happens.
|
* The {@link Lobby} is where the magic happens. In this class is a whole {@link GameInstance game} is processed. To
|
||||||
* In this class is a whole {@link GameInstance game} is processed.
|
* initialize the game it gets the following parameters
|
||||||
* To initialize the game it gets the following parameters
|
*
|
||||||
* @param gameID a String to identify the game
|
* @param gameID a String to identify the game
|
||||||
* @param connection the Connection to the {@link uulm.teamname.marvelous.server.lobbymanager.LobbyManager}
|
* @param connection the Connection to the {@link uulm.teamname.marvelous.server.lobbymanager.LobbyManager}
|
||||||
* @param partyConfig declared in Editor
|
* @param partyConfig declared in Editor
|
||||||
@ -84,6 +84,7 @@ public class Lobby {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by {@link LobbyConnection} to handle requests
|
* Called by {@link LobbyConnection} to handle requests
|
||||||
|
*
|
||||||
* @param requests to be processed
|
* @param requests to be processed
|
||||||
* @param source the player executing the requests
|
* @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.
|
* This method is called at the end of receiveRequests, to start a timer. The active player has now a specific
|
||||||
* The active player has now a specific amount of time to do his moves.
|
* amount of time to do his moves.
|
||||||
*/
|
*/
|
||||||
void updateTimer() {
|
void updateTimer() {
|
||||||
var currentActiveCharacterType = game.state.getActiveCharacter().type;
|
var currentActiveCharacterType = game.state.getActiveCharacter().type;
|
||||||
@ -151,6 +152,7 @@ public class Lobby {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the player executed a false request the request gets rejected.
|
* If the player executed a false request the request gets rejected.
|
||||||
|
*
|
||||||
* @param source the executing player
|
* @param source the executing player
|
||||||
*/
|
*/
|
||||||
private void reject(Participant source) {
|
private void reject(Participant source) {
|
||||||
@ -161,8 +163,7 @@ public class Lobby {
|
|||||||
connection.removeParticipant(source);
|
connection.removeParticipant(source);
|
||||||
if (connection.hasPlayer1()) {
|
if (connection.hasPlayer1()) {
|
||||||
generateWin(connection.getPlayer1());
|
generateWin(connection.getPlayer1());
|
||||||
}
|
} else if (connection.hasPlayer2()) {
|
||||||
else if(connection.hasPlayer2()) {
|
|
||||||
generateWin(connection.getPlayer2());
|
generateWin(connection.getPlayer2());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,6 +171,7 @@ public class Lobby {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Warns the player he get timeouted soon.
|
* Warns the player he get timeouted soon.
|
||||||
|
*
|
||||||
* @param source soon to be timeouted player
|
* @param source soon to be timeouted player
|
||||||
*/
|
*/
|
||||||
public synchronized void soonTimeout(Participant source) {
|
public synchronized void soonTimeout(Participant source) {
|
||||||
@ -180,6 +182,7 @@ public class Lobby {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If a player times out the other player automatically wins.
|
* If a player times out the other player automatically wins.
|
||||||
|
*
|
||||||
* @param source is the timeouted player
|
* @param source is the timeouted player
|
||||||
*/
|
*/
|
||||||
public synchronized void timeout(Participant source) {
|
public synchronized void timeout(Participant source) {
|
||||||
@ -190,11 +193,9 @@ public class Lobby {
|
|||||||
|
|
||||||
if (connection.hasPlayer1() && !connection.hasPlayer2()) {
|
if (connection.hasPlayer1() && !connection.hasPlayer2()) {
|
||||||
generateWin(connection.getPlayer1());
|
generateWin(connection.getPlayer1());
|
||||||
}
|
} else if (!connection.hasPlayer1() && connection.hasPlayer2()) {
|
||||||
else if(!connection.hasPlayer1() && connection.hasPlayer2()) {
|
|
||||||
generateWin(connection.getPlayer2());
|
generateWin(connection.getPlayer2());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Spectator was time-outed which is impossible");
|
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}.
|
* The method generates a Win event for a {@link Participant}. Afterwards it sends a Disconnect to everyone, and
|
||||||
* Afterwards it sends a Disconnect to everyone, and terminates the connection.
|
* terminates the connection.
|
||||||
*
|
*
|
||||||
* @param winner is the {@link Participant} that won
|
* @param winner is the {@link Participant} that won
|
||||||
*/
|
*/
|
||||||
|
@ -34,6 +34,7 @@ public class TurnTimer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method checks if the participant is not a spectator. Otherwise it won't start a timer.
|
* This method checks if the participant is not a spectator. Otherwise it won't start a timer.
|
||||||
|
*
|
||||||
* @param participant the timer is for
|
* @param participant the timer is for
|
||||||
*/
|
*/
|
||||||
public void startTurnTimer(Participant participant) {
|
public void startTurnTimer(Participant participant) {
|
||||||
@ -44,7 +45,10 @@ public class TurnTimer {
|
|||||||
clear();
|
clear();
|
||||||
Logger.debug("Starting turn timer for participant '{}' with role {}",
|
Logger.debug("Starting turn timer for participant '{}' with role {}",
|
||||||
participant.name, participant.type);
|
participant.name, participant.type);
|
||||||
current = timer.schedule(() -> {callback.accept(participant); return participant;},
|
current = timer.schedule(() -> {
|
||||||
|
callback.accept(participant);
|
||||||
|
return participant;
|
||||||
|
},
|
||||||
maxRoundTime,
|
maxRoundTime,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import java.util.List;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link DisconnectSegment} handles requests of {@link RequestType} DisconnectRequest.
|
* The {@link DisconnectSegment} handles requests of {@link RequestType} DisconnectRequest. Therefore it removes the
|
||||||
* Therefore it removes the disconnecting player-connection from the {@link Lobby}.
|
* disconnecting player-connection from the {@link Lobby}.
|
||||||
*/
|
*/
|
||||||
public class DisconnectSegment implements Segment {
|
public class DisconnectSegment implements Segment {
|
||||||
|
|
||||||
@ -31,8 +31,7 @@ public class DisconnectSegment implements Segment {
|
|||||||
if (packet.getOrigin().type != ParticipantType.Spectator) {
|
if (packet.getOrigin().type != ParticipantType.Spectator) {
|
||||||
if (parent.getConnection().hasPlayer1()) {
|
if (parent.getConnection().hasPlayer1()) {
|
||||||
parent.generateWin(parent.getConnection().getPlayer1());
|
parent.generateWin(parent.getConnection().getPlayer1());
|
||||||
}
|
} else if (parent.getConnection().hasPlayer2()) {
|
||||||
else if(parent.getConnection().hasPlayer2()) {
|
|
||||||
parent.generateWin(parent.getConnection().getPlayer2());
|
parent.generateWin(parent.getConnection().getPlayer2());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import java.util.List;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link GameStateSegment} handles all {@link GameInstance game} relevant {@link Request Requests}.
|
* The {@link GameStateSegment} handles all {@link GameInstance game} relevant {@link Request Requests}. Therefore it
|
||||||
* Therefore it updates the game with the matching request.
|
* updates the game with the matching request.
|
||||||
*/
|
*/
|
||||||
public class GameStateSegment implements Segment {
|
public class GameStateSegment implements Segment {
|
||||||
private GameInstance game;
|
private GameInstance game;
|
||||||
|
@ -7,8 +7,8 @@ import uulm.teamname.marvelous.server.lobbymanager.Participant;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Packet} contains all {@link Request Requests} and the belonging {@link Participant}.
|
* The {@link Packet} contains all {@link Request Requests} and the belonging {@link Participant}. You can add and
|
||||||
* You can add and remove {@link Request Requests} at will.
|
* remove {@link Request Requests} at will.
|
||||||
*/
|
*/
|
||||||
public class Packet extends ArrayList<Request> {
|
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
|
* This method checks if a {@link RequestType} is part of the {@link Packet} or not
|
||||||
|
*
|
||||||
* @param requiredType RequestType to check.
|
* @param requiredType RequestType to check.
|
||||||
* @return boolean
|
* @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}.
|
* This method removes all {@link Request Requests} of given {@link RequestType types} from the {@link Packet}.
|
||||||
|
*
|
||||||
* @param types RequestType(s) to remove
|
* @param types RequestType(s) to remove
|
||||||
*/
|
*/
|
||||||
public void removeRequestsOfTypes(RequestType... types) {
|
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
|
* @param types RequestType(s) to not remove
|
||||||
*/
|
*/
|
||||||
public void removeRequestsNotOfTypes(RequestType... types) {
|
public void removeRequestsNotOfTypes(RequestType... types) {
|
||||||
|
@ -22,9 +22,7 @@ public class PauseSegment implements Segment {
|
|||||||
paused = false;
|
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() {
|
public void pauseGame() {
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
paused = true;
|
paused = true;
|
||||||
@ -48,8 +46,8 @@ public class PauseSegment implements Segment {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pipelining method to process a set of requests.
|
* Pipelining method to process a set of requests. The list of requests will be processed according to the following
|
||||||
* The list of requests will be processed according to the following rules:
|
* rules:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>If there is a PauseStartRequest, the paused value will be set to true</li>
|
* <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:
|
* <li>Any CharacterRequests will be removed from the requests if the game is paused. These include:
|
||||||
|
@ -9,8 +9,8 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Pipeline} class pipelines {@link Request Requests} through {@link Segment Segments} to
|
* The {@link Pipeline} class pipelines {@link Request Requests} through {@link Segment Segments} to create {@link Event
|
||||||
* create {@link Event Events}. To add functionality without dabbling in the game library, create a new {@link Segment}.
|
* Events}. To add functionality without dabbling in the game library, create a new {@link Segment}.
|
||||||
*/
|
*/
|
||||||
public class Pipeline {
|
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.
|
* Pipeline the {@link Request Requests} through all {@link Segment Segments} that are in the pipeline. The {@link
|
||||||
* The {@link Request Requests} are declared as the <b>Packet</b>. The {@link Request Requests} are filtered
|
* Request Requests} are declared as the <b>Packet</b>. The {@link Request Requests} are filtered by each {@link
|
||||||
* by each {@link Segment segment}, whereby each {@link Segment segment} takes (and thereby removes) all
|
* Segment segment}, whereby each {@link Segment segment} takes (and thereby removes) all {@link Event events}
|
||||||
* {@link Event events} relevant to the {@link Segment segment}. The {@link Event Events} are returned at the
|
* relevant to the {@link Segment segment}. The {@link Event Events} are returned at the end of the pipeline.
|
||||||
* end of the pipeline.
|
*
|
||||||
* @param requests are the requests that are being pipelined through 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
|
* @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
|
* execution of the {@link Pipeline} was successful. <b>If the optional is empty, the input requests were invalid,
|
||||||
* invalid, and an error message can be sent to the client</b>. To get the {@link Event Events}
|
* and an error message can be sent to the client</b>. To get the {@link Event Events} out of the {@link Optional},
|
||||||
* out of the {@link Optional}, first check whether the {@link Optional} is empty by doing
|
* first check whether the {@link Optional} is empty by doing {@link Optional#isEmpty()} or {@link
|
||||||
* {@link Optional#isEmpty()} or {@link Optional#isPresent()}, and act accordingly.
|
* Optional#isPresent()}, and act accordingly.
|
||||||
*/
|
*/
|
||||||
public Optional<List<Event>> processRequests(Request[] requests, Participant origin) {
|
public Optional<List<Event>> processRequests(Request[] requests, Participant origin) {
|
||||||
Logger.trace("Pipeline started RequestProcessing");
|
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
|
* Adds a segment to the pipeline. Note that <b>ORDER MATTERS!</b> The first segment added will be the first segment
|
||||||
* first segment to process events. Also note that segments <b>cannot be removed once added</b>. This is by
|
* to process events. Also note that segments <b>cannot be removed once added</b>. This is by design, as removing
|
||||||
* design, as removing segments would give the pipeline runtime customizability, which it is not supposed to
|
* segments would give the pipeline runtime customizability, which it is not supposed to possess in the first
|
||||||
* possess in the first place.
|
* place.
|
||||||
|
*
|
||||||
* @param toAdd is the segment that will be added to the pipeline
|
* @param toAdd is the segment that will be added to the pipeline
|
||||||
* @return the pipeline itself for chaining
|
* @return the pipeline itself for chaining
|
||||||
*/
|
*/
|
||||||
|
@ -11,8 +11,8 @@ import java.util.List;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link RequestGameStateSegment} handles requests of {@link RequestType} Req.
|
* The {@link RequestGameStateSegment} handles requests of {@link RequestType} Req. Therefore it sends the active
|
||||||
* Therefore it sends the active gamestate and clears the {@link Packet} afterwards.
|
* gamestate and clears the {@link Packet} afterwards.
|
||||||
*/
|
*/
|
||||||
public class RequestGameStateSegment implements Segment {
|
public class RequestGameStateSegment implements Segment {
|
||||||
|
|
||||||
|
@ -8,18 +8,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
|
|
||||||
public interface Segment {
|
public interface Segment {
|
||||||
/**
|
/**
|
||||||
* Pipelining method to process a set of requests.
|
* Pipelining method to process a set of requests. The list of requests will be processed according to some set of
|
||||||
* The list of requests will be processed according to some set of rules. Hereby,
|
* rules. Hereby, the {@link Request Requests} in the packet will be filtered out as appropriate, whereby the
|
||||||
* the {@link Request Requests} in the packet will be filtered out as appropriate,
|
* resulting {@link Event Events} are appended to the carrier.
|
||||||
* whereby the resulting {@link Event Events} are appended to the carrier.
|
*
|
||||||
* @param packet is a {@link List} of {@link Request Requests} that is filtered
|
* @param packet is a {@link List} of {@link Request Requests} that is filtered by the {@link Segment} as
|
||||||
* by the {@link Segment} as appropriate
|
* appropriate
|
||||||
* @param carrier is a {@link List} of {@link Event Events} that is appended to
|
* @param carrier is a {@link List} of {@link Event Events} that is appended to if new requests are generated from
|
||||||
* if new requests are generated from the execution of the {@link Segment}
|
* the execution of the {@link Segment}
|
||||||
* @param abort is an {@link AtomicBoolean} describing whether an error has occurred during the execution of
|
* @param abort is an {@link AtomicBoolean} describing whether an error has occurred during the execution of the
|
||||||
* the {@link Segment} Note that <b>error</b> here does <b>not describe an execution error</b>
|
* {@link Segment} Note that <b>error</b> here does <b>not describe an execution error</b> of the
|
||||||
* of the segment, but instead an error in the events passed to it, like for example moving into a Rock.
|
* segment, but instead an error in the events passed to it, like for example moving into a Rock. The
|
||||||
* The conventional way of setting this boolean is to write {@code abort.set(true); return;}
|
* conventional way of setting this boolean is to write {@code abort.set(true); return;}
|
||||||
*/
|
*/
|
||||||
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort);
|
public void processRequests(Packet packet, List<Event> carrier, AtomicBoolean abort);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user