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 714047f1..3cc089df 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 @@ -17,7 +17,8 @@ public class CommandEcoEnchants extends PluginCommand { this.addSubcommand(new CommandDebug(plugin)) .addSubcommand(new CommandReload(plugin)) .addSubcommand(new CommandGiverandombook(plugin)) - .addSubcommand(new CommandRandomenchant(plugin)); + .addSubcommand(new CommandRandomenchant(plugin)) + .addSubcommand(new CommandExportLocale(plugin)); } @Override 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/CommandExportLocale.java new file mode 100644 index 00000000..c4e43e58 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandExportLocale.java @@ -0,0 +1,43 @@ +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 com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; + +import java.io.StringReader; + +public class CommandExportLocale extends Subcommand { + /** + * Instantiate a new /ecoenchants debug 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); + } + + @Override + public CommandHandler getHandler() { + return (sender, args) -> { + YamlConfiguration configuration = YamlConfiguration.loadConfiguration(new StringReader(this.getPlugin().getLangYml().toPlaintext())); + for (EcoEnchant enchant : EcoEnchants.values()) { + configuration.set("enchantments." + enchant.getKey().getKey() + ".name", enchant.getDisplayName()); + configuration.set("enchantments." + enchant.getKey().getKey() + ".description", enchant.getDescription()); + } + + Paste paste = new Paste(configuration.saveToString()); + + sender.sendMessage( + this.getPlugin().getLangYml().getMessage("link-to-locale").replace( + "%url%", + "https://hastebin.com/raw/" + 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 f8340ecb..8937c4aa 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -26,6 +26,7 @@ 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%" 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 eefce078..2114d786 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -58,6 +58,7 @@ permissions: ecoenchants.command.randomenchant: true ecoenchants.command.randomenchant.bypasshardcap: true ecoenchants.command.giverandombook: true + ecoenchants.command.exportlocale: true ecoenchants.command.ecoenchants: true ecoenchants.fromtable.*: description: Allows getting all enchantments from an enchanting table @@ -87,6 +88,9 @@ 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. + default: op ecoenchants.command.ecoenchants: description: Allows the use of /ecoenchants default: true