Merge remote-tracking branch 'origin/napojeni-database' #14
Merged
jakub
merged 1 commits from lang-manager into master 1 year ago
6 changed files with 183 additions and 21 deletions
@ -1,4 +1,4 @@ |
||||
package commands; |
||||
package xyz.soukup.mineconomiaCoreV2.commands; |
||||
|
||||
import org.bukkit.Bukkit; |
||||
import org.bukkit.World; |
||||
@ -1,16 +1,145 @@ |
||||
package xyz.soukup.mineconomiaCoreV2.tools; |
||||
|
||||
import net.matrixcreations.libraries.MatrixColorAPI; |
||||
import org.bukkit.ChatColor; |
||||
import org.bukkit.command.CommandSender; |
||||
import org.bukkit.configuration.InvalidConfigurationException; |
||||
import org.bukkit.configuration.file.FileConfiguration; |
||||
import org.bukkit.configuration.file.YamlConfiguration; |
||||
import org.bukkit.entity.Player; |
||||
|
||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.config; |
||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.plugin; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
import static xyz.soukup.mineconomiaCoreV2.core.sharedValues.*; |
||||
|
||||
public class LangManager { |
||||
|
||||
public static YamlConfiguration lang = null; |
||||
public static void loadLang(){ |
||||
String langPath = "lang/" + config.getString("lang"); |
||||
plugin.saveResource(langPath, false); |
||||
//lang = YamlConfiguration.loadConfiguration(plugin.getResource(langPath));
|
||||
private static FileConfiguration langConfig; |
||||
|
||||
|
||||
//Replace references and colorize retrieved string
|
||||
public static String get(String key){ |
||||
return MatrixColorAPI.process(retrieveString(key)); |
||||
} |
||||
|
||||
public static String get(String key, String s1){ |
||||
return MatrixColorAPI.process(retrieveString(key).replace("%s1", s1)); |
||||
} |
||||
|
||||
public static String get(String key, String s1, String s2) { |
||||
return MatrixColorAPI.process(retrieveString(key).replace("%s1", s1).replace("%s2", s2)); |
||||
} |
||||
|
||||
public static String get(String key, String s1, String s2, String s3) { |
||||
return MatrixColorAPI.process(retrieveString(key).replace("%s1", s1).replace("%s2", s2).replace("%s3", s3)); |
||||
} |
||||
|
||||
|
||||
//Info into server console
|
||||
public static void info(String key){ |
||||
logger.info(ChatColor.stripColor(get(key))); |
||||
} |
||||
|
||||
public static void info(String key, String s1){ |
||||
logger.info(ChatColor.stripColor(get(key, s1))); |
||||
} |
||||
public static void info(String key, String s1, String s2){ |
||||
logger.info(ChatColor.stripColor(get(key, s1, s2))); |
||||
} |
||||
public static void info(String key, String s1, String s2, String s3){ |
||||
logger.info(ChatColor.stripColor(get(key, s1, s2, s3))); |
||||
} |
||||
|
||||
//Warning into server console
|
||||
public static void warning(String key){ |
||||
logger.warning(ChatColor.stripColor(get(key))); |
||||
} |
||||
|
||||
public static void warning(String key, String s1){ |
||||
logger.warning(ChatColor.stripColor(get(key, s1))); |
||||
} |
||||
public static void warning(String key, String s1, String s2){ |
||||
logger.warning(ChatColor.stripColor(get(key, s1, s2))); |
||||
} |
||||
public static void warning(String key, String s1, String s2, String s3){ |
||||
logger.warning(ChatColor.stripColor(get(key, s1, s2, s3))); |
||||
} |
||||
|
||||
//Message to player
|
||||
public static void message(CommandSender commandSender, String key){ |
||||
commandSender.sendMessage(get(key)); |
||||
} |
||||
|
||||
public static void message(CommandSender commandSender, String key, String s1){ |
||||
commandSender.sendMessage(get(key, s1)); |
||||
} |
||||
|
||||
public static void message(CommandSender commandSender, String key, String s1, String s2) { |
||||
commandSender.sendMessage(get(key, s1, s2)); |
||||
} |
||||
|
||||
public static void message(CommandSender commandSender, String key, String s1, String s2, String s3) { |
||||
commandSender.sendMessage(get(key, s1, s2, s3)); |
||||
} |
||||
|
||||
|
||||
private static String retrieveString(String key) { |
||||
|
||||
Object value = langConfig.get(key); |
||||
|
||||
if (value == null){ |
||||
return key; |
||||
} |
||||
|
||||
if(value instanceof String){ |
||||
return (String) value; |
||||
} |
||||
|
||||
if (value instanceof List){ |
||||
List<String> stringList = (List<String>) value; |
||||
|
||||
StringBuilder result = new StringBuilder(); |
||||
boolean isFirst = true; |
||||
|
||||
for (String s : stringList){ |
||||
|
||||
if(!isFirst){ |
||||
result.append("\n"); |
||||
} |
||||
|
||||
result.append(s); |
||||
isFirst = false; |
||||
} |
||||
|
||||
return result.toString(); |
||||
} |
||||
|
||||
return key; |
||||
} |
||||
|
||||
public static void initLangManager() throws IOException, InvalidConfigurationException { |
||||
|
||||
if (langConfig != null){ |
||||
return; |
||||
} |
||||
|
||||
String selectedLang = config.getString("language"); |
||||
|
||||
File langFile = new File(plugin.getDataFolder(), "lang/" + selectedLang); |
||||
|
||||
if (!langFile.exists()) { |
||||
langFile.getParentFile().mkdirs(); |
||||
plugin.saveResource("lang/" + selectedLang, false); |
||||
} |
||||
|
||||
langConfig = new YamlConfiguration(); |
||||
|
||||
langConfig.load(langFile); |
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
Loading…
Reference in new issue