Search in sources :

Example 1 with CoreConfig

use of io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig in project Nucleus by NucleusPowered.

the class TestModule method configure.

@Override
protected void configure() {
    Path test;
    Path test2;
    try {
        test = Files.createTempDirectory("quick");
        test2 = Files.createTempFile(test, "quick", "conf");
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    this.bind(Path.class).annotatedWith(DefaultConfig.class).toInstance(test2);
    this.bind(Path.class).annotatedWith(ConfigDir.class).toInstance(test);
    this.bind(Game.class).toInstance(Mockito.mock(Game.class));
    this.bind(Logger.class).toInstance(Mockito.mock(Logger.class));
    CoreConfigAdapter mock = Mockito.mock(CoreConfigAdapter.class);
    PowerMockito.replace(PowerMockito.method(CoreConfigAdapter.class, "getNode")).with((obj, method, arguments) -> new CoreConfig());
    this.bind(CoreConfigAdapter.class).toInstance(mock);
    try {
        NucleusPlugin plugin = getMockPlugin();
        this.bind(NucleusPlugin.class).toInstance(plugin);
        this.bind(UserDataManager.class).toInstance(plugin.getUserDataManager());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) Game(org.spongepowered.api.Game) ConfigDir(org.spongepowered.api.config.ConfigDir) CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) DefaultConfig(org.spongepowered.api.config.DefaultConfig) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) IOException(java.io.IOException) Logger(org.slf4j.Logger) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) IOException(java.io.IOException)

Example 2 with CoreConfig

use of io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig in project Nucleus by NucleusPowered.

the class CoreListener method onReload.

@Override
public void onReload() throws Exception {
    CoreConfig c = Nucleus.getNucleus().getInternalServiceManager().getServiceUnchecked(CoreConfigAdapter.class).getNodeOrDefault();
    this.getKickOnStopMessage = c.isKickOnStop() ? c.getKickOnStopMessage() : null;
}
Also used : CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter)

Example 3 with CoreConfig

use of io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig in project Nucleus by NucleusPowered.

the class NucleusPlugin method reload.

@Override
public synchronized boolean reload() {
    try {
        this.moduleContainer.reloadSystemConfig();
        reloadMessages();
        this.commandsConfig.load();
        this.itemDataService.load();
        this.warmupConfig = null;
        CoreConfig coreConfig = this.getInternalServiceManager().getService(CoreConfigAdapter.class).get().getNodeOrDefault();
        this.isDebugMode = coreConfig.isDebugmode();
        this.isTraceUserCreations = coreConfig.traceUserCreations();
        this.savesandloads = coreConfig.isPrintSaveLoad();
        for (TextFileController tfc : textFileControllers.values()) {
            tfc.load();
        }
        fireReloadables();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
Also used : CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) TextFileController(io.github.nucleuspowered.nucleus.internal.TextFileController) ConfigException(com.typesafe.config.ConfigException) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) IOException(java.io.IOException) QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) NoModuleException(uk.co.drnaylor.quickstart.exceptions.NoModuleException) IncorrectAdapterTypeException(uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException)

Example 4 with CoreConfig

use of io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig in project Nucleus by NucleusPowered.

the class NucleusPlugin method onPostInit.

@Listener(order = Order.FIRST)
public void onPostInit(GamePostInitializationEvent event) {
    if (isErrored != null) {
        return;
    }
    logger.info(messageProvider.getMessageWithFormat("startup.postinit", PluginInfo.NAME));
    // Load up the general data files now, mods should have registered items by now.
    try {
        // Reloadable so that we can update the serialisers.
        moduleContainer.reloadSystemConfig();
    } catch (Exception e) {
        isErrored = e;
        disable();
        e.printStackTrace();
        return;
    }
    try {
        Sponge.getEventManager().post(new BaseModuleEvent.AboutToConstructEvent(this));
        logger.info(messageProvider.getMessageWithFormat("startup.moduleloading", PluginInfo.NAME));
        moduleContainer.loadModules(true);
        CoreConfig coreConfig = moduleContainer.getConfigAdapterForModule(CoreModule.ID, CoreConfigAdapter.class).getNodeOrDefault();
        if (coreConfig.isErrorOnStartup()) {
            throw new IllegalStateException("In main.conf, core.simulate-error-on-startup is set to TRUE. Remove this config entry to allow Nucleus to start. Simulating error and disabling Nucleus.");
        }
        this.isDebugMode = coreConfig.isDebugmode();
        this.isTraceUserCreations = coreConfig.traceUserCreations();
        this.savesandloads = coreConfig.isPrintSaveLoad();
    } catch (Throwable construction) {
        logger.info(messageProvider.getMessageWithFormat("startup.modulenotloaded", PluginInfo.NAME));
        construction.printStackTrace();
        disable();
        isErrored = construction;
        return;
    }
    // Register a reloadable.
    CommandPermissionHandler.onReload();
    registerReloadable(CommandPermissionHandler::onReload);
    getDocGenCache().ifPresent(x -> x.addTokenDocs(nucleusChatService.getNucleusTokenParser().getTokenNames()));
    logger.info(messageProvider.getMessageWithFormat("startup.moduleloaded", PluginInfo.NAME));
    registerPermissions();
    Sponge.getEventManager().post(new BaseModuleEvent.Complete(this));
    logger.info(messageProvider.getMessageWithFormat("startup.completeinit", PluginInfo.NAME));
}
Also used : CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) BaseModuleEvent(io.github.nucleuspowered.nucleus.internal.qsml.event.BaseModuleEvent) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) CommandPermissionHandler(io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler) ConfigException(com.typesafe.config.ConfigException) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) IOException(java.io.IOException) QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) NoModuleException(uk.co.drnaylor.quickstart.exceptions.NoModuleException) IncorrectAdapterTypeException(uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Example 5 with CoreConfig

use of io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig in project Nucleus by NucleusPowered.

the class RandomTeleportCommand method onReload.

@Override
public void onReload() {
    this.rc = this.plugin.getConfigAdapter(RTPModule.ID, RTPConfigAdapter.class).map(TypedAbstractConfigAdapter::getNodeOrDefault).orElseGet(RTPConfig::new);
    CoreConfig cc = this.plugin.getInternalServiceManager().getService(CoreConfigAdapter.class).map(TypedAbstractConfigAdapter::getNodeOrDefault).orElseGet(CoreConfig::new);
    this.height = cc.getSafeTeleportConfig().getHeight();
}
Also used : CoreConfig(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig) TypedAbstractConfigAdapter(uk.co.drnaylor.quickstart.config.TypedAbstractConfigAdapter) RTPConfigAdapter(io.github.nucleuspowered.nucleus.modules.rtp.config.RTPConfigAdapter)

Aggregations

CoreConfig (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfig)5 CoreConfigAdapter (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter)3 IOException (java.io.IOException)3 ConfigException (com.typesafe.config.ConfigException)2 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)2 IncorrectAdapterTypeException (uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException)2 NoModuleException (uk.co.drnaylor.quickstart.exceptions.NoModuleException)2 QuickStartModuleDiscoveryException (uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException)2 QuickStartModuleLoaderException (uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException)2 NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)1 UserDataManager (io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager)1 CommandPermissionHandler (io.github.nucleuspowered.nucleus.internal.CommandPermissionHandler)1 TextFileController (io.github.nucleuspowered.nucleus.internal.TextFileController)1 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)1 BaseModuleEvent (io.github.nucleuspowered.nucleus.internal.qsml.event.BaseModuleEvent)1 RTPConfigAdapter (io.github.nucleuspowered.nucleus.modules.rtp.config.RTPConfigAdapter)1 Path (java.nio.file.Path)1 Logger (org.slf4j.Logger)1 Game (org.spongepowered.api.Game)1 ConfigDir (org.spongepowered.api.config.ConfigDir)1