Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class MovePlayersToGameException extends Exception
- {
- public MovePlayersToGameException(Collection<? extends PlayerAlreadyInGameException> alreadyInGame,
- Collection<? extends PlayerNotOnlineException> notOnline)
- {
- super();
- alreadyInGameExceptions = (Collection<PlayerAlreadyInGameException>)alreadyInGame;
- notOnlineExceptions = (Collection<PlayerNotOnlineException>)notOnline;
- }
- public MovePlayersToGameException(Collection<? extends PlayerAlreadyInGameException> alreadyInGame,
- Collection<? extends PlayerNotOnlineException> notOnline,
- String message)
- {
- super(message);
- alreadyInGameExceptions = (Collection<PlayerAlreadyInGameException>)alreadyInGame;
- notOnlineExceptions = (Collection<PlayerNotOnlineException>)notOnline;
- }
- public MovePlayersToGameException(Collection<? extends PlayerAlreadyInGameException> alreadyInGame,
- Collection<? extends PlayerNotOnlineException> notOnline,
- String message,
- Throwable cause)
- {
- super(message, cause);
- alreadyInGameExceptions = (Collection<PlayerAlreadyInGameException>)alreadyInGame;
- notOnlineExceptions = (Collection<PlayerNotOnlineException>)notOnline;
- }
- public MovePlayersToGameException(Collection<? extends PlayerAlreadyInGameException> alreadyInGame,
- Collection<? extends PlayerNotOnlineException> notOnline,
- Throwable cause)
- {
- super(cause);
- alreadyInGameExceptions = (Collection<PlayerAlreadyInGameException>)alreadyInGame;
- notOnlineExceptions = (Collection<PlayerNotOnlineException>)notOnline;
- }
- Collection<PlayerAlreadyInGameException> alreadyInGameExceptions;
- Collection<PlayerNotOnlineException> notOnlineExceptions;
- public Collection<PlayerAlreadyInGameException> getPlayerAlreadyInGameExceptions()
- { return new ArrayList<PlayerAlreadyInGameException>(alreadyInGameExceptions); }
- public Collection<PlayerNotOnlineException> getPlayerNotOnlineExceptions()
- { return new ArrayList<PlayerNotOnlineException>(notOnlineExceptions); }
- }
- ---------- Later down in the class -------------
- public boolean movePlayerToGame(Player player) throws PlayerNotOnlineException, PlayerAlreadyInGameException, GameNotInProgressException
- {
- if(!this.isInGame())
- throw new GameNotInProgressException();
- if(!player.isOnline())
- throw new PlayerNotOnlineException(player, "Cannot move player to game because player is not online.");
- synchronized(busyPlayersInGame)
- {
- if(this.playersInGame.contains(player))
- throw new PlayerAlreadyInGameException(player, "Player is already in game.");
- this.playersInGame.add(player);
- }
- synchronized(busyPlayersInLobby)
- { this.playersInLobby.remove(player); }
- this.currentStage.tpPlayersToStartingPositions(player);
- return true;
- }
- public Collection<Player> movePlayersToGame(Collection<? extends Player> players) throws GameNotInProgressException, MovePlayersToGameException
- {
- if(!this.isInGame())
- throw new GameNotInProgressException();
- Collection<Player> returnVals = new ArrayList<Player>();
- Collection<PlayerNotOnlineException> notOnlineExceptions = new ArrayList<PlayerNotOnlineException>();
- Collection<PlayerAlreadyInGameException> alreadyInGameExceptions = new ArrayList<PlayerAlreadyInGameException>();
- for(Player player : players)
- {
- try
- {
- if(!player.isOnline())
- throw new PlayerNotOnlineException(player, "Cannot move player to game because player is not online.");
- synchronized(busyPlayersInGame)
- {
- if(this.playersInGame.contains(player))
- throw new PlayerAlreadyInGameException(player, "Player is already in game.");
- this.playersInGame.add(player);
- }
- synchronized(busyPlayersInLobby)
- { this.playersInLobby.remove(player); }
- returnVals.add(player);
- }
- catch(PlayerNotOnlineException e)
- { notOnlineExceptions.add(e); }
- catch(PlayerAlreadyInGameException e)
- { alreadyInGameExceptions.add(e); }
- }
- this.currentStage.tpPlayersToStartingPositions(returnVals);
- if((!notOnlineExceptions.isEmpty()) || (!alreadyInGameExceptions.isEmpty()))
- throw new MovePlayersToGameException(alreadyInGameExceptions, notOnlineExceptions);
- return returnVals;
- }
Advertisement
Add Comment
Please, Sign In to add comment