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);
}
}
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;
}
Aggregations