Merge branch 'master' of https://github.com/Bkm016/TabooLib
This commit is contained in:
@@ -87,8 +87,8 @@ public class SimpleI18n {
|
||||
}
|
||||
|
||||
private static File getLocaleFile(Plugin plugin) {
|
||||
TLocaleLoader.getLocalePriority().forEach(localeName -> Files.releaseResource(plugin, "simpleI18n/" + getVersion() + "/" + localeName + ".yml", false));
|
||||
return TLocaleLoader.getLocalePriority().stream().map(localeName -> new File("plugins/TabooLib/simpleI18n/" + getVersion() + "/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
|
||||
TLocaleLoader.getLocalePriority(plugin).forEach(localeName -> Files.releaseResource(plugin, "simpleI18n/" + getVersion() + "/" + localeName + ".yml", false));
|
||||
return TLocaleLoader.getLocalePriority(plugin).stream().map(localeName -> new File("plugins/TabooLib/simpleI18n/" + getVersion() + "/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private static String getVersion() {
|
||||
|
||||
@@ -118,7 +118,7 @@ public class TLocale {
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
Ref.getCallerClass(3).ifPresent(clazz -> TLocaleLoader.load(Ref.getCallerPlugin(clazz), false));
|
||||
Ref.getCallerClass(3).ifPresent(clazz -> TLocaleLoader.load(Ref.getCallerPlugin(clazz), true));
|
||||
}
|
||||
|
||||
public static final class Tellraw extends TLocale {
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -22,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class TLocaleLoader {
|
||||
|
||||
private static final Map<String, List<String>> localePriority = new HashMap<>();
|
||||
private static final Map<String, TLocaleInstance> map = new ConcurrentHashMap<>();
|
||||
|
||||
static {
|
||||
@@ -76,6 +78,12 @@ public class TLocaleLoader {
|
||||
public static void load(Plugin plugin, boolean isCover) {
|
||||
try {
|
||||
if (isLoadLocale(plugin, isCover)) {
|
||||
// 启用插件指定的独立语言加载顺序
|
||||
File settings = new File("plugins/" + plugin.getName() + "/settings.yml");
|
||||
List<String> priority = settings.exists() ? YamlConfiguration.loadConfiguration(settings).getStringList("LOCALE-PRIORITY") : plugin.getResource("settings.yml") != null ? YamlConfiguration.loadConfiguration(new BufferedReader(new InputStreamReader(plugin.getResource("settings.yml")))).getStringList("LOCALE-PRIORITY") : new ArrayList<>();
|
||||
if (!priority.isEmpty()) {
|
||||
setLocalePriority(plugin, priority);
|
||||
}
|
||||
// 获取文件
|
||||
File localeFile = getLocaleFile(plugin);
|
||||
if (localeFile == null) {
|
||||
@@ -107,8 +115,12 @@ public class TLocaleLoader {
|
||||
return plugin.getClass().getSuperclass().getSimpleName().equals("TabooPlugin");
|
||||
}
|
||||
|
||||
public static List<String> getLocalePriority() {
|
||||
return TabooLib.getConfig().contains("LOCALE.PRIORITY") ? TabooLib.getConfig().getStringList("LOCALE.PRIORITY") : Collections.singletonList("zh_CN");
|
||||
public static List<String> getLocalePriority(Plugin plugin) {
|
||||
return localePriority.getOrDefault(plugin.getName(), TabooLib.getConfig().contains("LOCALE.PRIORITY") ? TabooLib.getConfig().getStringList("LOCALE.PRIORITY") : Collections.singletonList("zh_CN"));
|
||||
}
|
||||
|
||||
public static List<String> setLocalePriority(Plugin plugin, List<String> priority) {
|
||||
return localePriority.put(plugin.getName(), priority);
|
||||
}
|
||||
|
||||
private static boolean isLoadLocale(Plugin plugin, boolean isCover) {
|
||||
@@ -124,8 +136,8 @@ public class TLocaleLoader {
|
||||
}
|
||||
|
||||
private static File getLocaleFile(Plugin plugin) {
|
||||
getLocalePriority().forEach(localeName -> Files.releaseResource(plugin, "lang/" + localeName + ".yml", false));
|
||||
return getLocalePriority().stream().map(localeName -> new File("plugins/" + plugin.getName() + "/lang/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
|
||||
getLocalePriority(plugin).forEach(localeName -> Files.releaseResource(plugin, "lang/" + localeName + ".yml", false));
|
||||
return getLocalePriority(plugin).stream().map(localeName -> new File("plugins/" + plugin.getName() + "/lang/" + localeName + ".yml")).filter(File::exists).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
private static TLocaleInstance getLocaleInstance(Plugin plugin) {
|
||||
|
||||
@@ -270,23 +270,51 @@ public class NMSImpl extends NMS {
|
||||
private Object toNBTBase(io.izzel.taboolib.module.nms.nbt.NBTBase base) {
|
||||
switch (base.getType().getId()) {
|
||||
case 1:
|
||||
return new NBTTagByte(base.asByte());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagByte.a(base.asByte());
|
||||
} else {
|
||||
return new NBTTagByte(base.asByte());
|
||||
}
|
||||
case 2:
|
||||
return new NBTTagShort(base.asShort());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagShort.a(base.asShort());
|
||||
} else {
|
||||
return new NBTTagShort(base.asShort());
|
||||
}
|
||||
case 3:
|
||||
return new NBTTagInt(base.asInt());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagInt.a(base.asInt());
|
||||
} else {
|
||||
return new NBTTagInt(base.asInt());
|
||||
}
|
||||
case 4:
|
||||
return new NBTTagLong(base.asLong());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagLong.a(base.asLong());
|
||||
} else {
|
||||
return new NBTTagLong(base.asLong());
|
||||
}
|
||||
case 5:
|
||||
return new NBTTagFloat(base.asFloat());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagFloat.a(base.asFloat());
|
||||
} else {
|
||||
return new NBTTagFloat(base.asFloat());
|
||||
}
|
||||
case 6:
|
||||
return new NBTTagDouble(base.asDouble());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagDouble.a(base.asDouble());
|
||||
} else {
|
||||
return new NBTTagDouble(base.asDouble());
|
||||
}
|
||||
case 7:
|
||||
return new NBTTagByteArray(base.asByteArray());
|
||||
case 11:
|
||||
return new NBTTagIntArray(base.asIntArray());
|
||||
case 8:
|
||||
return new NBTTagString(base.asString());
|
||||
if (Version.isAfter(Version.v1_15)) {
|
||||
return net.minecraft.server.v1_15_R1.NBTTagString.a(base.asString());
|
||||
} else {
|
||||
return new NBTTagString(base.asString());
|
||||
}
|
||||
case 9:
|
||||
Object nmsList = new NBTTagList();
|
||||
for (io.izzel.taboolib.module.nms.nbt.NBTBase value : base.asList()) {
|
||||
|
||||
Reference in New Issue
Block a user