Plugin Manager localisation

* Confugure Plugin Manager to use localised strings
* Add localisation strings for plugin manager
This commit is contained in:
TotalyNotOndre 2022-09-03 03:53:26 +03:00 committed by Melledy
parent a7317f2f9a
commit 49aed23f3d
11 changed files with 178 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import lombok.*;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static emu.grasscutter.config.Configuration.PLUGIN; import static emu.grasscutter.config.Configuration.PLUGIN;
import static emu.grasscutter.utils.Language.translate;
import java.io.*; import java.io.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -44,7 +45,7 @@ public final class PluginManager {
private void loadPlugins() { private void loadPlugins() {
File pluginsDir = new File(Utils.toFilePath(PLUGIN())); File pluginsDir = new File(Utils.toFilePath(PLUGIN()));
if (!pluginsDir.exists() && !pluginsDir.mkdirs()) { if (!pluginsDir.exists() && !pluginsDir.mkdirs()) {
Grasscutter.getLogger().error("Failed to create plugins directory: " + pluginsDir.getAbsolutePath()); Grasscutter.getLogger().error(translate("plugin.directory_failed", pluginsDir.getAbsolutePath()));
return; return;
} }
@ -63,7 +64,7 @@ public final class PluginManager {
try { try {
pluginNames[plugins.indexOf(plugin)] = plugin.toURI().toURL(); pluginNames[plugins.indexOf(plugin)] = plugin.toURI().toURL();
} catch (MalformedURLException exception) { } catch (MalformedURLException exception) {
Grasscutter.getLogger().warn("Unable to load plugin.", exception); Grasscutter.getLogger().warn(translate("plugin.unable_to_load"), exception);
} }
}); });
@ -86,7 +87,7 @@ public final class PluginManager {
PluginConfig pluginConfig = JsonUtils.loadToClass(fileReader, PluginConfig.class); PluginConfig pluginConfig = JsonUtils.loadToClass(fileReader, PluginConfig.class);
// Check if the plugin config is valid. // Check if the plugin config is valid.
if (!pluginConfig.validate()) { if (!pluginConfig.validate()) {
Grasscutter.getLogger().warn("Plugin " + plugin.getName() + " has an invalid config file."); Grasscutter.getLogger().warn(translate("plugin.invalid_config", plugin.getName()));
return; return;
} }
@ -120,12 +121,12 @@ public final class PluginManager {
// Load the plugin. // Load the plugin.
this.loadPlugin(pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig), loader); this.loadPlugin(pluginInstance, PluginIdentifier.fromPluginConfig(pluginConfig), loader);
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
Grasscutter.getLogger().warn("Plugin " + plugin.getName() + " has an invalid main class."); Grasscutter.getLogger().warn(translate("plugin.invalid_main_class", plugin.getName()));
} catch (FileNotFoundException ignored) { } catch (FileNotFoundException ignored) {
Grasscutter.getLogger().warn("Plugin " + plugin.getName() + " lacks a valid config file."); Grasscutter.getLogger().warn(translate("plugin.missing_config", plugin.getName()));
} }
} catch (Exception exception) { } catch (Exception exception) {
Grasscutter.getLogger().error("Failed to load plugin: " + plugin.getName(), exception); Grasscutter.getLogger().error(translate("plugin.failed_to_load_plugin", plugin.getName()), exception);
} }
} }
@ -134,7 +135,7 @@ public final class PluginManager {
while (!dependencies.isEmpty()) { while (!dependencies.isEmpty()) {
// Check if the depth is too high. // Check if the depth is too high.
if (depth >= maxDepth) { if (depth >= maxDepth) {
Grasscutter.getLogger().error("Failed to load plugins with dependencies."); Grasscutter.getLogger().error(translate("plugin.failed_to_load_dependencies"));
break; break;
} }
@ -154,7 +155,7 @@ public final class PluginManager {
// Load the plugin. // Load the plugin.
this.loadPlugin(pluginData.getPlugin(), pluginData.getIdentifier(), pluginData.getClassLoader()); this.loadPlugin(pluginData.getPlugin(), pluginData.getIdentifier(), pluginData.getClassLoader());
} catch (Exception exception) { } catch (Exception exception) {
Grasscutter.getLogger().error("Failed to load a plugin.", exception); depth++; Grasscutter.getLogger().error(translate("plugin.failed_to_load"), exception); depth++;
} }
} }
} }
@ -165,7 +166,7 @@ public final class PluginManager {
* @param plugin The plugin instance. * @param plugin The plugin instance.
*/ */
private void loadPlugin(Plugin plugin, PluginIdentifier identifier, URLClassLoader classLoader) { private void loadPlugin(Plugin plugin, PluginIdentifier identifier, URLClassLoader classLoader) {
Grasscutter.getLogger().info("Loading plugin: " + identifier.name); Grasscutter.getLogger().info(translate("plugin.loading_plugin", identifier.name));
// Add the plugin's identifier. // Add the plugin's identifier.
try { try {
@ -175,7 +176,7 @@ public final class PluginManager {
method.invoke(plugin, identifier, classLoader); method.invoke(plugin, identifier, classLoader);
method.setAccessible(false); method.setAccessible(false);
} catch (Exception ignored) { } catch (Exception ignored) {
Grasscutter.getLogger().warn("Failed to add plugin identifier: " + identifier.name); Grasscutter.getLogger().warn(translate("plugin.failed_add_id", identifier.name));
} }
// Add the plugin to the list of loaded plugins. // Add the plugin to the list of loaded plugins.
@ -187,7 +188,7 @@ public final class PluginManager {
try { try {
plugin.onLoad(); plugin.onLoad();
} catch (Throwable exception) { } catch (Throwable exception) {
Grasscutter.getLogger().error("Failed to load plugin: " + identifier.name, exception); Grasscutter.getLogger().error(translate("plugin.failed_to_load_plugin", identifier.name), exception);
} }
} }
@ -196,11 +197,11 @@ public final class PluginManager {
*/ */
public void enablePlugins() { public void enablePlugins() {
this.plugins.forEach((name, plugin) -> { this.plugins.forEach((name, plugin) -> {
Grasscutter.getLogger().info("Enabling plugin: " + name); Grasscutter.getLogger().info(translate("plugin.enabling_plugin", name));
try { try {
plugin.onEnable(); plugin.onEnable();
} catch (Throwable exception) { } catch (Throwable exception) {
Grasscutter.getLogger().error("Failed to enable plugin: " + name, exception); Grasscutter.getLogger().error(translate("plugin.enabling_failed", name), exception);
} }
}); });
} }
@ -210,7 +211,7 @@ public final class PluginManager {
*/ */
public void disablePlugins() { public void disablePlugins() {
this.plugins.forEach((name, plugin) -> { this.plugins.forEach((name, plugin) -> {
Grasscutter.getLogger().info("Disabling plugin: " + name); Grasscutter.getLogger().info(translate("plugin.disabling_plugin", name));
this.disablePlugin(plugin); this.disablePlugin(plugin);
}); });
} }
@ -277,7 +278,7 @@ public final class PluginManager {
// Call the plugin's onEnable method. // Call the plugin's onEnable method.
plugin.onEnable(); plugin.onEnable();
} catch (Exception exception) { } catch (Exception exception) {
Grasscutter.getLogger().error("Failed to enable plugin: " + plugin.getName(), exception); Grasscutter.getLogger().error(translate("plugin.enabling_failed", plugin.getName()), exception);
} }
} }
@ -291,7 +292,7 @@ public final class PluginManager {
// Call the plugin's onDisable method. // Call the plugin's onDisable method.
plugin.onDisable(); plugin.onDisable();
} catch (Exception exception) { } catch (Exception exception) {
Grasscutter.getLogger().error("Failed to disable plugin: " + plugin.getName(), exception); Grasscutter.getLogger().error(translate("plugin.disabling_failed", plugin.getName()), exception);
} }
// Un-register all listeners. // Un-register all listeners.

View File

@ -382,5 +382,21 @@
"handbook": "GM Handbook", "handbook": "GM Handbook",
"gacha_mapping": "Gacha mapping JSON" "gacha_mapping": "Gacha mapping JSON"
} }
},
"plugin": {
"directory_failed": "Failed to create plugins directory: ",
"unable_to_load": "Unable to load plugin.",
"invalid_config": "Plugin %s has an invalid config file.",
"invalid_main_class": "Plugin %s has an invalid main class.",
"missing_config": "Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "Failed to load plugin: %s",
"failed_to_load": "Failed to load a plugin.",
"failed_to_load_dependencies": "Failed to load plugins with dependencies.",
"loading_plugin": "Loading plugin: %s",
"failed_add_id": "Failed to add plugin identifier: %s",
"enabling_plugin": "Enabling plugin: %s",
"enabling_failed": "Failed to enable plugin: %s",
"disabling_plugin": "Disabling plugin: %s",
"disabling_failed": "Failed to disable plugin: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "🇺🇸GM Handbook", "handbook": "🇺🇸GM Handbook",
"gacha_mapping": "JSON de mapeo del Gacha" "gacha_mapping": "JSON de mapeo del Gacha"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "Manuel GM", "handbook": "Manuel GM",
"gacha_mapping": "🇺🇸Gacha mapping JSON" "gacha_mapping": "🇺🇸Gacha mapping JSON"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }

View File

@ -382,6 +382,22 @@
"handbook": "GM Handbook", "handbook": "GM Handbook",
"gacha_mapping": "ガチャマップ JSON" "gacha_mapping": "ガチャマップ JSON"
} }
} },
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
}
} }

View File

@ -382,5 +382,21 @@
"handbook": "🇺🇸GM Handbook", "handbook": "🇺🇸GM Handbook",
"gacha_mapping": "🇺🇸Gacha mapping JSON" "gacha_mapping": "🇺🇸Gacha mapping JSON"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "🇺🇸GM Handbook", "handbook": "🇺🇸GM Handbook",
"gacha_mapping": "Losowanie w formacie JSON" "gacha_mapping": "Losowanie w formacie JSON"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "Manual GM", "handbook": "Manual GM",
"gacha_mapping": "🇺🇸Gacha mapping JSON" "gacha_mapping": "🇺🇸Gacha mapping JSON"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "Справочник гейм-мастера", "handbook": "Справочник гейм-мастера",
"gacha_mapping": "Мапирование системы гача в JSON" "gacha_mapping": "Мапирование системы гача в JSON"
} }
},
"plugin": {
"directory_failed": "Ошибка создания директории плагинов: ",
"unable_to_load": "Невозможно загрудить плагин.",
"invalid_config": "Плагин %s имеет недопустимый файл конфигурации.",
"invalid_main_class": "Плагин %s имеет неверный главный класс.",
"missing_config": "Плагин %s не имеет корректного файла конфигурации.",
"failed_to_load_plugin": "Ошибка загрузки плагина: %s",
"failed_to_load": "Не удалось загрузить Плагин.",
"failed_to_load_dependencies": "Не удалось загрузитьзависимости Плагина.",
"loading_plugin": "Загрузка Плагина: %s",
"failed_add_id": "Ошибка присвоения идентификатора Плагину: %s",
"enabling_plugin": "Включаем Плагин: %s",
"enabling_failed": "Ошибка включения Плагина: %s",
"disabling_plugin": "Отключаем Плагин: %s",
"disabling_failed": "Ошибка отключения Плагина: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "GM手册", "handbook": "GM手册",
"gacha_mapping": "祈愿物品映射JSON" "gacha_mapping": "祈愿物品映射JSON"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }

View File

@ -382,5 +382,21 @@
"handbook": "🇺🇸GM Handbook", "handbook": "🇺🇸GM Handbook",
"gacha_mapping": "祈願物品映射到JSON上" "gacha_mapping": "祈願物品映射到JSON上"
} }
},
"plugin": {
"directory_failed": "🇺🇸Failed to create plugins directory: ",
"unable_to_load": "🇺🇸Unable to load plugin.",
"invalid_config": "🇺🇸Plugin %s has an invalid config file.",
"invalid_main_class": "🇺🇸Plugin %s has an invalid main class.",
"missing_config": "🇺🇸Plugin %s lacks a valid config file.",
"failed_to_load_plugin": "🇺🇸Failed to load plugin: %s",
"failed_to_load": "🇺🇸Failed to load a plugin.",
"failed_to_load_dependencies": "🇺🇸Failed to load plugins with dependencies.",
"loading_plugin": "🇺🇸Loading plugin: %s",
"failed_add_id": "🇺🇸Failed to add plugin identifier: %s",
"enabling_plugin": "🇺🇸Enabling plugin: %s",
"enabling_failed": "🇺🇸Failed to enable plugin: %s",
"disabling_plugin": "🇺🇸Disabling plugin: %s",
"disabling_failed": "🇺🇸Failed to disable plugin: %s"
} }
} }