Search in sources :

Example 1 with QuickStartModuleDiscoveryException

use of uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException in project QuickStartModuleLoader by NucleusPowered.

the class ModuleContainer method startDiscover.

public final void startDiscover() throws QuickStartModuleDiscoveryException {
    try {
        Preconditions.checkState(currentPhase == ConstructionPhase.INITALISED);
        currentPhase = ConstructionPhase.DISCOVERING;
        Set<Class<? extends Module>> modules = discoverModules();
        HashMap<String, ModuleSpec> discovered = Maps.newHashMap();
        for (Class<? extends Module> s : modules) {
            // If we have a module annotation, we are golden.
            String id;
            ModuleSpec ms;
            if (s.isAnnotationPresent(ModuleData.class)) {
                ModuleData md = s.getAnnotation(ModuleData.class);
                id = md.id().toLowerCase();
                ms = new ModuleSpec(s, md);
            } else if (this.requireAnnotation) {
                loggerProxy.warn(MessageFormat.format("The module class {0} does not have a ModuleData annotation associated with it. " + "It is not being loaded as the module container requires the annotation to be present.", s.getClass().getName()));
                continue;
            } else {
                id = s.getClass().getName().toLowerCase();
                loggerProxy.warn(MessageFormat.format("The module {0} does not have a ModuleData annotation associated with it. We're just assuming an ID of {0}.", id));
                ms = new ModuleSpec(s, id, id, LoadingStatus.ENABLED, false);
            }
            if (discovered.containsKey(id)) {
                throw new QuickStartModuleDiscoveryException("Duplicate module ID \"" + id + "\" was discovered - loading cannot continue.");
            }
            discovered.put(id, ms);
        }
        // Create the dependency map.
        resolveDependencyOrder(discovered);
        // Modules discovered. Create the Module Config adapter.
        List<ModuleSpec> moduleSpecList = this.discoveredModules.entrySet().stream().filter(x -> !x.getValue().isMandatory()).map(Map.Entry::getValue).collect(Collectors.toList());
        // Attaches config adapter and loads in the defaults.
        config.attachModulesConfig(moduleSpecList, this.descriptionProcessor, this.moduleSection, this.moduleSectionHeader);
        config.saveAdapterDefaults(false);
        // Load what we have in config into our discovered modules.
        try {
            config.getConfigAdapter().getNode().forEach((k, v) -> {
                try {
                    ModuleSpec ms = discoveredModules.get(k);
                    if (ms != null) {
                        ms.setStatus(v);
                    } else {
                        loggerProxy.warn(String.format("Ignoring module entry %s in the configuration file: module does not exist.", k));
                    }
                } catch (IllegalStateException ex) {
                    loggerProxy.warn("A mandatory module can't have its status changed by config. Falling back to FORCELOAD for " + k);
                }
            });
        } catch (ObjectMappingException e) {
            loggerProxy.warn("Could not load modules config, falling back to defaults.");
            e.printStackTrace();
        }
        // Modules have been discovered.
        currentPhase = ConstructionPhase.DISCOVERED;
    } catch (QuickStartModuleDiscoveryException ex) {
        throw ex;
    } catch (Exception e) {
        throw new QuickStartModuleDiscoveryException("Unable to discover QuickStart modules", e);
    }
}
Also used : QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) NoModuleException(uk.co.drnaylor.quickstart.exceptions.NoModuleException) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) IncorrectAdapterTypeException(uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException) IOException(java.io.IOException) UndisableableModuleException(uk.co.drnaylor.quickstart.exceptions.UndisableableModuleException) QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) MissingDependencyException(uk.co.drnaylor.quickstart.exceptions.MissingDependencyException) ModuleData(uk.co.drnaylor.quickstart.annotations.ModuleData) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 2 with QuickStartModuleDiscoveryException

use of uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException 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)2 QuickStartModuleDiscoveryException (uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException)2 QuickStartModuleLoaderException (uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)1 Platform (org.spongepowered.api.Platform)1 Text (org.spongepowered.api.text.Text)1 ModuleData (uk.co.drnaylor.quickstart.annotations.ModuleData)1 IncorrectAdapterTypeException (uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException)1 MissingDependencyException (uk.co.drnaylor.quickstart.exceptions.MissingDependencyException)1 NoModuleException (uk.co.drnaylor.quickstart.exceptions.NoModuleException)1 UndisableableModuleException (uk.co.drnaylor.quickstart.exceptions.UndisableableModuleException)1