Search in sources :

Example 1 with Tickable

use of com.voxelgameslib.voxelgameslib.tick.Tickable in project VoxelGamesLibv2 by VoxelGamesLib.

the class AbstractPhase method enable.

@Override
public void enable() {
    if (!checkDependencies()) {
        game.abortGame();
        return;
    }
    if (!checkVictoryConditionDependencies()) {
        game.abortGame();
        return;
    }
    if (victoryConditions.size() == 0) {
        addVictoryCondition(getGame().createVictoryCondition(EmptyVictoryCondition.class, this));
    }
    // 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());
        }
    }
}
Also used : EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition) Listener(org.bukkit.event.Listener) Tickable(com.voxelgameslib.voxelgameslib.tick.Tickable) FeatureCommandImplementor(com.voxelgameslib.voxelgameslib.feature.FeatureCommandImplementor) VictoryCondition(com.voxelgameslib.voxelgameslib.condition.VictoryCondition) EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition) Feature(com.voxelgameslib.voxelgameslib.feature.Feature) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) NoSuchFeatureException(com.voxelgameslib.voxelgameslib.exception.NoSuchFeatureException) DependencyGraphException(com.voxelgameslib.voxelgameslib.exception.DependencyGraphException) AbstractFeatureCommand(com.voxelgameslib.voxelgameslib.feature.AbstractFeatureCommand)

Aggregations

VictoryCondition (com.voxelgameslib.voxelgameslib.condition.VictoryCondition)1 EmptyVictoryCondition (com.voxelgameslib.voxelgameslib.condition.conditions.EmptyVictoryCondition)1 DependencyGraphException (com.voxelgameslib.voxelgameslib.exception.DependencyGraphException)1 NoSuchFeatureException (com.voxelgameslib.voxelgameslib.exception.NoSuchFeatureException)1 VoxelGameLibException (com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException)1 AbstractFeatureCommand (com.voxelgameslib.voxelgameslib.feature.AbstractFeatureCommand)1 Feature (com.voxelgameslib.voxelgameslib.feature.Feature)1 FeatureCommandImplementor (com.voxelgameslib.voxelgameslib.feature.FeatureCommandImplementor)1 Tickable (com.voxelgameslib.voxelgameslib.tick.Tickable)1 Listener (org.bukkit.event.Listener)1