From 9bdc97143f917e94fa487779679f5bdcfb49fc2d Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 12 Jul 2021 20:57:19 +0200 Subject: [PATCH] Added locale downloading --- .../command/CommandEcoEnchants.java | 2 +- .../ecoenchants/command/CommandLocale.java | 27 +++++++++++++ .../command/CommandLocaleDownload.java | 39 +++++++++++++++++++ ...rtLocale.java => CommandLocaleExport.java} | 11 +++--- .../core-plugin/src/main/resources/lang.yml | 5 ++- .../core-plugin/src/main/resources/plugin.yml | 19 +++++++-- 6 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocale.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleDownload.java rename eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/{CommandExportLocale.java => CommandLocaleExport.java} (78%) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEcoEnchants.java index 3cc089df..bd164f57 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEcoEnchants.java @@ -18,7 +18,7 @@ public class CommandEcoEnchants extends PluginCommand { .addSubcommand(new CommandReload(plugin)) .addSubcommand(new CommandGiverandombook(plugin)) .addSubcommand(new CommandRandomenchant(plugin)) - .addSubcommand(new CommandExportLocale(plugin)); + .addSubcommand(new CommandLocale(plugin)); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocale.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocale.java new file mode 100644 index 00000000..986b927f --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocale.java @@ -0,0 +1,27 @@ +package com.willfp.ecoenchants.command; + +import com.willfp.eco.core.command.CommandHandler; +import com.willfp.eco.core.command.impl.Subcommand; +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import org.jetbrains.annotations.NotNull; + +public class CommandLocale extends Subcommand { + /** + * Instantiate a new /ecoenchants locale command handler. + * + * @param plugin The plugin for the commands to listen for. + */ + public CommandLocale(@NotNull final EcoEnchantsPlugin plugin) { + super(plugin, "locale", "ecoenchants.command.locale", false); + + this.addSubcommand(new CommandLocaleExport(plugin)) + .addSubcommand(new CommandLocaleDownload(plugin)); + } + + @Override + public CommandHandler getHandler() { + return (sender, args) -> { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-locale-subcommand")); + }; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleDownload.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleDownload.java new file mode 100644 index 00000000..2faafc58 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleDownload.java @@ -0,0 +1,39 @@ +package com.willfp.ecoenchants.command; + +import com.willfp.eco.core.command.CommandHandler; +import com.willfp.eco.core.command.impl.Subcommand; +import com.willfp.eco.core.web.Paste; +import com.willfp.ecoenchants.EcoEnchantsPlugin; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; + +import java.io.StringReader; + +public class CommandLocaleDownload extends Subcommand { + /** + * Instantiate a new /ecoenchants locale download command handler. + * + * @param plugin The plugin for the commands to listen for. + */ + public CommandLocaleDownload(@NotNull final EcoEnchantsPlugin plugin) { + super(plugin, "download", "ecoenchants.command.locale.download", false); + } + + @Override + public CommandHandler getHandler() { + return (sender, args) -> { + if (args.size() == 0) { + sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-locale")); + } + + Paste paste = Paste.getFromHastebin(args.get(0)); + YamlConfiguration configuration = YamlConfiguration.loadConfiguration(new StringReader(paste.getContents())); + + for (String key : configuration.getKeys(true)) { + this.getPlugin().getLangYml().set(key, configuration.get(key)); + } + + sender.sendMessage(this.getPlugin().getLangYml().getMessage("downloaded-locale")); + }; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandExportLocale.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java similarity index 78% rename from eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandExportLocale.java rename to eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java index c4e43e58..d15ccb24 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandExportLocale.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java @@ -11,14 +11,14 @@ import org.jetbrains.annotations.NotNull; import java.io.StringReader; -public class CommandExportLocale extends Subcommand { +public class CommandLocaleExport extends Subcommand { /** - * Instantiate a new /ecoenchants debug command handler. + * Instantiate a new /ecoenchants locale export command handler. * * @param plugin The plugin for the commands to listen for. */ - public CommandExportLocale(@NotNull final EcoEnchantsPlugin plugin) { - super(plugin, "exportlocale", "ecoenchants.command.exportlocale", false); + public CommandLocaleExport(@NotNull final EcoEnchantsPlugin plugin) { + super(plugin, "export", "ecoenchants.command.locale.export", false); } @Override @@ -34,8 +34,7 @@ public class CommandExportLocale extends Subcommand { sender.sendMessage( this.getPlugin().getLangYml().getMessage("link-to-locale").replace( - "%url%", - "https://hastebin.com/raw/" + paste.getHastebinToken() + "%token%", paste.getHastebinToken() ) ); }; diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 46505e33..a00ca164 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -26,7 +26,10 @@ messages: invalid-player: "&cInvalid Player!" requires-player: "&cRequires a Player!" must-hold-item-other: "&cPlayer is not holding an enchantable item!" - link-to-locale: "The locale has been successfully exported! Get it here: %url%" + link-to-locale: "The locale has been successfully exported! Your token is: %token%" + downloaded-locale: "Locale downloaded! Reload config to enact changes." + invalid-locale: "&cYou must supply a valid locale! Check the wiki for more information." + specify-locale-subcommand: "&cYou must specify whether to export or download a locale!" no-targets: "&cCannot be applied" no-conflicts: "&cNo conflicts" diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 2114d786..fae8dec4 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -58,8 +58,15 @@ permissions: ecoenchants.command.randomenchant: true ecoenchants.command.randomenchant.bypasshardcap: true ecoenchants.command.giverandombook: true - ecoenchants.command.exportlocale: true + ecoenchants.command.locale.*: true ecoenchants.command.ecoenchants: true + ecoenchants.command.locale.*: + description: Allows managing locale features + default: op + children: + ecoenchants.command.locale.download: true + ecoenchants.command.locale.export: true + ecoenchants.command.locale: true ecoenchants.fromtable.*: description: Allows getting all enchantments from an enchanting table default: true @@ -88,8 +95,14 @@ permissions: ecoenchants.command.randomenchant.bypasshardcap: description: Allows /ecoenchants randomenchant bypassing the anvil hard cap default: op - ecoenchants.command.exportlocale: - description: Allows the use of /ecoenchants exportlocale to export all language config to hastebin. + ecoenchants.command.locale: + description: Allows the use of /ecoenchants locale to manage locale i18n + default: op + ecoenchants.command.locale.download: + description: Allows the use of /ecoenchants locale download to download locales + default: op + ecoenchants.command.locale.export: + description: Allows the use of /ecoenchants locale export to export locales default: op ecoenchants.command.ecoenchants: description: Allows the use of /ecoenchants