Search in sources :

Example 1 with ResourceMessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider in project Nucleus by NucleusPowered.

the class NucleusPlugin method reloadMessages.

@Override
public boolean reloadMessages() {
    boolean r = true;
    if (getConfigValue("core", CoreConfigAdapter.class, CoreConfig::isCustommessages).orElse(false)) {
        try {
            this.messageProvider = new ConfigMessageProvider(configDir.resolve("messages.conf"), ResourceMessageProvider.messagesBundle);
            this.commandMessageProvider = new ConfigMessageProvider(configDir.resolve("command-help-messages.conf"), ResourceMessageProvider.commandMessagesBundle);
            return true;
        } catch (Throwable exception) {
            r = false;
            // Blegh, relocations
            if (exception instanceof IOException && exception.getCause().getClass().getName().contains(ConfigException.class.getSimpleName())) {
                MessageReceiver s;
                if (Sponge.getGame().isServerAvailable()) {
                    s = Sponge.getServer().getConsole();
                } else {
                    s = new ClientMessageReciever();
                }
                exception = exception.getCause();
                s.sendMessage(Text.of(TextColors.RED, "It appears that there is an error in your messages file! The error is: "));
                s.sendMessage(Text.of(TextColors.RED, exception.getMessage()));
                s.sendMessage(Text.of(TextColors.RED, "Please correct this - then run ", TextColors.YELLOW, "/nucleus reload"));
                s.sendMessage(Text.of(TextColors.RED, "Ignoring messages.conf for now."));
                if (this.isDebugMode) {
                    exception.printStackTrace();
                }
            } else {
                this.logger.warn("Could not load custom messages file. Falling back.");
                exception.printStackTrace();
            }
        }
    }
    this.messageProvider = new ResourceMessageProvider(ResourceMessageProvider.messagesBundle);
    this.commandMessageProvider = new ResourceMessageProvider(ResourceMessageProvider.commandMessagesBundle);
    return r;
}
Also used : MessageReceiver(org.spongepowered.api.text.channel.MessageReceiver) ConfigMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider) ConfigException(com.typesafe.config.ConfigException) IOException(java.io.IOException) CoreConfigAdapter(io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter) ClientMessageReciever(io.github.nucleuspowered.nucleus.internal.client.ClientMessageReciever) ResourceMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider)

Example 2 with ResourceMessageProvider

use of io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider in project Nucleus by NucleusPowered.

the class TestModule method getMockPlugin.

private NucleusPlugin getMockPlugin() {
    NucleusPlugin plugin = Mockito.mock(NucleusPlugin.class);
    PermissionRegistry pr = new PermissionRegistry();
    Mockito.when(plugin.getMessageProvider()).thenReturn(new ResourceMessageProvider(ResourceMessageProvider.messagesBundle));
    Mockito.when(plugin.getPermissionRegistry()).thenReturn(pr);
    Mockito.when(plugin.getUserDataManager()).thenReturn(Mockito.mock(UserDataManager.class));
    /*
        Field f = Nucleus.class.getDeclaredField("nucleus");
        f.setAccessible(true);
        f.set(null, plugin);
*/
    try {
        Path file = Files.createTempFile("quickstartcmdtest", "conf");
        CommandsConfig cc = new CommandsConfig(file);
        Mockito.when(plugin.getCommandsConfig()).thenReturn(cc);
        return plugin;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) UserDataManager(io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager) CommandsConfig(io.github.nucleuspowered.nucleus.config.CommandsConfig) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) NucleusPlugin(io.github.nucleuspowered.nucleus.NucleusPlugin) IOException(java.io.IOException) ResourceMessageProvider(io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider)

Aggregations

ResourceMessageProvider (io.github.nucleuspowered.nucleus.internal.messages.ResourceMessageProvider)2 IOException (java.io.IOException)2 ConfigException (com.typesafe.config.ConfigException)1 NucleusPlugin (io.github.nucleuspowered.nucleus.NucleusPlugin)1 CommandsConfig (io.github.nucleuspowered.nucleus.config.CommandsConfig)1 UserDataManager (io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager)1 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)1 ClientMessageReciever (io.github.nucleuspowered.nucleus.internal.client.ClientMessageReciever)1 ConfigMessageProvider (io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider)1 CoreConfigAdapter (io.github.nucleuspowered.nucleus.modules.core.config.CoreConfigAdapter)1 Path (java.nio.file.Path)1 MessageReceiver (org.spongepowered.api.text.channel.MessageReceiver)1