use of com.voxelgameslib.voxelgameslib.api.feature.FeatureCommandImplementor in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractPhase method disable.
@Override
public void disable() {
// disable timer
duration = Duration.between(startTime, LocalDateTime.now());
log.finer("disable phase " + getName());
// only disable features that have been started to avoid errors
for (Feature feature : startedFeatures) {
log.finer("disable " + feature.getName());
try {
feature.disable();
} catch (Exception ex) {
log.severe("error while stopping " + feature.getName());
ex.printStackTrace();
return;
}
if (feature instanceof Listener) {
eventHandler.unregister((Listener) feature, getGame());
}
if (feature instanceof FeatureCommandImplementor) {
AbstractFeatureCommand cmd = injector.getInstance(((FeatureCommandImplementor) feature).getCommandClass());
commandHandler.unregister(cmd, this);
}
}
for (VictoryCondition victoryCondition : victoryConditions) {
if (victoryCondition instanceof Listener) {
eventHandler.registerEvents((Listener) victoryCondition, getGame());
}
}
phaseTickables.values().forEach(tickable -> {
tickable.disable();
if (tickable instanceof Ability) {
((Ability) tickable).unregister();
}
});
startedFeatures.clear();
}
use of com.voxelgameslib.voxelgameslib.api.feature.FeatureCommandImplementor in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractPhase method enable.
@Override
public void enable() {
phaseTiming = timingManager.of("Phase::Tickables::" + getName());
if (!checkDependencies()) {
game.abortGame();
return;
}
if (!checkVictoryConditionDependencies()) {
game.abortGame();
return;
}
if (victoryConditions.size() == 0) {
addVictoryCondition(getGame().createVictoryCondition(EmptyVictoryCondition.class, this));
}
// check for spec feature
if (allowSpectate && !getOptionalFeature(SpectatorFeature.class).isPresent()) {
log.warning(getName() + " does allow spectators but doesn't use the spectator feature! Did you forget to add it?");
}
// enable timer
startTime = LocalDateTime.now();
log.finer("enable phase" + getName());
phaseTickables.values().forEach(Tickable::enable);
for (Feature feature : features) {
if (game.isAborting()) {
return;
}
log.finer("enable " + feature.getName());
try {
feature.enable();
} catch (Exception ex) {
log.severe("error while starting " + feature.getName());
ex.printStackTrace();
game.abortGame();
return;
}
if (feature instanceof Listener) {
eventHandler.registerEvents((Listener) feature, getGame());
}
if (feature instanceof FeatureCommandImplementor) {
AbstractFeatureCommand cmd = injector.getInstance(((FeatureCommandImplementor) feature).getCommandClass());
// noinspection unchecked
cmd.setFeature(feature);
commandHandler.register(cmd, this);
}
startedFeatures.add(feature);
}
for (VictoryCondition victoryCondition : victoryConditions) {
if (victoryCondition instanceof Listener) {
eventHandler.registerEvents((Listener) victoryCondition, getGame());
}
}
}
Aggregations