Search in sources :

Example 1 with Ability

use of com.voxelgameslib.voxelgameslib.components.ability.Ability in project VoxelGamesLibv2 by VoxelGamesLib.

the class KitFeature method enable.

/**
 * @see AbstractFeature#enable()
 */
@Override
public void enable() {
    if (registerCommands) {
        commandManager.registerCommand(injector.getInstance(KitCommands.class));
    }
    if (allowedKits.size() == 0) {
        allowedKits.add("DefaultKit");
    }
    // try to load kits
    allowedKits.forEach(kit -> {
        Optional<Kit> k = kitHandler.loadKit(kit);
        if (k.isPresent()) {
            kits.add(k.get());
        } else {
            log.warning("Could not find kit " + kit);
        }
    });
    kits.forEach(kit -> {
        if (kit.getAbilities() != null) {
            for (Ability ability : kit.getAbilities().values()) {
                Bukkit.getPluginManager().registerEvents(ability, voxelGamesLib);
            }
        }
    });
}
Also used : Ability(com.voxelgameslib.voxelgameslib.components.ability.Ability) Kit(com.voxelgameslib.voxelgameslib.components.kits.Kit) KitCommands(com.voxelgameslib.voxelgameslib.command.commands.KitCommands)

Example 2 with Ability

use of com.voxelgameslib.voxelgameslib.components.ability.Ability 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();
}
Also used : Ability(com.voxelgameslib.voxelgameslib.components.ability.Ability) Listener(org.bukkit.event.Listener) 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

Ability (com.voxelgameslib.voxelgameslib.components.ability.Ability)2 KitCommands (com.voxelgameslib.voxelgameslib.command.commands.KitCommands)1 Kit (com.voxelgameslib.voxelgameslib.components.kits.Kit)1 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 Listener (org.bukkit.event.Listener)1