Skip to content

Commit

Permalink
Add more state events.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattysweeps committed Mar 17, 2019
1 parent a96443d commit a173577
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginGroup=io.github.m0pt0pmatt.survivalgames
pluginId=survivalgames
pluginVersion=1.1.7
pluginVersion=1.1.8
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@Plugin(
id = "survival-games",
name = "Survival Games",
version = "1.1.7",
version = "1.1.8",
description = "Survival Games for Sponge.",
url = "https://github.com/mattysweeps/SurvivalGames"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.github.m0pt0pmatt.survivalgames.event;

import io.github.m0pt0pmatt.survivalgames.SurvivalGamesPlugin;
import io.github.m0pt0pmatt.survivalgames.game.SurvivalGame;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.EventContext;

public class GameDeathmatchEvent extends SurvivalGameEvent {
public GameDeathmatchEvent(SurvivalGame survivalGame) {
super(Cause.of(EventContext.empty(), SurvivalGamesPlugin.PLUGIN), survivalGame);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.m0pt0pmatt.survivalgames.event;

import io.github.m0pt0pmatt.survivalgames.game.SurvivalGame;
import io.github.m0pt0pmatt.survivalgames.game.SurvivalGameState;

public class GameReadyEvent extends GameStateChangedEvent {
public GameReadyEvent(SurvivalGame survivalGame,SurvivalGameState previousState) {
super(survivalGame, previousState, SurvivalGameState.READY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.m0pt0pmatt.survivalgames.event;

import io.github.m0pt0pmatt.survivalgames.game.SurvivalGame;
import io.github.m0pt0pmatt.survivalgames.game.SurvivalGameState;

public class GameStartedEvent extends GameStateChangedEvent {
public GameStartedEvent(SurvivalGame survivalGame, SurvivalGameState previousState) {
super(survivalGame, previousState, SurvivalGameState.RUNNING);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.m0pt0pmatt.survivalgames.event;

import io.github.m0pt0pmatt.survivalgames.game.SurvivalGame;
import io.github.m0pt0pmatt.survivalgames.game.SurvivalGameState;

public class GameStoppedEvent extends GameStateChangedEvent {
public GameStoppedEvent(SurvivalGame survivalGame, SurvivalGameState previousState) {
super(survivalGame, previousState, SurvivalGameState.STOPPED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package io.github.m0pt0pmatt.survivalgames.game;

import io.github.m0pt0pmatt.survivalgames.data.GameConfig;
import io.github.m0pt0pmatt.survivalgames.event.GameStateChangedEvent;
import io.github.m0pt0pmatt.survivalgames.event.*;
import io.github.m0pt0pmatt.survivalgames.task.*;
import io.github.m0pt0pmatt.survivalgames.task.player.*;
import org.spongepowered.api.Sponge;
Expand Down Expand Up @@ -87,10 +87,7 @@ public static void ready(SurvivalGame survivalGame) {
executeTasks(READY_TASKS, survivalGame);
survivalGame.state = SurvivalGameState.READY;
survivalGame.runningState = SurvivalGameRunningState.STOPPED;
Sponge.getEventManager()
.post(
new GameStateChangedEvent(
survivalGame, oldState, SurvivalGameState.READY));
Sponge.getEventManager().post(new GameReadyEvent(survivalGame, oldState));
} catch (TextMessageException e) {
e.printStackTrace();
}
Expand All @@ -103,10 +100,7 @@ public static void start(SurvivalGame survivalGame) {
executeTasks(START_TASKS, survivalGame);
survivalGame.state = SurvivalGameState.RUNNING;
survivalGame.runningState = SurvivalGameRunningState.IN_PROGRESS;
Sponge.getEventManager()
.post(
new GameStateChangedEvent(
survivalGame, oldState, SurvivalGameState.RUNNING));
Sponge.getEventManager().post(new GameStartedEvent(survivalGame, oldState));
} catch (TextMessageException e) {
e.printStackTrace();
}
Expand All @@ -117,6 +111,7 @@ public static void deathMatch(SurvivalGame survivalGame) {
executeTasks(DEATH_MATCH_TASKS, survivalGame);
survivalGame.state = SurvivalGameState.RUNNING;
survivalGame.runningState = SurvivalGameRunningState.DEATH_MATCH;
Sponge.getEventManager().post(new GameDeathmatchEvent(survivalGame));
} catch (TextMessageException e) {
e.printStackTrace();
}
Expand All @@ -128,10 +123,7 @@ public static void stop(SurvivalGame survivalGame) {
executeTasks(STOP_TASKS, survivalGame);
survivalGame.state = SurvivalGameState.STOPPED;
survivalGame.runningState = SurvivalGameRunningState.STOPPED;
Sponge.getEventManager()
.post(
new GameStateChangedEvent(
survivalGame, oldState, SurvivalGameState.STOPPED));
Sponge.getEventManager().post(new GameStoppedEvent(survivalGame, oldState));
} catch (TextMessageException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit a173577

Please sign in to comment.