mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 03:55:27 +01:00
Add basic locale support.
This commit is contained in:
parent
4fc7519880
commit
0cd5df0a5e
@ -1,5 +1,6 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import co.aikar.commands.annotation.CommandAlias;
|
||||
import co.aikar.commands.annotation.CommandCompletion;
|
||||
import co.aikar.commands.annotation.CommandPermission;
|
||||
@ -9,6 +10,7 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.messaging.CoreMessageKeys;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -22,35 +24,35 @@ public class DebugCommand extends MultiverseCoreCommand {
|
||||
|
||||
@Subcommand("debug")
|
||||
@CommandPermission("multiverse.core.debug")
|
||||
@Description("Show the current debug level.")
|
||||
public void onShowDebugCommand(@NotNull CommandSender sender) {
|
||||
this.displayDebugMode(sender);
|
||||
@Description("{@@mv-core.debug_info_description}")
|
||||
public void onShowDebugCommand(@NotNull CommandIssuer issuer) {
|
||||
this.displayDebugMode(issuer);
|
||||
}
|
||||
|
||||
@Subcommand("debug")
|
||||
@CommandPermission("multiverse.core.debug")
|
||||
@Syntax("<level>")
|
||||
@CommandCompletion("@toggles|@range:3")
|
||||
@Description("Change debug level.")
|
||||
public void onChangeDebugCommand(@NotNull CommandSender sender,
|
||||
@Syntax("<{@@mv-core.debug_change_syntax}>")
|
||||
@CommandCompletion("@range:3")
|
||||
@Description("{@@mv-core.debug_change_description}")
|
||||
public void onChangeDebugCommand(@NotNull CommandIssuer issuer,
|
||||
|
||||
@Conditions("debuglevel")
|
||||
@Syntax("<level>")
|
||||
@Description("Debug level to set to.")
|
||||
@Syntax("<{@@mv-core.debug_change_syntax}>")
|
||||
@Description("{@@mv-core.debug_change_level_description}")
|
||||
int level) {
|
||||
|
||||
this.plugin.getMVConfig().setGlobalDebug(level);
|
||||
this.saveMVConfigs(sender);
|
||||
this.displayDebugMode(sender);
|
||||
this.saveMVConfigs(issuer);
|
||||
this.displayDebugMode(issuer);
|
||||
}
|
||||
|
||||
private void displayDebugMode(@NotNull CommandSender sender) {
|
||||
private void displayDebugMode(@NotNull CommandIssuer issuer) {
|
||||
final int debugLevel = this.plugin.getMVConfig().getGlobalDebug();
|
||||
if (debugLevel == 0) {
|
||||
sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF");
|
||||
issuer.sendInfo(CoreMessageKeys.DEBUG_INFO_OFF);
|
||||
return;
|
||||
}
|
||||
sender.sendMessage("Multiverse Debug mode is at level " + ChatColor.GREEN + debugLevel);
|
||||
Logging.fine("Multiverse Debug ENABLED");
|
||||
issuer.sendInfo(CoreMessageKeys.DEBUG_INFO_ON, "{level}", String.valueOf(debugLevel));
|
||||
Logging.fine("Multiverse Debug ENABLED.");
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.onarandombox.MultiverseCore.commands;
|
||||
|
||||
import co.aikar.commands.CommandIssuer;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import com.onarandombox.MultiverseCore.messaging.CoreMessageKeys;
|
||||
|
||||
/**
|
||||
* Generic multiverse core command with handy reference to the plugin instance.
|
||||
@ -16,12 +16,11 @@ public abstract class MultiverseCoreCommand extends MultiverseCommand {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected boolean saveMVConfigs(CommandSender sender) {
|
||||
protected boolean saveMVConfigs(CommandIssuer issuer) {
|
||||
if (this.plugin.saveMVConfigs()) {
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(ChatColor.RED + "An error occurred while trying to save Multiverse-Core config.yml. " +
|
||||
"You changes will be temporary!");
|
||||
issuer.sendError(CoreMessageKeys.CONFIG_SAVE_FAILED);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import co.aikar.commands.PaperCommandManager;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.commands.DebugCommand;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Main class to manage permissions.
|
||||
*/
|
||||
@ -20,6 +22,11 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
|
||||
// Setup locale
|
||||
this.addSupportedLanguage(Locale.ENGLISH);
|
||||
this.locales.addMessageBundles("multiverse-core");
|
||||
this.locales.loadLanguages();
|
||||
|
||||
// Register commands
|
||||
this.registerCommand(new DebugCommand(plugin));
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.onarandombox.MultiverseCore.messaging;
|
||||
|
||||
import co.aikar.locales.MessageKey;
|
||||
import co.aikar.locales.MessageKeyProvider;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum CoreMessageKeys implements MessageKeyProvider {
|
||||
|
||||
CONFIG_SAVE_FAILED,
|
||||
DEBUG_INFO_OFF,
|
||||
DEBUG_INFO_ON;
|
||||
|
||||
private final MessageKey key = MessageKey.of("mv-core." + this.name().toLowerCase(Locale.ENGLISH));
|
||||
|
||||
@Override
|
||||
public MessageKey getMessageKey() {
|
||||
return this.key;
|
||||
}
|
||||
}
|
7
src/main/resources/multiverse-core_en.properties
Normal file
7
src/main/resources/multiverse-core_en.properties
Normal file
@ -0,0 +1,7 @@
|
||||
mv-core.config_save_failed=§cUnable to save Multiverse-Core config.yml. Your changes will be temporary!
|
||||
mv-core.debug_info_description=Show the current debug level.
|
||||
mv-core.debug_info_off=§fMultiverse Debug mode is §cOFF§f.
|
||||
mv-core.debug_info_on=§fMultiverse Debug mode is at §alevel {level}§f.
|
||||
mv-core.debug_change_description=Change debug level.
|
||||
mv-core.debug_change_syntax=level
|
||||
mv-core.debug_change_level_description=Debug level to set to.
|
Loading…
Reference in New Issue
Block a user