Search in sources :

Example 1 with VoxelGamesLibEnableEvent

use of com.voxelgameslib.voxelgameslib.api.event.events.VoxelGamesLibEnableEvent in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoxelGamesLib method onEnable.

@Override
public void onEnable() {
    try {
        // logging first, only changes prefixes anyways
        loggingHandler = new LoggingHandler();
        loggingHandler.setErrorHandler(errorHandler);
        loggingHandler.enable();
        // enable by enabling external stuff. they don't require any VGL stuff
        // timings
        timingManager = TimingManager.of(this);
        // commands
        commandManager = new BukkitCommandManager(this);
        commandManager.setDefaultExceptionHandler((scope, registeredCommand, sender, args, t) -> {
            errorHandler.handle(sender, args, t);
            return false;
        });
        // living on the edge!
        commandManager.enableUnstableAPI("help");
        // task chain
        taskChainFactory = BukkitTaskChainFactory.create(this);
        taskChainFactory.setDefaultErrorHandler((e, t) -> {
            log.severe("Task " + t.hashCode() + " generated an exception:");
            e.printStackTrace();
        });
        // chat menu api
        ChatMenuAPI.init(this);
        // menu builder (excuse the hack, but we want to shade you)
        MenuBuilderPlugin menuBuilderPluginFake = new ObjenesisStd().getInstantiatorOf(MenuBuilderPlugin.class).newInstance();
        menuBuilderPluginFake.inventoryListener = new InventoryListener(menuBuilderPluginFake);
        MenuBuilderPlugin.instance = menuBuilderPluginFake;
        Bukkit.getPluginManager().registerEvents(menuBuilderPluginFake.inventoryListener, this);
        // guice
        VoxelGamesLibModule module = new VoxelGamesLibModule(this, loggingHandler, timingManager, commandManager, getVersion(), getDataFolder(), ModuleHandler.getOfferedModules(), errorHandler);
        injector = module.createInjector();
        injector.injectMembers(this);
        // startup handler
        startupHandler.registerService("onEnable");
        Bukkit.getPluginManager().registerEvents(injector.getInstance(StartupListener.class), this);
        // then enable all VGL stuff
        try (final Timing timing = new Timing("EnableAllHandlers")) {
            eventHandler.enable();
            configHandler.enable();
            persistenceHandler.enable();
            langHandler.enable();
            tickHandler.enable();
            chatHandler.enable();
            userHandler.enable();
            roleHandler.enable();
            mapHandler.enable();
            worldHandler.enable();
            teamHandler.enable();
            eloHandler.enable();
            matchmakingHandler.enable();
            signHandler.enable();
            metricHandler.enable();
            pointHandler.enable();
            kitHandler.enable();
            commandHandler.enable();
            textureHandler.enable();
            statsHandler.enable();
            gameHandler.enable();
        }
        registerListeners();
    } catch (Exception ex) {
        errorHandler.handle(ex, Severity.ERROR, true);
        startupHandler.interrupt();
        return;
    }
    // register commands
    registerCommandContexts();
    registerCommandReplacements();
    registerCommands();
    registerCommandCompletions();
    moduleHandler.enable();
    gameHandler.startDefaultGame();
    getServer().getPluginManager().callEvent(new VoxelGamesLibEnableEvent());
    testStuff.test();
    startupHandler.unregisterService("onEnable");
    enabledCleanly = true;
}
Also used : MenuBuilderPlugin(org.inventivetalent.menubuilder.MenuBuilderPlugin) LoggingHandler(com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) ObjenesisStd(org.objenesis.ObjenesisStd) InventoryListener(org.inventivetalent.menubuilder.inventory.InventoryListener) VoxelGamesLibEnableEvent(com.voxelgameslib.voxelgameslib.api.event.events.VoxelGamesLibEnableEvent) Timing(com.voxelgameslib.voxelgameslib.internal.timings.Timing) StartupListener(com.voxelgameslib.voxelgameslib.internal.startup.StartupListener)

Aggregations

BukkitCommandManager (co.aikar.commands.BukkitCommandManager)1 VoxelGamesLibEnableEvent (com.voxelgameslib.voxelgameslib.api.event.events.VoxelGamesLibEnableEvent)1 LoggingHandler (com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler)1 StartupListener (com.voxelgameslib.voxelgameslib.internal.startup.StartupListener)1 Timing (com.voxelgameslib.voxelgameslib.internal.timings.Timing)1 MenuBuilderPlugin (org.inventivetalent.menubuilder.MenuBuilderPlugin)1 InventoryListener (org.inventivetalent.menubuilder.inventory.InventoryListener)1 ObjenesisStd (org.objenesis.ObjenesisStd)1