mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 09:08:03 +01:00
New Locale system - it breaks everything
The locales are not being loaded Needs a few more methods to have a convenient way of using it Needs to be fixed
This commit is contained in:
parent
b21e6dbcb0
commit
9a3c900ac5
@ -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,19 +244,10 @@ public class BSkyBlock extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender
|
||||
* @return Locale object for sender
|
||||
* @return LocaleManager object
|
||||
*/
|
||||
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);
|
||||
public LocaleManager getLocaleManager() {
|
||||
return localeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,6 @@ 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;
|
||||
@ -65,11 +64,11 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Util.sendMessage(sender, plugin.getLocale(sender).get("help.header"));
|
||||
Util.sendMessage(sender, "help.header");
|
||||
for(ArgumentHandler handler: handlers) {
|
||||
if (handler.canUse(sender).isAllowed()) Util.sendMessage(sender, handler.getShortDescription(sender));
|
||||
}
|
||||
Util.sendMessage(sender, plugin.getLocale(sender).get("help.end"));
|
||||
Util.sendMessage(sender, "help.end");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,7 +78,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
@Override
|
||||
public String[] usage(CommandSender sender) {
|
||||
return new String[] {"", plugin.getLocale(sender).get("help.this")};
|
||||
return new String[] {"", "help.this"};
|
||||
}
|
||||
}.alias("help").alias("?"));
|
||||
}
|
||||
@ -221,22 +220,6 @@ 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<String, ArgumentHandler> getArgumentsMap() {
|
||||
return argumentsMap;
|
||||
|
@ -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.getLocale(sender).get("help.syntax");
|
||||
String msg = plugin.getLocaleManager().get(sender, "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.getLocale(sender).get("help.syntax-alias-separator") + alias;
|
||||
cmds += plugin.getLocaleManager().get(sender, "help.syntax-alias-separator") + alias;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,76 @@
|
||||
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();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
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
|
||||
public CanUseResp canUse(CommandSender sender) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return new CanUseResp(getLocale(sender).get("general.errors.use-in-game"));
|
||||
return new CanUseResp(Util.getMessage(sender, "general.errors.use-in-game"));
|
||||
}
|
||||
|
||||
// Basic permission check to even use /island
|
||||
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")) {
|
||||
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
|
||||
return new CanUseResp(Util.getMessage(sender, "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, ChatColor.RED + plugin.getLocale(player).get("general.errors.general"));
|
||||
Util.sendMessage(player, "general.errors.general");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -1,125 +0,0 @@
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
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,37 +1,35 @@
|
||||
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 us.tastybento.bskyblock.BSkyBlock;
|
||||
public class LocaleManager {
|
||||
|
||||
/**
|
||||
* Handles the BSkyBlock locale
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
public class LocaleManager extends AbstractLocaleManager {
|
||||
public static final String LOCALE_FOLDER = "localization";
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private Map<String, LocaleHandler> handlers = new HashMap<>();
|
||||
|
||||
public LocaleManager(BSkyBlock plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@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 void registerLocaleHandler(LocaleHandler handler) {
|
||||
handlers.put(handler.getIdentifier(), handler);
|
||||
handler.setupLocales();
|
||||
handler.loadLocales();
|
||||
}
|
||||
|
||||
return getLocales().get(locale);
|
||||
public String get(CommandSender sender, String reference) {
|
||||
return reference;
|
||||
}
|
||||
|
||||
public String get(UUID uuid, String reference) {
|
||||
return reference;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ 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,9 +625,9 @@ public class IslandsManager {
|
||||
player.teleport(home);
|
||||
//player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
|
||||
if (number == 1) {
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleport").replace("[label]", Settings.ISLANDCOMMAND));
|
||||
Util.sendMessage(player, "island.teleport", new Variable("[label]", Settings.ISLANDCOMMAND));
|
||||
} else {
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player.getUniqueId()).get("island.teleported").replace("[number]", String.valueOf(number)));
|
||||
Util.sendMessage(player, "island.teleported", new Variable("[number]", String.valueOf(number)));
|
||||
}
|
||||
// Exit spectator mode if in it
|
||||
if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
@ -853,7 +854,6 @@ 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,7 +929,6 @@ 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) {
|
||||
|
@ -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, plugin.getLocale(player.getUniqueId()).get("locked.islandlocked"));
|
||||
Util.sendMessage(player, "island.locked");
|
||||
plugin.getIslands().homeTeleport(player);
|
||||
}
|
||||
}
|
||||
|
@ -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(), plugin.getLocale(event.getPlayer().getUniqueId()).get("island.protected"));
|
||||
Util.sendMessage(event.getPlayer(), "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(), plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe"));
|
||||
Util.sendMessage(event.getPlayer(), "warps.error.not-safe");
|
||||
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(), plugin.getLocale(event.getPlayer().getUniqueId()).get("warps.error.NotSafe"));
|
||||
Util.sendMessage(event.getPlayer(), "warps.error.not-safe");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class IslandGuard implements Listener {
|
||||
return;
|
||||
}
|
||||
// Elsewhere - not allowed
|
||||
Util.sendMessage(event.getWhoClicked(), plugin.getLocale(event.getWhoClicked().getUniqueId()).get("island.protected"));
|
||||
Util.sendMessage(event.getWhoClicked(), "island.protected");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,18 @@ 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(BSkyBlock.getPlugin().getLocale(player).get("panel.languages"));
|
||||
.setName(Util.getMessage(player, "panel.languages.title"));
|
||||
|
||||
PanelItem test = new PanelItemBuilder()
|
||||
.setIcon(new ItemStack(Material.BEDROCK))
|
||||
.setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.test.name"))
|
||||
.setDescription(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.test.description"))
|
||||
.setName(Util.getMessage(player, "panel.languages.test.name"))
|
||||
.setDescription(Util.getMessage(player, "panel.languages.test.description"))
|
||||
.setGlow(true)
|
||||
.setClickHandler(new PanelItem.ClickHandler() {
|
||||
@Override
|
||||
@ -32,8 +33,8 @@ public class LanguagePanel {
|
||||
|
||||
PanelItem something = new PanelItemBuilder()
|
||||
.setIcon(new ItemStack(Material.ANVIL))
|
||||
.setName(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.something.name"))
|
||||
.setDescription(BSkyBlock.getPlugin().getLocale(player).get("panel.languages.something.description"))
|
||||
.setName(Util.getMessage(player, "panel.languages.something.name"))
|
||||
.setDescription(Util.getMessage(player, "panel.languages.something.description"))
|
||||
.build();
|
||||
|
||||
panelBuilder.addItem(1, test);
|
||||
|
@ -52,6 +52,7 @@ 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;
|
||||
@ -972,16 +973,16 @@ public class Schematic {
|
||||
Sign sign = (Sign) signState;
|
||||
if (sign.getLine(0).isEmpty()) {
|
||||
// TODO Add sign
|
||||
sign.setLine(0, plugin.getLocale(player.getUniqueId()).get("sign.line1").replace("[player]", player.getName()));
|
||||
sign.setLine(0, Util.getMessage(player, "sign.line1", new Variable("[player]", player.getName())));
|
||||
}
|
||||
if (sign.getLine(1).isEmpty()) {
|
||||
sign.setLine(1, plugin.getLocale(player.getUniqueId()).get("sign.line2").replace("[player]", player.getName()));
|
||||
sign.setLine(1, Util.getMessage(player, "sign.line2", new Variable("[player]", player.getName())));
|
||||
}
|
||||
if (sign.getLine(2).isEmpty()) {
|
||||
sign.setLine(2, plugin.getLocale(player.getUniqueId()).get("sign.line3").replace("[player]", player.getName()));
|
||||
sign.setLine(2, Util.getMessage(player, "sign.line3", new Variable("[player]", player.getName())));
|
||||
}
|
||||
if (sign.getLine(3).isEmpty()) {
|
||||
sign.setLine(3, plugin.getLocale(player.getUniqueId()).get("sign.line4").replace("[player]", player.getName()));
|
||||
sign.setLine(3, Util.getMessage(player, "sign.line4", new Variable("[player]", player.getName())));
|
||||
}
|
||||
// BlockFace direction = ((org.bukkit.material.Sign)
|
||||
// sign.getData()).getFacing();
|
||||
|
@ -29,6 +29,7 @@ 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;
|
||||
@ -43,8 +44,23 @@ import us.tastybento.bskyblock.util.placeholders.PlaceholderHandler;
|
||||
public class Util {
|
||||
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);
|
||||
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")){
|
||||
|
@ -12,7 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package us.tastybento.bskyblock.config;
|
||||
package us.tastybento.bskyblock.util;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.enumeration;
|
Loading…
Reference in New Issue
Block a user