Search in sources :

Example 1 with Tickable

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

the class AbstractPhase method tick.

@Override
public void tick() {
    phaseTiming.startTiming();
    for (Feature feature : features) {
        MCTiming timing = timingManager.ofStart("Phase::Tickables::" + getName() + "::" + feature.getName(), phaseTiming);
        feature.tick();
        timing.stopTiming();
    }
    for (Tickable tickable : phaseTickables.values()) {
        MCTiming timing = timingManager.ofStart("Phase::Tickables::" + getName() + "::" + tickable.getClass().getSimpleName(), phaseTiming);
        tickable.tick();
        timing.stopTiming();
    }
    phaseTiming.stopTiming();
    checkEnd();
}
Also used : Tickable(com.voxelgameslib.voxelgameslib.api.tick.Tickable) SpectatorFeature(com.voxelgameslib.voxelgameslib.api.feature.features.SpectatorFeature) Feature(com.voxelgameslib.voxelgameslib.api.feature.Feature) MCTiming(co.aikar.commands.lib.timings.MCTiming)

Example 2 with Tickable

use of com.voxelgameslib.voxelgameslib.api.tick.Tickable 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());
        }
    }
}
Also used : EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.api.condition.conditions.EmptyVictoryCondition) Listener(org.bukkit.event.Listener) Tickable(com.voxelgameslib.voxelgameslib.api.tick.Tickable) FeatureCommandImplementor(com.voxelgameslib.voxelgameslib.api.feature.FeatureCommandImplementor) SpectatorFeature(com.voxelgameslib.voxelgameslib.api.feature.features.SpectatorFeature) EmptyVictoryCondition(com.voxelgameslib.voxelgameslib.api.condition.conditions.EmptyVictoryCondition) VictoryCondition(com.voxelgameslib.voxelgameslib.api.condition.VictoryCondition) SpectatorFeature(com.voxelgameslib.voxelgameslib.api.feature.features.SpectatorFeature) Feature(com.voxelgameslib.voxelgameslib.api.feature.Feature) NoSuchFeatureException(com.voxelgameslib.voxelgameslib.api.exception.NoSuchFeatureException) VoxelGameLibException(com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException) DependencyGraphException(com.voxelgameslib.voxelgameslib.api.exception.DependencyGraphException) AbstractFeatureCommand(com.voxelgameslib.voxelgameslib.api.feature.AbstractFeatureCommand)

Aggregations

Feature (com.voxelgameslib.voxelgameslib.api.feature.Feature)2 SpectatorFeature (com.voxelgameslib.voxelgameslib.api.feature.features.SpectatorFeature)2 Tickable (com.voxelgameslib.voxelgameslib.api.tick.Tickable)2 MCTiming (co.aikar.commands.lib.timings.MCTiming)1 VictoryCondition (com.voxelgameslib.voxelgameslib.api.condition.VictoryCondition)1 EmptyVictoryCondition (com.voxelgameslib.voxelgameslib.api.condition.conditions.EmptyVictoryCondition)1 DependencyGraphException (com.voxelgameslib.voxelgameslib.api.exception.DependencyGraphException)1 NoSuchFeatureException (com.voxelgameslib.voxelgameslib.api.exception.NoSuchFeatureException)1 VoxelGameLibException (com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException)1 AbstractFeatureCommand (com.voxelgameslib.voxelgameslib.api.feature.AbstractFeatureCommand)1 FeatureCommandImplementor (com.voxelgameslib.voxelgameslib.api.feature.FeatureCommandImplementor)1 Listener (org.bukkit.event.Listener)1