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