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