Search in sources :

Example 1 with QuickStartModuleLoaderException

use of uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException in project Nucleus by NucleusPowered.

the class NucleusPlugin method getErrorMessage.

private List<Text> getErrorMessage() {
    List<Text> messages = Lists.newArrayList();
    messages.add(Text.of(TextColors.RED, "----------------------------"));
    messages.add(Text.of(TextColors.RED, "-  NUCLEUS FAILED TO LOAD  -"));
    messages.add(Text.of(TextColors.RED, "----------------------------"));
    addX(messages, 5);
    messages.add(Text.of(TextColors.RED, "----------------------------"));
    messages.add(Text.EMPTY);
    messages.add(Text.of(TextColors.RED, "Nucleus encountered an error during server start up and did not enable successfully. No commands, listeners or tasks are registered."));
    if (this.isServer) {
        messages.add(Text.of(TextColors.RED, "The server has been automatically whitelisted - this is to protect your server and players if you rely on some of Nucleus' functionality (such as fly states, etc.)"));
    }
    messages.add(Text.of(TextColors.RED, "The error that Nucleus encountered will be reproduced below for your convenience."));
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    if (isErrored == null) {
        messages.add(Text.of(TextColors.YELLOW, "No exception was saved."));
    } else {
        Throwable exception = isErrored;
        if (exception.getCause() != null && (exception instanceof QuickStartModuleLoaderException || exception instanceof QuickStartModuleDiscoveryException)) {
            exception = exception.getCause();
        }
        // Blegh, relocations
        if (exception instanceof IOException && exception.getCause().getClass().getName().contains(ConfigException.class.getSimpleName())) {
            exception = exception.getCause();
            messages.add(Text.of(TextColors.RED, "It appears that there is an error in your configuration file! The error is: "));
            messages.add(Text.of(TextColors.RED, exception.getMessage()));
            messages.add(Text.of(TextColors.RED, "Please correct this and restart your server."));
            messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
            messages.add(Text.of(TextColors.YELLOW, "(The error that was thrown is shown below)"));
        }
        try (StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw)) {
            exception.printStackTrace(pw);
            pw.flush();
            String[] stackTrace = sw.toString().split("(\r)?\n");
            for (String s : stackTrace) {
                messages.add(Text.of(TextColors.YELLOW, s));
            }
        } catch (IOException e) {
            exception.printStackTrace();
        }
    }
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    messages.add(Text.of(TextColors.RED, "If this error persists, check your configuration files and ensure that you have the latest version of Nucleus which matches the current version of the Sponge API."));
    messages.add(Text.of(TextColors.RED, "If you do, please report this error to the Nucleus team at https://github.com/NucleusPowered/Nucleus/issues"));
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    messages.add(Text.of(TextColors.YELLOW, "Server Information"));
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    messages.add(Text.of(TextColors.YELLOW, "Nucleus version: " + PluginInfo.VERSION + ", (Git: " + PluginInfo.GIT_HASH + ")"));
    Platform platform = Sponge.getPlatform();
    messages.add(Text.of(TextColors.YELLOW, "Minecraft version: " + platform.getMinecraftVersion().getName()));
    messages.add(Text.of(TextColors.YELLOW, String.format("Sponge Version: %s %s", platform.getContainer(Platform.Component.IMPLEMENTATION).getName(), platform.getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("unknown"))));
    messages.add(Text.of(TextColors.YELLOW, String.format("Sponge API Version: %s %s", platform.getContainer(Platform.Component.API).getName(), platform.getContainer(Platform.Component.API).getVersion().orElse("unknown"))));
    messages.add(Text.EMPTY);
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    messages.add(Text.of(TextColors.YELLOW, "Installed Plugins"));
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    Sponge.getPluginManager().getPlugins().forEach(x -> messages.add(Text.of(TextColors.YELLOW, x.getName() + " (" + x.getId() + ") version " + x.getVersion().orElse("unknown"))));
    messages.add(Text.EMPTY);
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    messages.add(Text.of(TextColors.YELLOW, "- END NUCLEUS ERROR REPORT -"));
    messages.add(Text.of(TextColors.YELLOW, "----------------------------"));
    return messages;
}
Also used : QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) StringWriter(java.io.StringWriter) Platform(org.spongepowered.api.Platform) Text(org.spongepowered.api.text.Text) IOException(java.io.IOException) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Platform (org.spongepowered.api.Platform)1 Text (org.spongepowered.api.text.Text)1 QuickStartModuleDiscoveryException (uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException)1 QuickStartModuleLoaderException (uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException)1