diff --git a/TabooLib.iml b/TabooLib.iml
index 88212e0..e1d93e7 100644
--- a/TabooLib.iml
+++ b/TabooLib.iml
@@ -26,7 +26,6 @@
-
diff --git a/pom.xml b/pom.xml
index 8be3a23..287e3fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.skymc
TabooLib
- 4.0
+ 4.01
UTF-8
diff --git a/src/main/java/com/ilummc/tlib/resources/TLocale.java b/src/main/java/com/ilummc/tlib/resources/TLocale.java
index 982671e..b2dc858 100644
--- a/src/main/java/com/ilummc/tlib/resources/TLocale.java
+++ b/src/main/java/com/ilummc/tlib/resources/TLocale.java
@@ -1,17 +1,20 @@
package com.ilummc.tlib.resources;
import com.ilummc.tlib.TLib;
+import com.ilummc.tlib.bungee.api.ChatColor;
import com.ilummc.tlib.inject.TLoggerManager;
import com.ilummc.tlib.util.Ref;
import com.ilummc.tlib.util.Strings;
+import me.clip.placeholderapi.PlaceholderAPI;
import me.skymc.taboolib.Main;
+import me.skymc.taboolib.TabooLib;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
-import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.entity.Player;
-import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
+import java.util.stream.Collectors;
public class TLocale {
@@ -20,15 +23,15 @@ public class TLocale {
}
static String asString(String path, Class> callerClass, String... args) {
- return TLocaleLoader.asString(getCallerPlugin(callerClass), path, args);
+ return TLocaleLoader.asString(Ref.getCallerPlugin(callerClass), path, args);
}
static List asStringList(String path, Class> callerClass, String... args) {
- return TLocaleLoader.asStringList(getCallerPlugin(callerClass), path, args);
+ return TLocaleLoader.asStringList(Ref.getCallerPlugin(callerClass), path, args);
}
private static void sendTo(String path, CommandSender sender, String[] args, Class> callerClass) {
- TLocaleLoader.sendTo(getCallerPlugin(callerClass), path, sender, args);
+ TLocaleLoader.sendTo(Ref.getCallerPlugin(callerClass), path, sender, args);
}
public static void sendToConsole(String path, String... args) {
@@ -45,7 +48,7 @@ public class TLocale {
public static String asString(String path, String... args) {
try {
- return asString(path, Ref.getCallerClassNotOptional(3), args);
+ return asString(path, Ref.getCallerClass(3).orElse(Main.class), args);
} catch (Exception e) {
TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("FETCH-LOCALE-ERROR"), path));
TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.getMessage()));
@@ -55,7 +58,7 @@ public class TLocale {
public static List asStringList(String path, String... args) {
try {
- return asStringList(path, Ref.getCallerClassNotOptional(3), args);
+ return asStringList(path, Ref.getCallerClass(3).orElse(Main.class), args);
} catch (Exception e) {
TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("FETCH-LOCALE-ERROR"), path));
TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.getMessage()));
@@ -64,48 +67,64 @@ public class TLocale {
}
public static void reload() {
- Ref.getCallerClass(3).ifPresent(clazz -> TLocaleLoader.load(getCallerPlugin(clazz), false));
+ Ref.getCallerClass(3).ifPresent(clazz -> TLocaleLoader.load(Ref.getCallerPlugin(clazz), false));
}
- private static JavaPlugin getCallerPlugin(Class> callerClass) {
- try {
- Field pluginField = callerClass.getClassLoader().getClass().getDeclaredField("plugin");
- pluginField.setAccessible(true);
- return (JavaPlugin) pluginField.get(callerClass.getClassLoader());
- } catch (Exception ignored) {
- TLib.getTLib().getLogger().error("无效的语言文件发送形式: &4" + callerClass.getName());
+ public static final class Translate extends TLocale {
+
+ public static boolean isPlaceholderUseDefault() {
+ return Main.getInst().getConfig().getBoolean("LOCALE.USE_PAPI", false);
+ }
+
+ public static boolean isPlaceholderPluginEnabled() {
+ return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null && Bukkit.getPluginManager().getPlugin("PlaceholderAPI").isEnabled();
+ }
+
+ public static String setColored(String args) {
+ return ChatColor.translateAlternateColorCodes('&', args);
+ }
+
+ public static List setColored(List args) {
+ return args.stream().map(var -> ChatColor.translateAlternateColorCodes('&', var)).collect(Collectors.toList());
+ }
+
+ public static String setPlaceholders(CommandSender sender, String args) {
+ return isPlaceholderPluginEnabled() ? sender instanceof Player ? PlaceholderAPI.setPlaceholders((Player) sender, args) : args : args;
+ }
+
+ public static List setPlaceholders(CommandSender sender, List args) {
+ return isPlaceholderPluginEnabled() ? sender instanceof Player ? PlaceholderAPI.setPlaceholders((Player) sender, args) : args : args;
}
- return (JavaPlugin) Main.getInst();
}
public static final class Logger extends TLocale {
public static void info(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).info(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).info(locale)));
}
public static void warn(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).warn(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).warn(locale)));
}
public static void error(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).error(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).error(locale)));
}
public static void fatal(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).fatal(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).fatal(locale)));
}
public static void fine(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).fine(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).fine(locale)));
}
public static void finest(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).finest(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).finest(locale)));
}
public static void verbose(String path, String... args) {
- Ref.getCallerClass(3).ifPresent(clazz -> TLoggerManager.getLogger(TLocale.getCallerPlugin(clazz)).verbose(asString(path, clazz, args)));
+ Ref.getCallerClass(3).ifPresent(clazz -> asStringList(path, clazz, args).forEach(locale -> TLoggerManager.getLogger(Ref.getCallerPlugin(clazz)).verbose(locale)));
}
}
diff --git a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java
index 5664243..e77ec67 100644
--- a/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java
+++ b/src/main/java/com/ilummc/tlib/resources/TLocaleInstance.java
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList;
import com.ilummc.tlib.TLib;
import com.ilummc.tlib.resources.type.TLocaleText;
import com.ilummc.tlib.util.Strings;
+import me.skymc.taboolib.TabooLib;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
@@ -11,19 +12,17 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import javax.annotation.concurrent.ThreadSafe;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@ThreadSafe
@SuppressWarnings("rawtypes")
class TLocaleInstance {
- private final Map> map = new HashMap<>();
+ private final Map> map = new HashMap<>();
private final Plugin plugin;
+ private final AtomicInteger latestUpdateNodes = new AtomicInteger();
TLocaleInstance(Plugin plugin) {
this.plugin = plugin;
@@ -38,7 +37,7 @@ class TLocaleInstance {
return map.size();
}
- public Map> getMap() {
+ public Map> getMap() {
return map;
}
@@ -46,58 +45,71 @@ class TLocaleInstance {
return plugin;
}
+ public AtomicInteger getLatestUpdateNodes() {
+ return latestUpdateNodes;
+ }
+
public void sendTo(String path, CommandSender sender, String... args) {
try {
- map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).forEach(sendable -> {
+ map.getOrDefault(path, ImmutableList.of(TLocaleSerialize.getEmpty(path))).forEach(tSender -> {
if (Bukkit.isPrimaryThread()) {
- sendable.sendTo(sender, args);
+ tSender.sendTo(sender, args);
} else {
- Bukkit.getScheduler().runTask(plugin, () -> sendable.sendTo(sender, args));
+ Bukkit.getScheduler().runTask(plugin, () -> tSender.sendTo(sender, args));
}
});
} catch (Exception | Error e) {
TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("SEND-LOCALE-ERROR"), path));
TLib.getTLib().getLogger().error(Strings.replaceWithOrder(TLib.getInternalLanguage().getString("LOCALE-ERROR-REASON"), e.toString()));
- e.printStackTrace();
}
}
public String asString(String path, String... args) {
- return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asString(args);
+ return map.getOrDefault(path, ImmutableList.of(TLocaleSerialize.getEmpty(path))).get(0).asString(args);
}
public List asStringList(String path, String... args) {
- return map.getOrDefault(path, ImmutableList.of(TLocaleSendable.getEmpty(path))).get(0).asStringList(args);
+ return map.getOrDefault(path, ImmutableList.of(TLocaleSerialize.getEmpty(path))).get(0).asStringList(args);
}
- private static final Function