summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/luxons/sevenwonders/controllers/GameController.java8
-rw-r--r--src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java18
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Game.java18
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Lobby.java24
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Player.java10
-rw-r--r--src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java36
-rw-r--r--src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java24
7 files changed, 69 insertions, 69 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/controllers/GameController.java b/src/main/java/org/luxons/sevenwonders/controllers/GameController.java
index 0bb3eb23..0deac4a3 100644
--- a/src/main/java/org/luxons/sevenwonders/controllers/GameController.java
+++ b/src/main/java/org/luxons/sevenwonders/controllers/GameController.java
@@ -48,16 +48,16 @@ public class GameController {
private void sendPreparedCard(PreparedCard preparedCard, Game game) {
for (Player player : game.getPlayers()) {
- String userName = player.getUserName();
- template.convertAndSendToUser(userName, "/topic/game/" + game.getId() + "/prepared", preparedCard);
+ String username = player.getUsername();
+ template.convertAndSendToUser(username, "/topic/game/" + game.getId() + "/prepared", preparedCard);
}
}
private void sendTurnInfo(Game game) {
List<PlayerTurnInfo> turnInfos = game.getTurnInfo();
for (PlayerTurnInfo turnInfo : turnInfos) {
- String userName = turnInfo.getPlayer().getUserName();
- template.convertAndSendToUser(userName, "/topic/game/" + game.getId() + "/turn", turnInfo);
+ String username = turnInfo.getPlayer().getUsername();
+ template.convertAndSendToUser(username, "/topic/game/" + game.getId() + "/turn", turnInfo);
}
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
index 1664d05e..020576bc 100644
--- a/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
+++ b/src/main/java/org/luxons/sevenwonders/controllers/LobbyController.java
@@ -52,10 +52,10 @@ public class LobbyController {
@MessageMapping("/chooseName")
@SendToUser("/queue/nameChoice")
public Player chooseName(@Validated ChooseNameAction action, Principal principal) {
- String userName = principal.getName();
- Player player = playerRepository.updateOrCreatePlayer(userName, action.getPlayerName());
+ String username = principal.getName();
+ Player player = playerRepository.updateOrCreatePlayer(username, action.getPlayerName());
- logger.info("Player '{}' chose the name '{}'", userName, player.getDisplayName());
+ logger.info("Player '{}' chose the name '{}'", username, player.getDisplayName());
return player;
}
@@ -75,7 +75,7 @@ public class LobbyController {
gameOwner.setLobby(lobby);
logger.info("Game '{}' ({}) created by {} ({})", lobby.getName(), lobby.getId(), gameOwner.getDisplayName(),
- gameOwner.getUserName());
+ gameOwner.getUsername());
return Collections.singletonList(lobby);
}
@@ -89,7 +89,7 @@ public class LobbyController {
lobby.addPlayer(newPlayer);
newPlayer.setLobby(lobby);
- logger.info("Player '{}' ({}) joined game {}", newPlayer.getDisplayName(), newPlayer.getUserName(),
+ logger.info("Player '{}' ({}) joined game {}", newPlayer.getDisplayName(), newPlayer.getUsername(),
lobby.getName());
sendLobbyUpdateToPlayers(lobby);
return lobby;
@@ -151,14 +151,14 @@ public class LobbyController {
}
private static class UserNotInLobbyException extends ApiMisuseException {
- UserNotInLobbyException(String userName) {
- super("User " + userName + " is not in a lobby, create or join a game first");
+ UserNotInLobbyException(String username) {
+ super("User " + username + " is not in a lobby, create or join a game first");
}
}
private static class UserIsNotOwnerException extends ApiMisuseException {
- UserIsNotOwnerException(String userName) {
- super("User " + userName + " does not own the lobby he's in");
+ UserIsNotOwnerException(String username) {
+ super("User " + username + " does not own the lobby he's in");
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Game.java b/src/main/java/org/luxons/sevenwonders/game/Game.java
index bc9c3b17..8aa7d1b9 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Game.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Game.java
@@ -55,8 +55,8 @@ public class Game {
return id;
}
- public boolean containsUser(String userName) {
- return players.stream().anyMatch(p -> p.getUserName().equals(userName));
+ public boolean containsUser(String username) {
+ return players.stream().anyMatch(p -> p.getUsername().equals(username));
}
public List<Player> getPlayers() {
@@ -96,8 +96,8 @@ public class Game {
}
}
- public PreparedCard prepareCard(String userName, PlayerMove playerMove) throws InvalidMoveException {
- Player player = getPlayer(userName);
+ public PreparedCard prepareCard(String username, PlayerMove playerMove) throws InvalidMoveException {
+ Player player = getPlayer(username);
Card card = decks.getCard(playerMove.getCardName());
Move move = playerMove.getType().resolve(player.getIndex(), card, playerMove);
validate(move);
@@ -105,11 +105,11 @@ public class Game {
return new PreparedCard(player, card.getBack());
}
- private Player getPlayer(String userName) {
+ private Player getPlayer(String username) {
return players.stream()
- .filter(p -> p.getUserName().equals(userName))
+ .filter(p -> p.getUsername().equals(username))
.findAny()
- .orElseThrow(() -> new UnknownPlayerException(userName));
+ .orElseThrow(() -> new UnknownPlayerException(username));
}
private void validate(Move move) throws InvalidMoveException {
@@ -222,8 +222,8 @@ public class Game {
}
private static class UnknownPlayerException extends IllegalArgumentException {
- UnknownPlayerException(String userName) {
- super(userName);
+ UnknownPlayerException(String username) {
+ super(username);
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Lobby.java b/src/main/java/org/luxons/sevenwonders/game/Lobby.java
index c0201438..6975349a 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Lobby.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Lobby.java
@@ -90,29 +90,29 @@ public class Lobby {
return players.size() >= gameDefinition.getMinPlayers();
}
- public void reorderPlayers(List<String> orderedUserNames) {
+ public void reorderPlayers(List<String> orderedUsernames) {
List<Player> formerList = new ArrayList<>(players);
players.clear();
- for (int i = 0; i < orderedUserNames.size(); i++) {
- Player player = getPlayer(formerList, orderedUserNames.get(i));
+ for (int i = 0; i < orderedUsernames.size(); i++) {
+ Player player = getPlayer(formerList, orderedUsernames.get(i));
players.add(player);
player.setIndex(i);
}
}
- private static Player getPlayer(List<Player> players, String userName) {
+ private static Player getPlayer(List<Player> players, String username) {
return players.stream()
- .filter(p -> p.getUserName().equals(userName))
+ .filter(p -> p.getUsername().equals(username))
.findAny()
- .orElseThrow(() -> new UnknownPlayerException(userName));
+ .orElseThrow(() -> new UnknownPlayerException(username));
}
- public boolean isOwner(String userName) {
- return owner.getUserName().equals(userName);
+ public boolean isOwner(String username) {
+ return owner.getUsername().equals(username);
}
- public boolean containsUser(String userName) {
- return players.stream().anyMatch(p -> p.getUserName().equals(userName));
+ public boolean containsUser(String username) {
+ return players.stream().anyMatch(p -> p.getUsername().equals(username));
}
static class GameAlreadyStartedException extends IllegalStateException {
@@ -131,8 +131,8 @@ public class Lobby {
}
static class UnknownPlayerException extends IllegalArgumentException {
- UnknownPlayerException(String userName) {
- super(userName);
+ UnknownPlayerException(String username) {
+ super(username);
}
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/Player.java b/src/main/java/org/luxons/sevenwonders/game/Player.java
index c8c1509c..f1095049 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Player.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Player.java
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
public class Player {
- private final String userName;
+ private final String username;
private String displayName;
@@ -14,13 +14,13 @@ public class Player {
private transient Game game;
- public Player(String userName, String displayName) {
- this.userName = userName;
+ public Player(String username, String displayName) {
+ this.username = username;
this.displayName = displayName;
}
- public String getUserName() {
- return userName;
+ public String getUsername() {
+ return username;
}
public String getDisplayName() {
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
index 76df13b4..f6c29d83 100644
--- a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
+++ b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
@@ -12,50 +12,50 @@ public class PlayerRepository {
private Map<String, Player> players = new HashMap<>();
- public Player updateOrCreatePlayer(String userName, String displayName) {
- if (players.containsKey(userName)) {
- return updatePlayerName(userName, displayName);
+ public Player updateOrCreatePlayer(String username, String displayName) {
+ if (players.containsKey(username)) {
+ return updatePlayerName(username, displayName);
} else {
- return createPlayer(userName, displayName);
+ return createPlayer(username, displayName);
}
}
- private Player createPlayer(String userName, String displayName) throws PlayerAlreadyExistsException {
- Player player = new Player(userName, displayName);
+ private Player createPlayer(String username, String displayName) throws PlayerAlreadyExistsException {
+ Player player = new Player(username, displayName);
add(player);
return player;
}
private void add(Player player) throws PlayerAlreadyExistsException {
- if (players.containsKey(player.getUserName())) {
- throw new PlayerAlreadyExistsException(player.getUserName());
+ if (players.containsKey(player.getUsername())) {
+ throw new PlayerAlreadyExistsException(player.getUsername());
}
- players.put(player.getUserName(), player);
+ players.put(player.getUsername(), player);
}
- private Player updatePlayerName(String userName, String displayName) throws PlayerNotFoundException {
- Player player = find(userName);
+ private Player updatePlayerName(String username, String displayName) throws PlayerNotFoundException {
+ Player player = find(username);
player.setDisplayName(displayName);
return player;
}
- public Player find(String userName) throws PlayerNotFoundException {
- Player player = players.get(userName);
+ public Player find(String username) throws PlayerNotFoundException {
+ Player player = players.get(username);
if (player == null) {
- throw new PlayerNotFoundException(userName);
+ throw new PlayerNotFoundException(username);
}
return player;
}
public static class PlayerNotFoundException extends ApiMisuseException {
- PlayerNotFoundException(String userName) {
- super("Player '" + userName + "' doesn't exist");
+ PlayerNotFoundException(String username) {
+ super("Player '" + username + "' doesn't exist");
}
}
private static class PlayerAlreadyExistsException extends ApiMisuseException {
- PlayerAlreadyExistsException(String userName) {
- super("Player '" + userName + "' already exists");
+ PlayerAlreadyExistsException(String username) {
+ super("Player '" + username + "' already exists");
}
}
}
diff --git a/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java b/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
index 64f14dee..65b3623c 100644
--- a/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
+++ b/src/main/java/org/luxons/sevenwonders/validation/DestinationAccessValidator.java
@@ -27,46 +27,46 @@ public class DestinationAccessValidator {
this.gameRepository = gameRepository;
}
- public boolean hasAccess(String userName, String destination) {
- if (userName == null) {
+ public boolean hasAccess(String username, String destination) {
+ if (username == null) {
// unnamed user cannot belong to anything
return false;
}
- if (hasForbiddenGameReference(userName, destination)) {
+ if (hasForbiddenGameReference(username, destination)) {
return false;
}
- if (hasForbiddenLobbyReference(userName, destination)) {
+ if (hasForbiddenLobbyReference(username, destination)) {
return false;
}
return true;
}
- private boolean hasForbiddenGameReference(String userName, String destination) {
+ private boolean hasForbiddenGameReference(String username, String destination) {
Matcher gameMatcher = gameDestination.matcher(destination);
if (!gameMatcher.matches()) {
return false; // no game reference is always OK
}
int gameId = extractId(gameMatcher);
- return !isUserInGame(userName, gameId);
+ return !isUserInGame(username, gameId);
}
- private boolean hasForbiddenLobbyReference(String userName, String destination) {
+ private boolean hasForbiddenLobbyReference(String username, String destination) {
Matcher lobbyMatcher = lobbyDestination.matcher(destination);
if (!lobbyMatcher.matches()) {
return false; // no lobby reference is always OK
}
int lobbyId = extractId(lobbyMatcher);
- return !isUserInLobby(userName, lobbyId);
+ return !isUserInLobby(username, lobbyId);
}
- private boolean isUserInGame(String userName, int gameId) {
+ private boolean isUserInGame(String username, int gameId) {
Game game = gameRepository.find(gameId);
- return game.containsUser(userName);
+ return game.containsUser(username);
}
- private boolean isUserInLobby(String userName, int lobbyId) {
+ private boolean isUserInLobby(String username, int lobbyId) {
Lobby lobby = lobbyRepository.find(lobbyId);
- return lobby.containsUser(userName);
+ return lobby.containsUser(username);
}
private static int extractId(Matcher matcher) {
bgstack15