public class AbstractGame<P extends Player> implements IGameInstance
public AbstractGame(@NotNull
java.lang.String pluginUUID)
pluginUUID - Used for generating replay name.@NotNull public java.util.List<P> getPlayers()
@Nullable public P getActivePlayer()
protected void setActivePlayer(@Nullable
P p)
@NotNull protected java.util.List<sc.api.plugins.host.IGameListener> getListeners()
public boolean isPaused()
public void setPaused(boolean p)
public void afterPause()
public void onAction(@NotNull
Player fromPlayer,
@NotNull
ProtocolMessage data)
Called by the Server once an action was received.
fromPlayer - The player who invoked this action.data - The plugin-specific data.GameLogicException - if no move has been requested from the given class PlayerInvalidMoveException - when the given Move is not possiblepublic void onRoundBasedAction(@NotNull
Player fromPlayer,
@NotNull
ProtocolMessage data)
Called by onAction to execute a move of a Player.
onAction@Nullable public WinCondition checkWinCondition()
Returns a WinCondition if the Game is over. Checks:
if a win condition in the current game state is met
round limit and end of round (and playerStats)
whether goal is reached
public void destroy()
At any time this method might be invoked by the server. Any open handles should be removed. No events should be sent out (GameOver etc) after this method has been called.
public void start()
Starts the game by sending a class WelcomeMessage to all players and calling next.
class WelcomeMessage,
nextpublic void onPlayerLeft(@NotNull
Player player,
@Nullable
ScoreCause cause)
Handle leave of a player.
player - the player that left.cause - the cause for the leave. If none is provided, then it will either be {@link ScoreCause#RULE_VIOLATION} or {$link ScoreCause#LEFT}, depending on whether the player has {@link Player#hasViolated()}.protected void next(@Nullable
P nextPlayer)
Advances the Game to nextPlayer.
sends out a state update
invokes notifyOnGameOver if the game is over
updates activePlayer to nextPlayer
requests a new move if isPaused is false
nextPlayer,
notifyOnGameOver,
activePlayer,
nextPlayer,
isPaused@NotNull public PlayerScore getScoreFor(@NotNull P player)
@NotNull public IGameState getCurrentState()
protected void notifyActivePlayer()
Notifies the active player that it's their time to make a move.
protected void requestMove(@NotNull
P player)
Sends a MoveRequest directly to the given player. Does not consider the pause state.
@NotNull protected ActionTimeout getTimeoutFor(@NotNull P player)
@NotNull public java.util.Map<sc.framework.plugins.Player,sc.shared.PlayerScore> generateScoreMap()
public void addGameListener(@NotNull
IGameListener listener)
Extends the set of listeners.
listener - GameListener to be addedpublic void removeGameListener(@NotNull
IGameListener listener)
Removes listener
listener - GameListener to be removedprotected void notifyOnGameOver(@NotNull
java.util.Map<sc.framework.plugins.Player,sc.shared.PlayerScore> map)
protected void notifyOnNewState(@NotNull
IGameState mementoState,
boolean observersOnly)
@NotNull public java.lang.String getPluginUUID()
Used for generating replay name.