Search in sources :

Example 1 with LoggingHandler

use of com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler 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)

Example 2 with LoggingHandler

use of com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoxelGamesLibModule method configure.

@Override
protected void configure() {
    bind(Plugin.class).toInstance(voxelGamesLib);
    bind(VoxelGamesLib.class).toInstance(voxelGamesLib);
    bind(TimingManager.class).toInstance(timingManager);
    bind(BukkitCommandManager.class).toInstance(commandManager);
    bind(LoggingHandler.class).toInstance(loggingHandler);
    bind(ErrorHandler.class).toInstance(errorHandler);
    bind(String.class).annotatedWith(Names.named("PluginVersion")).toInstance(pluginVersion);
    bind(File.class).annotatedWith(Names.named("ConfigFolder")).toInstance(dataFolder);
    bind(File.class).annotatedWith(Names.named("LangFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "lang"));
    bind(File.class).annotatedWith(Names.named("WorldsFolder")).toInstance(new File(Bukkit.getWorldContainer().getAbsoluteFile(), "worlds"));
    bind(File.class).annotatedWith(Names.named("WorldContainer")).toInstance(Bukkit.getWorldContainer().getAbsoluteFile());
    bind(File.class).annotatedWith(Names.named("GameDefinitionFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "games"));
    bind(File.class).annotatedWith(Names.named("DataFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "data"));
    bind(File.class).annotatedWith(Names.named("KitsFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "kits"));
    bind(File.class).annotatedWith(Names.named("SkinsFolder")).toInstance(new File(dataFolder.getAbsoluteFile(), "skins"));
    bind(WorldConfig.class).toProvider(WorldHandler.class);
    bind(GlobalConfig.class).toProvider(ConfigHandler.class);
    requestStaticInjection(Lang.class);
    requestStaticInjection(Permission.class);
    offeredModules.forEach((key, value) -> bind(key).toInstance(value));
}
Also used : ErrorHandler(com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler) LoggingHandler(com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) GlobalConfig(com.voxelgameslib.voxelgameslib.internal.config.GlobalConfig) WorldConfig(com.voxelgameslib.voxelgameslib.components.world.WorldConfig) File(java.io.File) Plugin(org.bukkit.plugin.Plugin) TimingManager(co.aikar.commands.lib.timings.TimingManager)

Aggregations

BukkitCommandManager (co.aikar.commands.BukkitCommandManager)2 LoggingHandler (com.voxelgameslib.voxelgameslib.internal.log.LoggingHandler)2 TimingManager (co.aikar.commands.lib.timings.TimingManager)1 VoxelGamesLibEnableEvent (com.voxelgameslib.voxelgameslib.api.event.events.VoxelGamesLibEnableEvent)1 WorldConfig (com.voxelgameslib.voxelgameslib.components.world.WorldConfig)1 GlobalConfig (com.voxelgameslib.voxelgameslib.internal.config.GlobalConfig)1 ErrorHandler (com.voxelgameslib.voxelgameslib.internal.error.ErrorHandler)1 StartupListener (com.voxelgameslib.voxelgameslib.internal.startup.StartupListener)1 Timing (com.voxelgameslib.voxelgameslib.internal.timings.Timing)1 File (java.io.File)1 Plugin (org.bukkit.plugin.Plugin)1 MenuBuilderPlugin (org.inventivetalent.menubuilder.MenuBuilderPlugin)1 InventoryListener (org.inventivetalent.menubuilder.inventory.InventoryListener)1 ObjenesisStd (org.objenesis.ObjenesisStd)1