Fix TellrawJson
This commit is contained in:
parent
156c56d71d
commit
ec3dc24a5e
@ -69,4 +69,11 @@ public abstract class InternalPluginBridge {
|
||||
abstract public Map<String, Object> taboolibTLocaleSerialize(Object in);
|
||||
|
||||
abstract public FileConfiguration taboolibGetPlayerData(OfflinePlayer player);
|
||||
|
||||
abstract public int protocolSupportPlayerVersion(Player player);
|
||||
|
||||
abstract public int viaVersionPlayerVersion(Player player);
|
||||
|
||||
abstract public Class getClass(String name) throws ClassNotFoundException;
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import protocolsupport.api.ProtocolSupportAPI;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
@ -205,4 +207,19 @@ public class BridgeImpl extends InternalPluginBridge {
|
||||
public FileConfiguration taboolibGetPlayerData(OfflinePlayer player) {
|
||||
return PlayerDataManager.getPlayerData(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int protocolSupportPlayerVersion(Player player) {
|
||||
return ProtocolSupportAPI.getProtocolVersion(player).getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int viaVersionPlayerVersion(Player player) {
|
||||
return Via.getAPI().getPlayerVersion(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(name);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package io.izzel.taboolib.module.lite;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
@ -107,7 +108,7 @@ public class SimpleReflection {
|
||||
try {
|
||||
if (ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
|
||||
for (Type actualTypeArgument : ((ParameterizedType) genericType).getActualTypeArguments()) {
|
||||
return Class.forName(actualTypeArgument.getTypeName());
|
||||
return TabooLibAPI.getPluginBridge().getClass(actualTypeArgument.getTypeName());
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
@ -122,7 +123,7 @@ public class SimpleReflection {
|
||||
Type genericType = field.getGenericType();
|
||||
if (ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
|
||||
for (Type actualTypeArgument : ((ParameterizedType) genericType).getActualTypeArguments()) {
|
||||
mapType[mapType[0] == null ? 0 : 1] = Class.forName(actualTypeArgument.getTypeName());
|
||||
mapType[mapType[0] == null ? 0 : 1] = TabooLibAPI.getPluginBridge().getClass(actualTypeArgument.getTypeName());
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
|
@ -71,6 +71,7 @@ public class SimpleVersionControl {
|
||||
this.from.add(from.startsWith("v") ? from : "v" + from);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置原版本,写法如:v1_8_R3, v1_12_R1
|
||||
*/
|
||||
@ -80,7 +81,7 @@ public class SimpleVersionControl {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置目标版本
|
||||
* 设置目标版本
|
||||
*/
|
||||
public SimpleVersionControl to(String to) {
|
||||
this.to = to.startsWith("v") ? to : "v" + to;
|
||||
@ -116,15 +117,16 @@ public class SimpleVersionControl {
|
||||
}
|
||||
|
||||
public Class<?> translate(Plugin plugin) throws IOException {
|
||||
InputStream inputStream;
|
||||
if (useCache && cacheClasses.containsKey(target)) {
|
||||
inputStream = new ByteArrayInputStream(cacheClasses.get(target));
|
||||
} else {
|
||||
inputStream = Files.getResource(plugin, target.replace(".", "/") + ".class");
|
||||
if (useCache) {
|
||||
cacheClasses.put(target, IO.readFully(inputStream));
|
||||
// 防止出现 Class not found 的奇葩问题,使用缓存(目的是兼容热重载)
|
||||
InputStream inputStream = useCache ? new ByteArrayInputStream(cacheClasses.computeIfAbsent(target, n -> {
|
||||
try {
|
||||
return IO.readFully(Files.getResource(plugin, target.replace(".", "/") + ".class"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return new byte[0];
|
||||
})) : Files.getResource(plugin, target.replace(".", "/") + ".class");
|
||||
// 读取
|
||||
ClassReader classReader = new ClassReader(inputStream);
|
||||
ClassWriter classWriter = new ClassWriter(0);
|
||||
ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
|
||||
@ -132,7 +134,7 @@ public class SimpleVersionControl {
|
||||
classWriter.visitEnd();
|
||||
classVisitor.visitEnd();
|
||||
// 因第三方插件调用该方法时会出现找不到类,所以第三方插件使用 BridgeLoader 加载类
|
||||
return plugin instanceof InternalPlugin ? AsmClassLoader.createNewClass(target, classWriter.toByteArray()) : BridgeLoader.createNewClass(target, classWriter.toByteArray());
|
||||
return plugin instanceof InternalPlugin ? AsmClassLoader.createNewClass(target, classWriter.toByteArray()) : BridgeLoader.createNewClass(target, classWriter.toByteArray());
|
||||
}
|
||||
|
||||
public Class<?> translateBridge() throws IOException {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.izzel.taboolib.module.tellraw;
|
||||
|
||||
import io.izzel.taboolib.module.inject.TFunction;
|
||||
import io.izzel.taboolib.module.inject.TSchedule;
|
||||
import io.izzel.taboolib.module.lite.SimpleVersionControl;
|
||||
import io.izzel.taboolib.module.tellraw.internal.AbstractTellraw;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -17,8 +18,6 @@ public class TellrawCreator {
|
||||
private static boolean protocolSupportLoaded;
|
||||
|
||||
public static void init() {
|
||||
viaVersionLoaded = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
|
||||
protocolSupportLoaded = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null;
|
||||
try {
|
||||
abstractTellraw = (AbstractTellraw) SimpleVersionControl.createNMS("io.izzel.taboolib.module.tellraw.internal.InternalTellraw").translate().newInstance();
|
||||
} catch (Exception e) {
|
||||
@ -26,6 +25,12 @@ public class TellrawCreator {
|
||||
}
|
||||
}
|
||||
|
||||
@TSchedule
|
||||
static void tick() {
|
||||
viaVersionLoaded = Bukkit.getPluginManager().getPlugin("ViaVersion") != null;
|
||||
protocolSupportLoaded = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null;
|
||||
}
|
||||
|
||||
// *********************************
|
||||
//
|
||||
// Getter and Setter
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.izzel.taboolib.module.tellraw;
|
||||
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.module.locale.TLocale;
|
||||
import io.izzel.taboolib.util.ArrayUtil;
|
||||
import io.izzel.taboolib.util.Strings;
|
||||
@ -8,8 +9,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import protocolsupport.api.ProtocolSupportAPI;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -88,11 +87,11 @@ public class TellrawJson {
|
||||
public String toRawMessage(Player player) {
|
||||
// ViaVersion support!
|
||||
if (TellrawCreator.isViaVersionLoaded()) {
|
||||
return toRawMessage(Via.getAPI().getPlayerVersion(player) > 316 ? TellrawVersion.HIGH_VERSION : TellrawVersion.LOW_VERSION);
|
||||
return toRawMessage(TabooLibAPI.getPluginBridge().viaVersionPlayerVersion(player) > 316 ? TellrawVersion.HIGH_VERSION : TellrawVersion.LOW_VERSION);
|
||||
}
|
||||
// ProtocolSupport support!
|
||||
else if (TellrawCreator.isProtocolSupportLoaded()) {
|
||||
return toRawMessage(ProtocolSupportAPI.getProtocolVersion(player).getId() > 316 ? TellrawVersion.HIGH_VERSION : TellrawVersion.LOW_VERSION);
|
||||
return toRawMessage(TabooLibAPI.getPluginBridge().protocolSupportPlayerVersion(player) > 316 ? TellrawVersion.HIGH_VERSION : TellrawVersion.LOW_VERSION);
|
||||
}
|
||||
return toRawMessage();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user