mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-02 22:47:43 +01:00
Revert "New Locale system - it breaks everything"
This reverts commit 9a3c900ac5
.
This commit is contained in:
parent
9a3c900ac5
commit
1e4dd979ae
@ -9,9 +9,9 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
||||||
import us.tastybento.bskyblock.api.localization.BSBLocale;
|
|
||||||
import us.tastybento.bskyblock.commands.AdminCommand;
|
import us.tastybento.bskyblock.commands.AdminCommand;
|
||||||
import us.tastybento.bskyblock.commands.IslandCommand;
|
import us.tastybento.bskyblock.commands.IslandCommand;
|
||||||
|
import us.tastybento.bskyblock.config.BSBLocale;
|
||||||
import us.tastybento.bskyblock.config.LocaleManager;
|
import us.tastybento.bskyblock.config.LocaleManager;
|
||||||
import us.tastybento.bskyblock.config.PluginConfig;
|
import us.tastybento.bskyblock.config.PluginConfig;
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
@ -244,10 +244,19 @@ public class BSkyBlock extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LocaleManager object
|
* @param sender
|
||||||
|
* @return Locale object for sender
|
||||||
*/
|
*/
|
||||||
public LocaleManager getLocaleManager() {
|
public BSBLocale getLocale(CommandSender sender) {
|
||||||
return localeManager;
|
return localeManager.getLocale(sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param uuid
|
||||||
|
* @return Locale object for UUID
|
||||||
|
*/
|
||||||
|
public BSBLocale getLocale(UUID uuid) {
|
||||||
|
return localeManager.getLocale(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.events.command.CommandEvent;
|
import us.tastybento.bskyblock.api.events.command.CommandEvent;
|
||||||
|
import us.tastybento.bskyblock.config.BSBLocale;
|
||||||
import us.tastybento.bskyblock.database.managers.PlayersManager;
|
import us.tastybento.bskyblock.database.managers.PlayersManager;
|
||||||
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
|
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
import us.tastybento.bskyblock.util.Util;
|
||||||
@ -64,11 +65,11 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
Util.sendMessage(sender, "help.header");
|
Util.sendMessage(sender, plugin.getLocale(sender).get("help.header"));
|
||||||
for(ArgumentHandler handler: handlers) {
|
for(ArgumentHandler handler: handlers) {
|
||||||
if (handler.canUse(sender).isAllowed()) Util.sendMessage(sender, handler.getShortDescription(sender));
|
if (handler.canUse(sender).isAllowed()) Util.sendMessage(sender, handler.getShortDescription(sender));
|
||||||
}
|
}
|
||||||
Util.sendMessage(sender, "help.end");
|
Util.sendMessage(sender, plugin.getLocale(sender).get("help.end"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -78,7 +79,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] usage(CommandSender sender) {
|
public String[] usage(CommandSender sender) {
|
||||||
return new String[] {"", "help.this"};
|
return new String[] {"", plugin.getLocale(sender).get("help.this")};
|
||||||
}
|
}
|
||||||
}.alias("help").alias("?"));
|
}.alias("help").alias("?"));
|
||||||
}
|
}
|
||||||
@ -220,6 +221,22 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
|||||||
protected IslandsManager getIslands() {
|
protected IslandsManager getIslands() {
|
||||||
return plugin.getIslands();
|
return plugin.getIslands();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param sender
|
||||||
|
* @return Locale for sender
|
||||||
|
*/
|
||||||
|
protected BSBLocale getLocale(CommandSender sender) {
|
||||||
|
return plugin.getLocale(sender);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param uuid
|
||||||
|
* @return Locale for UUID
|
||||||
|
*/
|
||||||
|
protected BSBLocale getLocale(UUID uuid) {
|
||||||
|
return plugin.getLocale(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Map<String, ArgumentHandler> getArgumentsMap() {
|
public Map<String, ArgumentHandler> getArgumentsMap() {
|
||||||
return argumentsMap;
|
return argumentsMap;
|
||||||
|
@ -29,7 +29,7 @@ public abstract class ArgumentHandler {
|
|||||||
|
|
||||||
public String getShortDescription(CommandSender sender) {
|
public String getShortDescription(CommandSender sender) {
|
||||||
// syntax: " &7/&b[label] &c[command] &a[args] &7: &e[info]"
|
// syntax: " &7/&b[label] &c[command] &a[args] &7: &e[info]"
|
||||||
String msg = plugin.getLocaleManager().get(sender, "help.syntax");
|
String msg = plugin.getLocale(sender).get("help.syntax");
|
||||||
msg = msg.replace("[label]", label);
|
msg = msg.replace("[label]", label);
|
||||||
|
|
||||||
String cmds = "";
|
String cmds = "";
|
||||||
@ -37,7 +37,7 @@ public abstract class ArgumentHandler {
|
|||||||
if (cmds.isEmpty()) {
|
if (cmds.isEmpty()) {
|
||||||
cmds = alias;
|
cmds = alias;
|
||||||
} else {
|
} else {
|
||||||
cmds += plugin.getLocaleManager().get(sender, "help.syntax-alias-separator") + alias;
|
cmds += plugin.getLocale(sender).get("help.syntax-alias-separator") + alias;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,76 +0,0 @@
|
|||||||
package us.tastybento.bskyblock.api.localization;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
|
||||||
import us.tastybento.bskyblock.config.LocaleManager;
|
|
||||||
import us.tastybento.bskyblock.util.YamlResourceBundle;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.ResourceBundle;
|
|
||||||
|
|
||||||
public class BSBLocale {
|
|
||||||
|
|
||||||
private BSkyBlock plugin = BSkyBlock.getPlugin();
|
|
||||||
|
|
||||||
private Locale locale;
|
|
||||||
private ResourceBundle resourceBundle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads the locale into a ResourceBundle.
|
|
||||||
* Locale files are .yml and have the filename "[identifier]_[country and language tag].yml", e.g. bsb_en_GB.yml or levels_fr_FR.yml
|
|
||||||
*
|
|
||||||
* @param identifier
|
|
||||||
* @param languageTag
|
|
||||||
*
|
|
||||||
* @throws MalformedURLException
|
|
||||||
*/
|
|
||||||
public BSBLocale(String identifier, String languageTag) throws MalformedURLException {
|
|
||||||
this.locale = Locale.forLanguageTag(languageTag);
|
|
||||||
File localeDir = new File(plugin.getDataFolder(), LocaleManager.LOCALE_FOLDER);
|
|
||||||
this.resourceBundle = ResourceBundle.getBundle(identifier, locale, new URLClassLoader(new URL[] {localeDir.toURI().toURL()}), YamlResourceBundle.Control.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get text from the yml file for this locale
|
|
||||||
*
|
|
||||||
* @param reference - the YAML node where the text is
|
|
||||||
*
|
|
||||||
* @return Text for this locale reference or the reference if nothing has been found
|
|
||||||
*/
|
|
||||||
public String get(String reference) {
|
|
||||||
if (resourceBundle.containsKey(reference)) {
|
|
||||||
return ChatColor.translateAlternateColorCodes('&', resourceBundle.getString(reference));
|
|
||||||
}
|
|
||||||
return reference; // Return reference in case nothing has been found
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the locale language
|
|
||||||
* @return the locale language
|
|
||||||
*/
|
|
||||||
public String getLanguageName(){
|
|
||||||
if(locale == null) return "unknown";
|
|
||||||
return locale.getDisplayLanguage(locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the locale country
|
|
||||||
* @return the locale country
|
|
||||||
*/
|
|
||||||
public String getCountryName(){
|
|
||||||
if(locale == null) return "unknown";
|
|
||||||
return locale.getDisplayCountry(locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the locale language tag (e.g: en-GB)
|
|
||||||
* @return the locale language tag
|
|
||||||
*/
|
|
||||||
public String getLanguageTag(){
|
|
||||||
return locale.toLanguageTag();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package us.tastybento.bskyblock.api.localization;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class LocaleHandler {
|
|
||||||
|
|
||||||
private String identifier;
|
|
||||||
private Map<String, BSBLocale> locales;
|
|
||||||
|
|
||||||
public LocaleHandler(String identifier) {
|
|
||||||
this.identifier = identifier;
|
|
||||||
this.locales = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setupLocales() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadLocales() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public BSBLocale getLocale(String languageTag) {
|
|
||||||
return locales.getOrDefault(languageTag, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, BSBLocale> getLocales() {
|
|
||||||
return this.locales;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIdentifier() {
|
|
||||||
return this.identifier;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package us.tastybento.bskyblock.api.localization;
|
|
||||||
|
|
||||||
public class Variable {
|
|
||||||
|
|
||||||
private String placeholder;
|
|
||||||
private String replacement;
|
|
||||||
|
|
||||||
public Variable(String placeholder, String replacement) {
|
|
||||||
this.placeholder = placeholder;
|
|
||||||
this.replacement = replacement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String apply(String s) {
|
|
||||||
return s.replace(this.placeholder, this.replacement);
|
|
||||||
}
|
|
||||||
}
|
|
@ -63,12 +63,12 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
@Override
|
@Override
|
||||||
public CanUseResp canUse(CommandSender sender) {
|
public CanUseResp canUse(CommandSender sender) {
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return new CanUseResp(Util.getMessage(sender, "general.errors.use-in-game"));
|
return new CanUseResp(getLocale(sender).get("general.errors.use-in-game"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Basic permission check to even use /island
|
// Basic permission check to even use /island
|
||||||
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")) {
|
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")) {
|
||||||
return new CanUseResp(Util.getMessage(sender, "general.errors.no-permission"));
|
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CanUseResp(true);
|
return new CanUseResp(true);
|
||||||
@ -1535,7 +1535,7 @@ public class IslandCommand extends AbstractCommand {
|
|||||||
.build();
|
.build();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Could not create island for player.");
|
plugin.getLogger().severe("Could not create island for player.");
|
||||||
Util.sendMessage(player, "general.errors.general");
|
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.general"));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,125 @@
|
|||||||
|
package us.tastybento.bskyblock.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import us.tastybento.bskyblock.util.FileLister;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles locale functions
|
||||||
|
* @author ben
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class AbstractLocaleManager {
|
||||||
|
private Plugin plugin;
|
||||||
|
private HashMap<String, BSBLocale> locales = new HashMap<>();
|
||||||
|
final static String LOCALE_FOLDER = "locales";
|
||||||
|
|
||||||
|
public AbstractLocaleManager(Plugin plugin) {
|
||||||
|
super();
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.loadLocales();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an HashMap of locale identifier and the related object
|
||||||
|
* @return the locales
|
||||||
|
*/
|
||||||
|
public HashMap<String, BSBLocale> getLocales(){
|
||||||
|
return locales;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the available locales
|
||||||
|
* @param locales - the locales to set
|
||||||
|
*/
|
||||||
|
public void setLocales(HashMap<String, BSBLocale> locales){
|
||||||
|
this.locales = locales;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default locale
|
||||||
|
* @return the default locale
|
||||||
|
*/
|
||||||
|
public BSBLocale getLocale(){
|
||||||
|
return locales.get(Settings.defaultLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale for the specified CommandSender
|
||||||
|
* @param sender - CommandSender to get the locale
|
||||||
|
* @return if sender is a player, the player's locale, otherwise the default locale
|
||||||
|
*/
|
||||||
|
public BSBLocale getLocale(CommandSender sender){
|
||||||
|
if(sender instanceof Player) return getLocale(((Player) sender).getUniqueId());
|
||||||
|
else return getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale for the specified player
|
||||||
|
* @param player - Player to get the locale
|
||||||
|
* @return the locale for this player
|
||||||
|
*/
|
||||||
|
public abstract BSBLocale getLocale(UUID player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all the locales available. If the locale folder does not exist, one will be created and
|
||||||
|
* filled with locale files from the jar.
|
||||||
|
*/
|
||||||
|
public void loadLocales() {
|
||||||
|
// Describe the filter - we only want files that are correctly named
|
||||||
|
FilenameFilter ymlFilter = new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
//plugin.getLogger().info("DEBUG: filename = " + name);
|
||||||
|
if (name.toLowerCase().startsWith("bsb_") && name.toLowerCase().endsWith(".yml")) {
|
||||||
|
// See if this is a valid locale
|
||||||
|
//Locale localeObject = new Locale(name.substring(0, 2), name.substring(3, 5));
|
||||||
|
Locale localeObject = Locale.forLanguageTag(name.substring(4, name.length() - 4));
|
||||||
|
if (localeObject == null) {
|
||||||
|
plugin.getLogger().severe("Filename '" + name + "' is an unknown locale, skipping...");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (name.toLowerCase().endsWith(".yml")) {
|
||||||
|
plugin.getLogger().severe("Filename '" + name + "' is not in the correct format for a locale file - skipping...");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Run through the files and store the locales
|
||||||
|
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER);
|
||||||
|
// If the folder does not exist, then make it and fill with the locale files from the jar
|
||||||
|
if (!localeDir.exists()) {
|
||||||
|
localeDir.mkdir();
|
||||||
|
FileLister lister = new FileLister(plugin);
|
||||||
|
try {
|
||||||
|
for (String name : lister.listJar(LOCALE_FOLDER)) {
|
||||||
|
plugin.saveResource(name,true);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Store all the locales available
|
||||||
|
for (String language : localeDir.list(ymlFilter)) {
|
||||||
|
try {
|
||||||
|
BSBLocale locale = new BSBLocale(plugin, language);
|
||||||
|
locales.put(locale.getLocaleId(), locale);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
99
src/main/java/us/tastybento/bskyblock/config/BSBLocale.java
Normal file
99
src/main/java/us/tastybento/bskyblock/config/BSBLocale.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
package us.tastybento.bskyblock.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class BSBLocale {
|
||||||
|
|
||||||
|
final static String LOCALE_FOLDER = "locales";
|
||||||
|
private Plugin plugin;
|
||||||
|
//private String localeId;
|
||||||
|
private String languageTag;
|
||||||
|
private ResourceBundle rb;
|
||||||
|
Locale localeObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides localization
|
||||||
|
* Locale files are .yml and have the filename "bsb_[country and language tag].yml", e.g. bsb_en_GB.yml
|
||||||
|
* @param plugin
|
||||||
|
* @throws MalformedURLException
|
||||||
|
*/
|
||||||
|
public BSBLocale(Plugin plugin, String localeId) throws MalformedURLException {
|
||||||
|
this.plugin = plugin;
|
||||||
|
//this.localeId = localeId;
|
||||||
|
// Check if the folder exists
|
||||||
|
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER);
|
||||||
|
if (!localeDir.exists()) {
|
||||||
|
localeDir.mkdirs();
|
||||||
|
}
|
||||||
|
// Check if this file does not exist
|
||||||
|
File localeFile = new File(localeDir, localeId);
|
||||||
|
if (!localeFile.exists()) {
|
||||||
|
// Does not exist - look in JAR and save if possible
|
||||||
|
plugin.saveResource(LOCALE_FOLDER + localeId, false);
|
||||||
|
}
|
||||||
|
languageTag = localeId.substring(4, localeId.length() - 4).replace('_', '-');
|
||||||
|
URL[] urls = {localeDir.toURI().toURL()};
|
||||||
|
ClassLoader loader = new URLClassLoader(urls);
|
||||||
|
localeObject = Locale.forLanguageTag(languageTag);
|
||||||
|
rb = ResourceBundle.getBundle("bsb", localeObject, loader, YamlResourceBundle.Control.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get text from the yml file for this locale
|
||||||
|
* @param reference - the YAML node where the text is
|
||||||
|
* @return Text for this locale reference or the reference is nothing has been found
|
||||||
|
*/
|
||||||
|
public String get(String reference) {
|
||||||
|
// TODO: add placeholder conversion?
|
||||||
|
//plugin.getLogger().info("DEBUG: default lang = " + Settings.defaultLanguage);
|
||||||
|
//plugin.getLogger().info("DEBUG: this locale = " + languageTag);
|
||||||
|
//plugin.getLogger().info("DEBUG: reference = " + reference);
|
||||||
|
if (rb.containsKey(reference)) {
|
||||||
|
//plugin.getLogger().info("DEBUG: contains key");
|
||||||
|
return ChatColor.translateAlternateColorCodes('&', rb.getString(reference));
|
||||||
|
} else if (!Settings.defaultLanguage.equals(languageTag)){
|
||||||
|
//plugin.getLogger().info("DEBUG: try default");
|
||||||
|
// TODO: Try default lang
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
plugin.getLogger().severe(reference + " not found in " + languageTag + " or default lang " + Settings.defaultLanguage);
|
||||||
|
return reference; // Return reference for debug purposes, like for the mods.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale language
|
||||||
|
* @return the locale language
|
||||||
|
*/
|
||||||
|
public String getLanguageName(){
|
||||||
|
if(localeObject == null) return "unknown";
|
||||||
|
|
||||||
|
return localeObject.getDisplayLanguage(localeObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale country
|
||||||
|
* @return the locale country
|
||||||
|
*/
|
||||||
|
public String getCountryName(){
|
||||||
|
if(localeObject == null) return "unknown";
|
||||||
|
|
||||||
|
return localeObject.getDisplayCountry(localeObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the locale identifier (e.g: en-GB)
|
||||||
|
* @return the locale ID
|
||||||
|
*/
|
||||||
|
public String getLocaleId(){
|
||||||
|
return this.localeObject.toLanguageTag();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,35 +1,37 @@
|
|||||||
package us.tastybento.bskyblock.config;
|
package us.tastybento.bskyblock.config;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
|
||||||
import us.tastybento.bskyblock.api.localization.LocaleHandler;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class LocaleManager {
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
|
|
||||||
public static final String LOCALE_FOLDER = "localization";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the BSkyBlock locale
|
||||||
|
* @author ben
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LocaleManager extends AbstractLocaleManager {
|
||||||
|
|
||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin;
|
||||||
private Map<String, LocaleHandler> handlers = new HashMap<>();
|
|
||||||
|
|
||||||
public LocaleManager(BSkyBlock plugin) {
|
public LocaleManager(BSkyBlock plugin) {
|
||||||
|
super(plugin);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerLocaleHandler(LocaleHandler handler) {
|
@Override
|
||||||
handlers.put(handler.getIdentifier(), handler);
|
/**
|
||||||
handler.setupLocales();
|
* Returns the locale for the specified player
|
||||||
handler.loadLocales();
|
* @param player - Player to get the locale
|
||||||
}
|
* @return the locale for this player
|
||||||
|
*/
|
||||||
|
public BSBLocale getLocale(UUID player){
|
||||||
|
//getLogger().info("DEBUG: " + player);
|
||||||
|
//getLogger().info("DEBUG: " + getPlayers() == null ? "Players is null":"Players in not null");
|
||||||
|
//getLogger().info("DEBUG: " + getPlayers().getPlayer(player));
|
||||||
|
//getLogger().info("DEBUG: " + getPlayers().getPlayer(player).getLocale());
|
||||||
|
String locale = plugin.getPlayers().getPlayer(player).getLocale();
|
||||||
|
if(locale.isEmpty() || !getLocales().containsKey(locale)) return getLocales().get(Settings.defaultLanguage);
|
||||||
|
|
||||||
public String get(CommandSender sender, String reference) {
|
return getLocales().get(locale);
|
||||||
return reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String get(UUID uuid, String reference) {
|
|
||||||
return reference;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package us.tastybento.bskyblock.util;
|
package us.tastybento.bskyblock.config;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.enumeration;
|
import static java.util.Collections.enumeration;
|
@ -21,7 +21,6 @@ import org.bukkit.material.TrapDoor;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.localization.Variable;
|
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||||
@ -624,10 +623,10 @@ public class IslandsManager {
|
|||||||
//home.getChunk().load();
|
//home.getChunk().load();
|
||||||
player.teleport(home);
|
player.teleport(home);
|
||||||
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
||||||
if (number == 1) {
|
if (number ==1 ) {
|
||||||
Util.sendMessage(player, "island.teleport", new Variable("[label]", Settings.ISLANDCOMMAND));
|
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleport").replace("[label]", Settings.ISLANDCOMMAND));
|
||||||
} else {
|
} else {
|
||||||
Util.sendMessage(player, "island.teleported", new Variable("[number]", String.valueOf(number)));
|
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleported").replace("[number]", String.valueOf(number)));
|
||||||
}
|
}
|
||||||
// Exit spectator mode if in it
|
// Exit spectator mode if in it
|
||||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||||
@ -854,6 +853,7 @@ public class IslandsManager {
|
|||||||
* This removes players from an island overworld and nether - used when reseting or deleting an island
|
* This removes players from an island overworld and nether - used when reseting or deleting an island
|
||||||
* Mobs are killed when the chunks are refreshed.
|
* Mobs are killed when the chunks are refreshed.
|
||||||
* @param island to remove players from
|
* @param island to remove players from
|
||||||
|
* @param uuid
|
||||||
*/
|
*/
|
||||||
public void removePlayersFromIsland(final Island island) {
|
public void removePlayersFromIsland(final Island island) {
|
||||||
// Teleport players away
|
// Teleport players away
|
||||||
@ -929,6 +929,7 @@ public class IslandsManager {
|
|||||||
/**
|
/**
|
||||||
* Puts a player in a team. Removes them from their old island if required.
|
* Puts a player in a team. Removes them from their old island if required.
|
||||||
* @param playerUUID
|
* @param playerUUID
|
||||||
|
* @param teamLeader
|
||||||
* @return true if successful, false if not
|
* @return true if successful, false if not
|
||||||
*/
|
*/
|
||||||
public boolean setJoinTeam(Island teamIsland, UUID playerUUID) {
|
public boolean setJoinTeam(Island teamIsland, UUID playerUUID) {
|
||||||
|
@ -77,7 +77,7 @@ public class JoinLeaveListener implements Listener {
|
|||||||
&& !VaultHelper.hasPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
|
&& !VaultHelper.hasPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
||||||
Util.sendMessage(player, "island.locked");
|
Util.sendMessage(player, plugin.getLocale(player.getUniqueId()).get("locked.islandlocked"));
|
||||||
plugin.getIslands().homeTeleport(player);
|
plugin.getIslands().homeTeleport(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ public class NetherPortals implements Listener {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: Portal use not allowed");
|
plugin.getLogger().info("DEBUG: Portal use not allowed");
|
||||||
if (!event.getPlayer().isOp() && !VaultHelper.hasPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
if (!event.getPlayer().isOp() && !VaultHelper.hasPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) {
|
||||||
Util.sendMessage(event.getPlayer(), "island.protected");
|
Util.sendMessage(event.getPlayer(), plugin.getLocale(event.getPlayer().getUniqueId()).get("island.protected"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ public class NetherPortals implements Listener {
|
|||||||
// end_place.getBlock().getType(),end_place.getBlock().getData());
|
// end_place.getBlock().getType(),end_place.getBlock().getData());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
Util.sendMessage(event.getPlayer(), "warps.error.not-safe");
|
Util.sendMessage(event.getPlayer(), plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe"));
|
||||||
plugin.getIslands().homeTeleport(event.getPlayer());
|
plugin.getIslands().homeTeleport(event.getPlayer());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ public class NetherPortals implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic");
|
plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic");
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Util.sendMessage(event.getPlayer(), "warps.error.not-safe");
|
Util.sendMessage(event.getPlayer(), plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ public class IslandGuard implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Elsewhere - not allowed
|
// Elsewhere - not allowed
|
||||||
Util.sendMessage(event.getWhoClicked(), "island.protected");
|
Util.sendMessage(event.getWhoClicked(), plugin.getLocale(event.getWhoClicked().getUniqueId()).get("island.protected"));
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,18 +9,17 @@ import us.tastybento.bskyblock.api.panels.Panel;
|
|||||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||||
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||||
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||||
import us.tastybento.bskyblock.util.Util;
|
|
||||||
|
|
||||||
public class LanguagePanel {
|
public class LanguagePanel {
|
||||||
|
|
||||||
public static void openPanel(Player player) {
|
public static void openPanel(Player player) {
|
||||||
PanelBuilder panelBuilder = new PanelBuilder()
|
PanelBuilder panelBuilder = new PanelBuilder()
|
||||||
.setName(Util.getMessage(player, "panel.languages.title"));
|
.setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages"));
|
||||||
|
|
||||||
PanelItem test = new PanelItemBuilder()
|
PanelItem test = new PanelItemBuilder()
|
||||||
.setIcon(new ItemStack(Material.BEDROCK))
|
.setIcon(new ItemStack(Material.BEDROCK))
|
||||||
.setName(Util.getMessage(player, "panel.languages.test.name"))
|
.setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.test.name"))
|
||||||
.setDescription(Util.getMessage(player, "panel.languages.test.description"))
|
.setDescription(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.test.description"))
|
||||||
.setGlow(true)
|
.setGlow(true)
|
||||||
.setClickHandler(new PanelItem.ClickHandler() {
|
.setClickHandler(new PanelItem.ClickHandler() {
|
||||||
@Override
|
@Override
|
||||||
@ -33,8 +32,8 @@ public class LanguagePanel {
|
|||||||
|
|
||||||
PanelItem something = new PanelItemBuilder()
|
PanelItem something = new PanelItemBuilder()
|
||||||
.setIcon(new ItemStack(Material.ANVIL))
|
.setIcon(new ItemStack(Material.ANVIL))
|
||||||
.setName(Util.getMessage(player, "panel.languages.something.name"))
|
.setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.something.name"))
|
||||||
.setDescription(Util.getMessage(player, "panel.languages.something.description"))
|
.setDescription(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.something.description"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
panelBuilder.addItem(1, test);
|
panelBuilder.addItem(1, test);
|
||||||
|
@ -52,7 +52,6 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.localization.Variable;
|
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.config.Settings.GameType;
|
import us.tastybento.bskyblock.config.Settings.GameType;
|
||||||
import us.tastybento.bskyblock.database.objects.Island;
|
import us.tastybento.bskyblock.database.objects.Island;
|
||||||
@ -973,16 +972,16 @@ public class Schematic {
|
|||||||
Sign sign = (Sign) signState;
|
Sign sign = (Sign) signState;
|
||||||
if (sign.getLine(0).isEmpty()) {
|
if (sign.getLine(0).isEmpty()) {
|
||||||
// TODO Add sign
|
// TODO Add sign
|
||||||
sign.setLine(0, Util.getMessage(player, "sign.line1", new Variable("[player]", player.getName())));
|
sign.setLine(0, plugin.getLocale(player.getUniqueId()).get("sign.line1").replace("[player]", player.getName()));
|
||||||
}
|
}
|
||||||
if (sign.getLine(1).isEmpty()) {
|
if (sign.getLine(1).isEmpty()) {
|
||||||
sign.setLine(1, Util.getMessage(player, "sign.line2", new Variable("[player]", player.getName())));
|
sign.setLine(1, plugin.getLocale(player.getUniqueId()).get("sign.line2").replace("[player]", player.getName()));
|
||||||
}
|
}
|
||||||
if (sign.getLine(2).isEmpty()) {
|
if (sign.getLine(2).isEmpty()) {
|
||||||
sign.setLine(2, Util.getMessage(player, "sign.line3", new Variable("[player]", player.getName())));
|
sign.setLine(2, plugin.getLocale(player.getUniqueId()).get("sign.line3").replace("[player]", player.getName()));
|
||||||
}
|
}
|
||||||
if (sign.getLine(3).isEmpty()) {
|
if (sign.getLine(3).isEmpty()) {
|
||||||
sign.setLine(3, Util.getMessage(player, "sign.line4", new Variable("[player]", player.getName())));
|
sign.setLine(3, plugin.getLocale(player.getUniqueId()).get("sign.line4").replace("[player]", player.getName()));
|
||||||
}
|
}
|
||||||
// BlockFace direction = ((org.bukkit.material.Sign)
|
// BlockFace direction = ((org.bukkit.material.Sign)
|
||||||
// sign.getData()).getFacing();
|
// sign.getData()).getFacing();
|
||||||
|
@ -29,7 +29,6 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
|||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.localization.Variable;
|
|
||||||
import us.tastybento.bskyblock.config.Settings;
|
import us.tastybento.bskyblock.config.Settings;
|
||||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||||
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
||||||
@ -44,23 +43,8 @@ import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler;
|
|||||||
public class Util {
|
public class Util {
|
||||||
private static BSkyBlock plugin = BSkyBlock.getPlugin();
|
private static BSkyBlock plugin = BSkyBlock.getPlugin();
|
||||||
|
|
||||||
/**
|
public static void sendMessage(CommandSender receiver, String message){
|
||||||
* Temporary placeholder method. Wont stay.
|
|
||||||
* @param receiver
|
|
||||||
* @param reference
|
|
||||||
* @param variables
|
|
||||||
*/
|
|
||||||
public static String getMessage(CommandSender receiver, String reference, Variable... variables) {
|
|
||||||
String message = plugin.getLocaleManager().get(receiver, reference);
|
|
||||||
for (Variable variable: variables) {
|
|
||||||
message = variable.apply(message);
|
|
||||||
}
|
|
||||||
message = PlaceholderHandler.replacePlaceholders(receiver, message);
|
message = PlaceholderHandler.replacePlaceholders(receiver, message);
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendMessage(CommandSender receiver, String reference, Variable... variables){
|
|
||||||
String message = getMessage(receiver, reference, variables);
|
|
||||||
|
|
||||||
if (!ChatColor.stripColor(message).trim().isEmpty()) {
|
if (!ChatColor.stripColor(message).trim().isEmpty()) {
|
||||||
for(String part : message.split("\n")){
|
for(String part : message.split("\n")){
|
||||||
|
Loading…
Reference in New Issue
Block a user