use of io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider 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;
}
use of io.github.nucleuspowered.nucleus.internal.messages.ConfigMessageProvider in project Nucleus by NucleusPowered.
the class MessagesUpdateCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// First, reload the messages.
boolean reload = this.plugin.reloadMessages();
if (!reload) {
// There was a failure loading a custom file
throw ReturnMessageException.fromKey("command.nucleus.messageupdate.couldnotload");
}
MessageProvider messageProvider = plugin.getMessageProvider();
if (!(messageProvider instanceof ConfigMessageProvider)) {
throw new ReturnMessageException(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.notfile"));
}
ConfigMessageProvider cmp = (ConfigMessageProvider) messageProvider;
List<String> keys = cmp.checkForMigration();
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.reloaded"));
if (keys.isEmpty()) {
return CommandResult.success();
}
if (args.hasAny("y")) {
cmp.reset(keys);
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.reset"));
} else {
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.sometoupdate", String.valueOf(keys.size())));
keys.forEach(x -> src.sendMessage(Text.of(TextColors.YELLOW, x)));
src.sendMessage(messageProvider.getTextMessageWithFormat("command.nucleus.messageupdate.confirm", "/nucleus update-messages -y").toBuilder().onClick(TextActions.runCommand("/nucleus update-messages -y")).build());
}
return CommandResult.success();
}
Aggregations