Added /ecoenchants exportlocale

This commit is contained in:
Auxilor 2021-07-12 20:40:57 +02:00
parent 354441655d
commit b7c606d29c
4 changed files with 50 additions and 1 deletions

View File

@ -17,7 +17,8 @@ public class CommandEcoEnchants extends PluginCommand {
this.addSubcommand(new CommandDebug(plugin)) this.addSubcommand(new CommandDebug(plugin))
.addSubcommand(new CommandReload(plugin)) .addSubcommand(new CommandReload(plugin))
.addSubcommand(new CommandGiverandombook(plugin)) .addSubcommand(new CommandGiverandombook(plugin))
.addSubcommand(new CommandRandomenchant(plugin)); .addSubcommand(new CommandRandomenchant(plugin))
.addSubcommand(new CommandExportLocale(plugin));
} }
@Override @Override

View File

@ -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()
)
);
};
}
}

View File

@ -26,6 +26,7 @@ messages:
invalid-player: "&cInvalid Player!" invalid-player: "&cInvalid Player!"
requires-player: "&cRequires a Player!" requires-player: "&cRequires a Player!"
must-hold-item-other: "&cPlayer is not holding an enchantable item!" 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-targets: "&cCannot be applied"
no-conflicts: "&cNo conflicts" no-conflicts: "&cNo conflicts"

View File

@ -58,6 +58,7 @@ permissions:
ecoenchants.command.randomenchant: true ecoenchants.command.randomenchant: true
ecoenchants.command.randomenchant.bypasshardcap: true ecoenchants.command.randomenchant.bypasshardcap: true
ecoenchants.command.giverandombook: true ecoenchants.command.giverandombook: true
ecoenchants.command.exportlocale: true
ecoenchants.command.ecoenchants: true ecoenchants.command.ecoenchants: true
ecoenchants.fromtable.*: ecoenchants.fromtable.*:
description: Allows getting all enchantments from an enchanting table description: Allows getting all enchantments from an enchanting table
@ -87,6 +88,9 @@ permissions:
ecoenchants.command.randomenchant.bypasshardcap: ecoenchants.command.randomenchant.bypasshardcap:
description: Allows /ecoenchants randomenchant bypassing the anvil hard cap description: Allows /ecoenchants randomenchant bypassing the anvil hard cap
default: op default: op
ecoenchants.command.exportlocale:
description: Allows the use of /ecoenchants exportlocale to export all language config to hastebin.
default: op
ecoenchants.command.ecoenchants: ecoenchants.command.ecoenchants:
description: Allows the use of /ecoenchants description: Allows the use of /ecoenchants
default: true default: true