From 1e4dd979ae95ddb4e01fcc692a9ebb6387020c43 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Sun, 3 Dec 2017 17:34:31 +0100 Subject: [PATCH] Revert "New Locale system - it breaks everything" This reverts commit 9a3c900ac5feb263367855e4e92383bec2ea8b81. --- .../us/tastybento/bskyblock/BSkyBlock.java | 17 ++- .../api/commands/AbstractCommand.java | 23 +++- .../api/commands/ArgumentHandler.java | 4 +- .../bskyblock/api/localization/BSBLocale.java | 76 ----------- .../api/localization/LocaleHandler.java | 35 ----- .../bskyblock/api/localization/Variable.java | 16 --- .../bskyblock/commands/IslandCommand.java | 6 +- .../config/AbstractLocaleManager.java | 125 ++++++++++++++++++ .../bskyblock/config/BSBLocale.java | 99 ++++++++++++++ .../bskyblock/config/LocaleManager.java | 44 +++--- .../{util => config}/YamlResourceBundle.java | 2 +- .../managers/island/IslandsManager.java | 9 +- .../listeners/JoinLeaveListener.java | 2 +- .../bskyblock/listeners/NetherPortals.java | 6 +- .../listeners/protection/IslandGuard.java | 2 +- .../bskyblock/panels/LanguagePanel.java | 11 +- .../bskyblock/schematics/Schematic.java | 9 +- .../us/tastybento/bskyblock/util/Util.java | 18 +-- 18 files changed, 306 insertions(+), 198 deletions(-) delete mode 100644 src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java delete mode 100644 src/main/java/us/tastybento/bskyblock/api/localization/LocaleHandler.java delete mode 100644 src/main/java/us/tastybento/bskyblock/api/localization/Variable.java create mode 100644 src/main/java/us/tastybento/bskyblock/config/AbstractLocaleManager.java create mode 100644 src/main/java/us/tastybento/bskyblock/config/BSBLocale.java rename src/main/java/us/tastybento/bskyblock/{util => config}/YamlResourceBundle.java (99%) diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index 88de8b99f..5b67a572e 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -9,9 +9,9 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; 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.IslandCommand; +import us.tastybento.bskyblock.config.BSBLocale; import us.tastybento.bskyblock.config.LocaleManager; import us.tastybento.bskyblock.config.PluginConfig; 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() { - return localeManager; + public BSBLocale getLocale(CommandSender sender) { + return localeManager.getLocale(sender); + } + + /** + * @param uuid + * @return Locale object for UUID + */ + public BSBLocale getLocale(UUID uuid) { + return localeManager.getLocale(uuid); } /** diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java b/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java index 108dd8bc1..83a71bca1 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/AbstractCommand.java @@ -18,6 +18,7 @@ import org.bukkit.entity.Player; import us.tastybento.bskyblock.BSkyBlock; 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.island.IslandsManager; import us.tastybento.bskyblock.util.Util; @@ -64,11 +65,11 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { @Override 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) { 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 @@ -78,7 +79,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { @Override public String[] usage(CommandSender sender) { - return new String[] {"", "help.this"}; + return new String[] {"", plugin.getLocale(sender).get("help.this")}; } }.alias("help").alias("?")); } @@ -220,6 +221,22 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter { protected IslandsManager 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 getArgumentsMap() { return argumentsMap; diff --git a/src/main/java/us/tastybento/bskyblock/api/commands/ArgumentHandler.java b/src/main/java/us/tastybento/bskyblock/api/commands/ArgumentHandler.java index 45f50af31..c659532b4 100644 --- a/src/main/java/us/tastybento/bskyblock/api/commands/ArgumentHandler.java +++ b/src/main/java/us/tastybento/bskyblock/api/commands/ArgumentHandler.java @@ -29,7 +29,7 @@ public abstract class ArgumentHandler { public String getShortDescription(CommandSender sender) { // 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); String cmds = ""; @@ -37,7 +37,7 @@ public abstract class ArgumentHandler { if (cmds.isEmpty()) { cmds = alias; } else { - cmds += plugin.getLocaleManager().get(sender, "help.syntax-alias-separator") + alias; + cmds += plugin.getLocale(sender).get("help.syntax-alias-separator") + alias; } } diff --git a/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java b/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java deleted file mode 100644 index 621ce730b..000000000 --- a/src/main/java/us/tastybento/bskyblock/api/localization/BSBLocale.java +++ /dev/null @@ -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(); - } -} diff --git a/src/main/java/us/tastybento/bskyblock/api/localization/LocaleHandler.java b/src/main/java/us/tastybento/bskyblock/api/localization/LocaleHandler.java deleted file mode 100644 index 70114712c..000000000 --- a/src/main/java/us/tastybento/bskyblock/api/localization/LocaleHandler.java +++ /dev/null @@ -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 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 getLocales() { - return this.locales; - } - - public String getIdentifier() { - return this.identifier; - } -} diff --git a/src/main/java/us/tastybento/bskyblock/api/localization/Variable.java b/src/main/java/us/tastybento/bskyblock/api/localization/Variable.java deleted file mode 100644 index 2d0416efe..000000000 --- a/src/main/java/us/tastybento/bskyblock/api/localization/Variable.java +++ /dev/null @@ -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); - } -} diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index 38cdcf4d5..881afefc0 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -63,12 +63,12 @@ public class IslandCommand extends AbstractCommand { @Override public CanUseResp canUse(CommandSender sender) { 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 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); @@ -1535,7 +1535,7 @@ public class IslandCommand extends AbstractCommand { .build(); } catch (IOException e) { 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(); } } diff --git a/src/main/java/us/tastybento/bskyblock/config/AbstractLocaleManager.java b/src/main/java/us/tastybento/bskyblock/config/AbstractLocaleManager.java new file mode 100644 index 000000000..b5703c03c --- /dev/null +++ b/src/main/java/us/tastybento/bskyblock/config/AbstractLocaleManager.java @@ -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 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 getLocales(){ + return locales; + } + + /** + * Set the available locales + * @param locales - the locales to set + */ + public void setLocales(HashMap 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(); + } + + } + } +} diff --git a/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java b/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java new file mode 100644 index 000000000..4b22aaf94 --- /dev/null +++ b/src/main/java/us/tastybento/bskyblock/config/BSBLocale.java @@ -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(); + } + +} diff --git a/src/main/java/us/tastybento/bskyblock/config/LocaleManager.java b/src/main/java/us/tastybento/bskyblock/config/LocaleManager.java index f521f5ca2..2fd00fd6a 100644 --- a/src/main/java/us/tastybento/bskyblock/config/LocaleManager.java +++ b/src/main/java/us/tastybento/bskyblock/config/LocaleManager.java @@ -1,35 +1,37 @@ 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; -public class LocaleManager { - - public static final String LOCALE_FOLDER = "localization"; +import us.tastybento.bskyblock.BSkyBlock; +/** + * Handles the BSkyBlock locale + * @author ben + * + */ +public class LocaleManager extends AbstractLocaleManager { + private BSkyBlock plugin; - private Map handlers = new HashMap<>(); public LocaleManager(BSkyBlock plugin) { + super(plugin); this.plugin = plugin; } - public void registerLocaleHandler(LocaleHandler handler) { - handlers.put(handler.getIdentifier(), handler); - handler.setupLocales(); - handler.loadLocales(); - } + @Override + /** + * Returns the locale for the specified player + * @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 reference; - } - - public String get(UUID uuid, String reference) { - return reference; + return getLocales().get(locale); } } diff --git a/src/main/java/us/tastybento/bskyblock/util/YamlResourceBundle.java b/src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java similarity index 99% rename from src/main/java/us/tastybento/bskyblock/util/YamlResourceBundle.java rename to src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java index abbbe896d..3d9a2db36 100644 --- a/src/main/java/us/tastybento/bskyblock/util/YamlResourceBundle.java +++ b/src/main/java/us/tastybento/bskyblock/config/YamlResourceBundle.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package us.tastybento.bskyblock.util; +package us.tastybento.bskyblock.config; import static java.util.Arrays.asList; import static java.util.Collections.enumeration; diff --git a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java index 8afdd38c7..234f3603d 100644 --- a/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java +++ b/src/main/java/us/tastybento/bskyblock/database/managers/island/IslandsManager.java @@ -21,7 +21,6 @@ import org.bukkit.material.TrapDoor; import org.bukkit.util.Vector; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.api.localization.Variable; import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; @@ -624,10 +623,10 @@ public class IslandsManager { //home.getChunk().load(); player.teleport(home); //player.sendBlockChange(home, Material.GLOWSTONE, (byte)0); - if (number == 1) { - Util.sendMessage(player, "island.teleport", new Variable("[label]", Settings.ISLANDCOMMAND)); + if (number ==1 ) { + Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleport").replace("[label]", Settings.ISLANDCOMMAND)); } 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 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 * Mobs are killed when the chunks are refreshed. * @param island to remove players from + * @param uuid */ public void removePlayersFromIsland(final Island island) { // Teleport players away @@ -929,6 +929,7 @@ public class IslandsManager { /** * Puts a player in a team. Removes them from their old island if required. * @param playerUUID + * @param teamLeader * @return true if successful, false if not */ public boolean setJoinTeam(Island teamIsland, UUID playerUUID) { diff --git a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java index c5277dbe6..6ea42c6ca 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/JoinLeaveListener.java @@ -77,7 +77,7 @@ public class JoinLeaveListener implements Listener { && !VaultHelper.hasPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) { if (DEBUG) 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); } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java index f18bf2cde..6c7ee9b4f 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/NetherPortals.java @@ -117,7 +117,7 @@ public class NetherPortals implements Listener { if (DEBUG) plugin.getLogger().info("DEBUG: Portal use not allowed"); 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); return; } @@ -139,7 +139,7 @@ public class NetherPortals implements Listener { // end_place.getBlock().getType(),end_place.getBlock().getData()); return; } 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()); return; } @@ -229,7 +229,7 @@ public class NetherPortals implements Listener { } else { plugin.getLogger().severe("Cannot teleport player to nether because there is no nether schematic"); 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; } } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java index d11eb8883..a93539184 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/IslandGuard.java @@ -121,7 +121,7 @@ public class IslandGuard implements Listener { return; } // Elsewhere - not allowed - Util.sendMessage(event.getWhoClicked(), "island.protected"); + Util.sendMessage(event.getWhoClicked(), plugin.getLocale(event.getWhoClicked().getUniqueId()).get("island.protected")); event.setCancelled(true); } } diff --git a/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java b/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java index 17e9d776b..fb4b24903 100644 --- a/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java +++ b/src/main/java/us/tastybento/bskyblock/panels/LanguagePanel.java @@ -9,18 +9,17 @@ import us.tastybento.bskyblock.api.panels.Panel; import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.panels.builders.PanelBuilder; import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder; -import us.tastybento.bskyblock.util.Util; public class LanguagePanel { public static void openPanel(Player player) { PanelBuilder panelBuilder = new PanelBuilder() - .setName(Util.getMessage(player, "panel.languages.title")); + .setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages")); PanelItem test = new PanelItemBuilder() .setIcon(new ItemStack(Material.BEDROCK)) - .setName(Util.getMessage(player, "panel.languages.test.name")) - .setDescription(Util.getMessage(player, "panel.languages.test.description")) + .setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.test.name")) + .setDescription(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.test.description")) .setGlow(true) .setClickHandler(new PanelItem.ClickHandler() { @Override @@ -33,8 +32,8 @@ public class LanguagePanel { PanelItem something = new PanelItemBuilder() .setIcon(new ItemStack(Material.ANVIL)) - .setName(Util.getMessage(player, "panel.languages.something.name")) - .setDescription(Util.getMessage(player, "panel.languages.something.description")) + .setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.something.name")) + .setDescription(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.something.description")) .build(); panelBuilder.addItem(1, test); diff --git a/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java b/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java index cd8758584..8893b1857 100644 --- a/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java +++ b/src/main/java/us/tastybento/bskyblock/schematics/Schematic.java @@ -52,7 +52,6 @@ import org.bukkit.util.Vector; import net.milkbowl.vault.economy.EconomyResponse; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.api.localization.Variable; import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings.GameType; import us.tastybento.bskyblock.database.objects.Island; @@ -973,16 +972,16 @@ public class Schematic { Sign sign = (Sign) signState; if (sign.getLine(0).isEmpty()) { // 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()) { - 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()) { - 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()) { - 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) // sign.getData()).getFacing(); diff --git a/src/main/java/us/tastybento/bskyblock/util/Util.java b/src/main/java/us/tastybento/bskyblock/util/Util.java index f1ee4f7d4..1ca0a1b4d 100755 --- a/src/main/java/us/tastybento/bskyblock/util/Util.java +++ b/src/main/java/us/tastybento/bskyblock/util/Util.java @@ -29,7 +29,6 @@ import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.Plugin; import us.tastybento.bskyblock.BSkyBlock; -import us.tastybento.bskyblock.api.localization.Variable; import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.generators.IslandWorld; import us.tastybento.bskyblock.util.nms.NMSAbstraction; @@ -44,23 +43,8 @@ import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler; public class Util { private static BSkyBlock plugin = BSkyBlock.getPlugin(); - /** - * 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); - } + public static void sendMessage(CommandSender receiver, String 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()) { for(String part : message.split("\n")){