mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Merge 2.1.51
This commit is contained in:
commit
3997a44fce
@ -0,0 +1,30 @@
|
||||
package com.gmail.nossr50.commands.admin;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author Mark Vainomaa
|
||||
*/
|
||||
public final class McmmoReloadLocaleCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
if (!Permissions.reloadlocale(sender)) {
|
||||
sender.sendMessage(command.getPermissionMessage());
|
||||
return true;
|
||||
}
|
||||
|
||||
LocaleLoader.reloadLocale();
|
||||
sender.sendMessage(LocaleLoader.getString("Locale.Reloaded"));
|
||||
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,14 +3,25 @@ package com.gmail.nossr50.locale;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public final class LocaleLoader {
|
||||
private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
|
||||
private static Map<String, String> bundleCache = new HashMap<>();
|
||||
private static ResourceBundle bundle = null;
|
||||
private static ResourceBundle filesystemBundle = null;
|
||||
private static ResourceBundle enBundle = null;
|
||||
|
||||
private LocaleLoader() {
|
||||
@ -32,12 +43,38 @@ public final class LocaleLoader {
|
||||
initialize();
|
||||
}
|
||||
|
||||
String rawMessage = bundleCache.computeIfAbsent(key, LocaleLoader::getRawString);
|
||||
return formatString(rawMessage, messageArguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads locale
|
||||
*/
|
||||
public static void reloadLocale() {
|
||||
bundle = null;
|
||||
filesystemBundle = null;
|
||||
enBundle = null;
|
||||
bundleCache = new HashMap<>(); // Cheaper to replace than clear()
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static String getRawString(String key) {
|
||||
if (filesystemBundle != null) {
|
||||
try {
|
||||
return getString(key, bundle, messageArguments);
|
||||
} catch (MissingResourceException ex) {
|
||||
return filesystemBundle.getString(key);
|
||||
}
|
||||
catch (MissingResourceException ignored) {}
|
||||
}
|
||||
|
||||
try {
|
||||
return getString(key, enBundle, messageArguments);
|
||||
} catch (MissingResourceException ex2) {
|
||||
return bundle.getString(key);
|
||||
}
|
||||
catch (MissingResourceException ignored) {}
|
||||
|
||||
try {
|
||||
return enBundle.getString(key);
|
||||
}
|
||||
catch (MissingResourceException ignored) {
|
||||
if (!key.contains("Guides")) {
|
||||
mcMMO.p.getLogger().warning("Could not find locale string: " + key);
|
||||
}
|
||||
@ -45,11 +82,6 @@ public final class LocaleLoader {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getString(String key, ResourceBundle bundle, Object... messageArguments) throws MissingResourceException {
|
||||
return formatString(bundle.getString(key), messageArguments);
|
||||
}
|
||||
|
||||
public static String formatString(String string, Object... messageArguments) {
|
||||
if (messageArguments != null) {
|
||||
@ -82,6 +114,19 @@ public final class LocaleLoader {
|
||||
locale = new Locale(myLocale[0], myLocale[1]);
|
||||
}
|
||||
|
||||
if (locale == null) {
|
||||
throw new IllegalStateException("Failed to parse locale string '" + mcMMO.getConfigManager().getConfigLanguage().getTargetLanguage() + "'");
|
||||
}
|
||||
|
||||
Path localePath = Paths.get(mcMMO.getLocalesDirectory() + "locale_" + locale.toString() + ".properties");
|
||||
if (Files.exists(localePath) && Files.isRegularFile(localePath)) {
|
||||
try (Reader localeReader = Files.newBufferedReader(localePath)) {
|
||||
mcMMO.p.getLogger().log(Level.INFO, "Loading locale from {0}", localePath);
|
||||
filesystemBundle = new PropertyResourceBundle(localeReader);
|
||||
} catch (IOException e) {
|
||||
mcMMO.p.getLogger().log(Level.WARNING, "Failed to load locale from " + localePath, e);
|
||||
}
|
||||
}
|
||||
bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
|
||||
enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
|
||||
}
|
||||
|
@ -90,6 +90,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private static MaterialMapStore materialMapStore;
|
||||
/* File Paths */
|
||||
private static String mainDirectory;
|
||||
private static String localesDirectory;
|
||||
private static String flatFileDirectory;
|
||||
private static String usersFile;
|
||||
private static String modDirectory;
|
||||
@ -421,13 +422,16 @@ public class mcMMO extends JavaPlugin {
|
||||
}
|
||||
|
||||
databaseManager.onDisable();
|
||||
|
||||
//Unload configs last
|
||||
configManager.unloadAllConfigsAndRegisters();
|
||||
|
||||
debug("Was disabled."); // How informative!
|
||||
}
|
||||
|
||||
public static String getLocalesDirectory() {
|
||||
return localesDirectory;
|
||||
}
|
||||
|
||||
public boolean isXPEventEnabled() {
|
||||
return xpEventEnabled;
|
||||
}
|
||||
@ -458,6 +462,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private void setupFilePaths() {
|
||||
mcmmo = getFile();
|
||||
mainDirectory = getDataFolder().getPath() + File.separator;
|
||||
localesDirectory = mainDirectory + "locales" + File.separator;
|
||||
flatFileDirectory = mainDirectory + "flatfile" + File.separator;
|
||||
usersFile = flatFileDirectory + "mcmmo.users";
|
||||
modDirectory = mainDirectory + "mods" + File.separator;
|
||||
@ -511,6 +516,8 @@ public class mcMMO extends JavaPlugin {
|
||||
|
||||
File currentFlatfilePath = new File(flatFileDirectory);
|
||||
currentFlatfilePath.mkdirs();
|
||||
File localesDirectoryPath = new File(localesDirectory);
|
||||
localesDirectoryPath.mkdirs();
|
||||
}
|
||||
|
||||
private void loadConfigFiles() {
|
||||
|
@ -233,6 +233,8 @@ public final class Permissions {
|
||||
return permissible.hasPermission("mcmmo.commands.mmoupdate");
|
||||
}
|
||||
|
||||
public static boolean reloadlocale(Permissible permissible) { return permissible.hasPermission("mcmmo.commands.reloadlocale"); }
|
||||
|
||||
/*
|
||||
* PERKS
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.gmail.nossr50.util.commands;
|
||||
|
||||
import com.gmail.nossr50.commands.*;
|
||||
import com.gmail.nossr50.commands.admin.McmmoReloadLocaleCommand;
|
||||
import com.gmail.nossr50.commands.chat.AdminChatCommand;
|
||||
import com.gmail.nossr50.commands.chat.McChatSpy;
|
||||
import com.gmail.nossr50.commands.chat.PartyChatCommand;
|
||||
@ -408,6 +409,15 @@ public final class CommandRegistrationManager {
|
||||
command.setExecutor(new McImportCommand());
|
||||
}
|
||||
|
||||
private static void registerReloadLocaleCommand() {
|
||||
PluginCommand command = mcMMO.p.getCommand("mcmmoreloadlocale");
|
||||
command.setDescription("Reloads locale"); // TODO: Localize
|
||||
command.setPermission("mcmmo.commands.reloadlocale");
|
||||
command.setPermissionMessage(permissionsMessage);
|
||||
command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcmmoreloadlocale"));
|
||||
command.setExecutor(new McmmoReloadLocaleCommand());
|
||||
}
|
||||
|
||||
public static void registerCommands() {
|
||||
// Generic Commands
|
||||
registerMmoInfoCommand();
|
||||
@ -458,5 +468,7 @@ public final class CommandRegistrationManager {
|
||||
|
||||
//Config Commands
|
||||
registerMcmmoReloadCommand();
|
||||
// Admin commands
|
||||
registerReloadLocaleCommand();
|
||||
}
|
||||
}
|
||||
|
@ -1086,3 +1086,4 @@ Reminder.Squelched=[[GRAY]]Reminder: You are currently not receiving notificatio
|
||||
#Misc
|
||||
Commands.Reload.Start=mcMMO is reloading... this may take a moment
|
||||
Commands.Reload.Finished=mcMMO has finished reloading!
|
||||
Locale.Reloaded=[[GREEN]]Locale reloaded!
|
||||
|
@ -163,6 +163,10 @@ commands:
|
||||
aliases: [macho, jumping, throwing, wrecking, crafting, walking, swimming, falling, climbing, flying, diving, piggy]
|
||||
description: Deploy jokes
|
||||
permission: mcmmo.commands.mcfools
|
||||
mcmmoreloadlocale:
|
||||
aliases: [mcreloadlocale]
|
||||
description: Reloads locale
|
||||
permission: mcmmo.commands.reloadlocale
|
||||
permissions:
|
||||
mcmmo.*:
|
||||
default: false
|
||||
@ -800,6 +804,7 @@ permissions:
|
||||
mcmmo.commands.mmoedit.others: true
|
||||
mcmmo.commands.mmoshowdb: true
|
||||
mcmmo.commands.ptp.world.all: true
|
||||
mcmmo.commands.reloadlocale: true
|
||||
mcmmo.commands.skillreset.all: true
|
||||
mcmmo.commands.xprate.all: true
|
||||
mcmmo.commands.acrobatics:
|
||||
|
Loading…
Reference in New Issue
Block a user