use of com.ebicep.warlords.game.state.ClosedState in project Warlords by ebicep.
the class Game method run.
@Override
public void run() {
if (this.nextState == null && this.state != null) {
this.nextState = this.state.run();
}
while (this.nextState != null) {
for (GameAddon addon : this.addons) {
nextState = addon.stateWillChange(this, this.state, nextState);
if (nextState == null) {
return;
}
}
if (this.state != null) {
this.state.end();
}
State newState = nextState == null ? new ClosedState(this) : nextState;
nextState = null;
// System.out.println("DEBUG OLD TO NEW STATE");
// this.printDebuggingInformation();
State oldState = this.state;
this.state = newState;
newState.begin();
for (GameAddon addon : this.addons) {
addon.stateHasChanged(this, oldState, newState);
}
}
}
use of com.ebicep.warlords.game.state.ClosedState in project Warlords by ebicep.
the class Game method close.
@Override
public void close() {
if (this.closed) {
return;
}
this.closed = true;
List<Throwable> exceptions = new ArrayList<>();
for (BukkitTask task : gameTasks) {
task.cancel();
}
gameTasks.clear();
for (Listener listener : eventHandlers) {
HandlerList.unregisterAll(listener);
}
eventHandlers.clear();
try {
removeAllPlayers();
} catch (Throwable e) {
exceptions.add(e);
}
for (Option option : options) {
try {
option.onGameCleanup(this);
} catch (Throwable e) {
exceptions.add(e);
}
}
this.acceptsPlayers = false;
this.acceptsSpectators = false;
this.nextState = null;
if (this.state != null && !(this.state instanceof ClosedState)) {
try {
this.state.end();
} catch (Throwable e) {
exceptions.add(e);
}
this.state = new ClosedState(this);
}
this.options = Collections.emptyList();
if (!exceptions.isEmpty()) {
RuntimeException e = new RuntimeException("Problems closing the game", exceptions.get(0));
for (int i = 1; i < exceptions.size(); i++) {
e.addSuppressed(exceptions.get(i));
}
throw e;
}
}
Aggregations