Update JDK 11
This commit is contained in:
parent
7563559fda
commit
498854260d
@ -7,6 +7,7 @@ import io.izzel.taboolib.TabooLibAPI;
|
||||
import io.izzel.taboolib.TabooLibLoader;
|
||||
import io.izzel.taboolib.client.packet.impl.PacketEmpty;
|
||||
import io.izzel.taboolib.module.inject.TListener;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -68,7 +69,7 @@ public class PacketSerializer implements Listener {
|
||||
Arrays.stream(packet.getClass().getDeclaredFields()).filter(field -> field.isAnnotationPresent(PacketValue.class)).forEach(field -> {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object obj = field.get(packet);
|
||||
Object obj = Ref.getField(packet, field);
|
||||
if (obj instanceof Number) {
|
||||
json.addProperty(field.getName(), (Number) obj);
|
||||
} else if (obj instanceof Boolean) {
|
||||
|
@ -30,7 +30,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
try {
|
||||
SimpleReflection.saveField(PathfinderGoalSelector.class);
|
||||
SimpleReflection.saveField(ControllerJump.class);
|
||||
pathfinderGoalSelectorSet =SimpleReflection.getField(PathfinderGoalSelector.class, "b");
|
||||
pathfinderGoalSelectorSet = SimpleReflection.getField(PathfinderGoalSelector.class, "b");
|
||||
controllerJumpCurrent = SimpleReflection.getField(ControllerJump.class, "a");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -86,7 +86,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public Object getPathEntity(LivingEntity entity) {
|
||||
try {
|
||||
return pathEntity.get(getNavigation(entity));
|
||||
return Ref.getField(getNavigation(entity), pathEntity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -115,7 +115,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public void clearGoalAi(LivingEntity entity) {
|
||||
try {
|
||||
((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector)).clear();
|
||||
((Collection) Ref.getField(((EntityInsentient) getEntityInsentient(entity)).goalSelector, pathfinderGoalSelectorSet)).clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -124,7 +124,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public void clearTargetAi(LivingEntity entity) {
|
||||
try {
|
||||
((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector)).clear();
|
||||
((Collection) Ref.getField(((EntityInsentient) getEntityInsentient(entity)).targetSelector, pathfinderGoalSelectorSet)).clear();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -133,7 +133,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public Iterable getGoalAi(LivingEntity entity) {
|
||||
try {
|
||||
return ((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).goalSelector));
|
||||
return ((Collection) Ref.getField(((EntityInsentient) getEntityInsentient(entity)).goalSelector, pathfinderGoalSelectorSet));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@ -143,7 +143,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public Iterable getTargetAi(LivingEntity entity) {
|
||||
try {
|
||||
return ((Collection) pathfinderGoalSelectorSet.get(((EntityInsentient) getEntityInsentient(entity)).targetSelector));
|
||||
return ((Collection) Ref.getField(((EntityInsentient) getEntityInsentient(entity)).targetSelector, pathfinderGoalSelectorSet));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@ -153,8 +153,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
@Override
|
||||
public void setGoalAi(LivingEntity entity, Iterable ai) {
|
||||
try {
|
||||
Ref.putField(((EntityInsentient) getEntityInsentient(entity)).goalSelector,
|
||||
this.pathfinderGoalSelectorSet, ai);
|
||||
Ref.putField(((EntityInsentient) getEntityInsentient(entity)).goalSelector, this.pathfinderGoalSelectorSet, ai);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
@ -164,7 +163,7 @@ public class InternalPathfinderExecutor extends PathfinderExecutor {
|
||||
public void setTargetAi(LivingEntity entity, Iterable ai) {
|
||||
try {
|
||||
Ref.putField(((EntityInsentient) getEntityInsentient(entity)).targetSelector,
|
||||
this.pathfinderGoalSelectorSet, ai);
|
||||
this.pathfinderGoalSelectorSet, ai);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -83,8 +83,7 @@ public abstract class BaseMainCommand implements CommandExecutor, TabExecutor {
|
||||
fields.sort(Comparator.comparingDouble(commandField -> commandField.getField().getAnnotation(SubCommand.class).priority()));
|
||||
fields.forEach(commandField -> {
|
||||
try {
|
||||
commandField.getField().setAccessible(true);
|
||||
BaseSubCommand subCommand = (BaseSubCommand) commandField.getField().get(commandField.getParent().newInstance());
|
||||
BaseSubCommand subCommand = Ref.getField(commandField.getParent().newInstance(), commandField.getField(), BaseSubCommand.class);
|
||||
subCommand.label(commandField.getField().getName()).annotation(commandField.getField().getAnnotation(SubCommand.class));
|
||||
baseMainCommand.registerSubCommand(subCommand);
|
||||
} catch (Throwable ignored) {
|
||||
|
@ -2,6 +2,7 @@ package io.izzel.taboolib.module.inject;
|
||||
|
||||
import io.izzel.taboolib.TabooLibLoader;
|
||||
import io.izzel.taboolib.module.locale.logger.TLogger;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -34,7 +35,7 @@ public class PlayerContainerLoader implements Listener, TabooLibLoader.Loader {
|
||||
field.setAccessible(true);
|
||||
for (Object instance : TInjectHelper.getInstance(field, pluginClass, plugin)) {
|
||||
try {
|
||||
pluginContainer.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(new Container(field.get(instance), annotation.uniqueId()));
|
||||
pluginContainer.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(new Container(Ref.getField(instance, field), annotation.uniqueId()));
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
||||
// SimpleCommandBuilder Inject
|
||||
injectTypes.put(CommandBuilder.class, (plugin, field, args, pluginClass, instance) -> {
|
||||
try {
|
||||
CommandBuilder builder = (CommandBuilder) field.get(instance);
|
||||
CommandBuilder builder = Ref.getField(instance, field, CommandBuilder.class);
|
||||
if (!builder.isBuild()) {
|
||||
if (builder.isSimpleMode()) {
|
||||
builder.command(field.getName());
|
||||
@ -115,7 +115,7 @@ public class TInjectLoader implements TabooLibLoader.Loader {
|
||||
// CooldownPack Inject
|
||||
injectTypes.put(Cooldown.class, (plugin, field, args, pluginClass, instance) -> {
|
||||
try {
|
||||
Cooldowns.register((Cooldown) field.get(instance), plugin);
|
||||
Cooldowns.register((Cooldown) Ref.getField(instance, field), plugin);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import io.izzel.taboolib.Version;
|
||||
import io.izzel.taboolib.module.lite.SimpleReflection;
|
||||
import io.izzel.taboolib.module.nms.nbt.*;
|
||||
import io.izzel.taboolib.module.packet.TPacketHandler;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
import net.minecraft.server.v1_12_R1.ChatMessageType;
|
||||
import net.minecraft.server.v1_12_R1.EntityVillager;
|
||||
import net.minecraft.server.v1_12_R1.MinecraftServer;
|
||||
@ -130,7 +131,7 @@ public class NMSImpl extends NMS {
|
||||
return "entity.minecraft." + ((net.minecraft.server.v1_14_R1.MinecraftKey) minecraftKey).getKey();
|
||||
} else if (Version.isAfter(Version.v1_13)) {
|
||||
try {
|
||||
String name = "entity.minecraft." + IRegistry.ENTITY_TYPE.getKey((net.minecraft.server.v1_13_R2.EntityTypes<?>) entityTypesField.get(((org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) entity).getHandle())).getKey();
|
||||
String name = "entity.minecraft." + IRegistry.ENTITY_TYPE.getKey((net.minecraft.server.v1_13_R2.EntityTypes<?>) Ref.getField(((org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) entity).getHandle(), entityTypesField)).getKey();
|
||||
if (entity instanceof Villager && ((CraftVillager) entity).getCareer() != null) {
|
||||
name += "." + String.valueOf(((CraftVillager) entity).getCareer()).toLowerCase();
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.izzel.taboolib.util;
|
||||
|
||||
import com.google.common.primitives.Primitives;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.TabooLibAPI;
|
||||
@ -92,6 +91,11 @@ public class Ref {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getField(Object src, Field field, Class<T> cast) {
|
||||
Object obj = getField(src, field);
|
||||
return obj == null ? null : (T) obj;
|
||||
}
|
||||
|
||||
public static Object getField(Object src, Field field) {
|
||||
if (Modifier.isStatic(field.getModifiers())) {
|
||||
Object base = getUnsafe().staticFieldBase(field);
|
||||
@ -165,7 +169,7 @@ public class Ref {
|
||||
} catch (Exception | Error e) {
|
||||
try {
|
||||
List<Field> list = Arrays.stream(clazz.getDeclaredFields())
|
||||
.filter(field -> (field.getModifiers() & excludeModifiers) == 0).collect(Collectors.toList());
|
||||
.filter(field -> (field.getModifiers() & excludeModifiers) == 0).collect(Collectors.toList());
|
||||
cachedFields.putIfAbsent(clazz.getName(), list);
|
||||
return list;
|
||||
} catch (Error err) {
|
||||
@ -209,7 +213,7 @@ public class Ref {
|
||||
} catch (Exception | Error e) {
|
||||
try {
|
||||
List<Method> list = Arrays.stream(clazz.getDeclaredMethods())
|
||||
.filter(field -> (field.getModifiers() & excludeModifiers) == 0).collect(Collectors.toList());
|
||||
.filter(field -> (field.getModifiers() & excludeModifiers) == 0).collect(Collectors.toList());
|
||||
cacheMethods.putIfAbsent(clazz.getName(), list);
|
||||
return list;
|
||||
} catch (Error err) {
|
||||
@ -257,10 +261,8 @@ public class Ref {
|
||||
return cachePlugin.computeIfAbsent(callerClass.getName(), n -> {
|
||||
try {
|
||||
ClassLoader loader = callerClass.getClassLoader();
|
||||
Field pluginF = loader.getClass().getDeclaredField("plugin");
|
||||
pluginF.setAccessible(true);
|
||||
Object o = pluginF.get(loader);
|
||||
return (JavaPlugin) o;
|
||||
Object instance = getField(loader, loader.getClass().getDeclaredField("plugin"));
|
||||
return (JavaPlugin) instance;
|
||||
} catch (Exception e) {
|
||||
return TabooLib.getPlugin();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.izzel.taboolib.util.asm;
|
||||
|
||||
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
@ -36,7 +37,7 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
|
||||
Class<?> clazz = AsmClassLoader.createNewClass(newClassName, writer.toByteArray());
|
||||
Field field = from.getClassLoader().getClass().getDeclaredField("classes");
|
||||
field.setAccessible(true);
|
||||
((Map<String, Class<?>>) field.get(from.getClassLoader())).put(newClassName, clazz);
|
||||
Ref.getField(from.getClassLoader(), field, Map.class).put(newClassName, clazz);
|
||||
Constructor<?> constructor = clazz.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
|
@ -2,6 +2,7 @@ package io.izzel.taboolib.util.plugin;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import io.izzel.taboolib.TabooLib;
|
||||
import io.izzel.taboolib.util.Ref;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
@ -248,26 +249,26 @@ public class PluginUtils {
|
||||
try {
|
||||
Field pluginsField = Bukkit.getPluginManager().getClass().getDeclaredField("plugins");
|
||||
pluginsField.setAccessible(true);
|
||||
plugins = (List) pluginsField.get(pluginManager);
|
||||
plugins = (List) Ref.getField(pluginManager, pluginsField);
|
||||
Field lookupNamesField = Bukkit.getPluginManager().getClass().getDeclaredField("lookupNames");
|
||||
lookupNamesField.setAccessible(true);
|
||||
names = (Map) lookupNamesField.get(pluginManager);
|
||||
names = (Map) Ref.getField(pluginManager, lookupNamesField);
|
||||
|
||||
Field commandMapField;
|
||||
try {
|
||||
commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("listeners");
|
||||
commandMapField.setAccessible(true);
|
||||
listeners = (Map) commandMapField.get(pluginManager);
|
||||
listeners = (Map) Ref.getField(pluginManager, commandMapField);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
commandMapField = Bukkit.getPluginManager().getClass().getDeclaredField("commandMap");
|
||||
commandMapField.setAccessible(true);
|
||||
commandMap = (SimpleCommandMap) commandMapField.get(pluginManager);
|
||||
commandMap = (SimpleCommandMap) Ref.getField(pluginManager, commandMapField);
|
||||
Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
knownCommandsField.setAccessible(true);
|
||||
commands = (Map) knownCommandsField.get(commandMap);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
commands = (Map) Ref.getField(commandMap, knownCommandsField);
|
||||
} catch (NoSuchFieldException e) {
|
||||
return new PluginUnloadState(true, e.toString());
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class TSerializer {
|
||||
if (serializer == null) {
|
||||
serializable.read(jsonElementEntry.getKey(), jsonElementEntry.getValue().getAsString());
|
||||
} else {
|
||||
readCollection((Collection) declaredField.get(serializable), jsonElementEntry.getValue().getAsString(), checkCustom(listType, serializer));
|
||||
readCollection((Collection) Ref.getField(serializable, declaredField), jsonElementEntry.getValue().getAsString(), checkCustom(listType, serializer));
|
||||
}
|
||||
}
|
||||
// Map
|
||||
@ -65,7 +65,7 @@ public class TSerializer {
|
||||
if (serializerK == null || serializerV == null) {
|
||||
serializable.read(jsonElementEntry.getKey(), jsonElementEntry.getValue().getAsString());
|
||||
} else {
|
||||
readMap((Map) declaredField.get(serializable), jsonElementEntry.getValue().getAsString(), checkCustom(mapType[0], serializerK), checkCustom(mapType[1], serializerV));
|
||||
readMap((Map) Ref.getField(serializable, declaredField), jsonElementEntry.getValue().getAsString(), checkCustom(mapType[0], serializerK), checkCustom(mapType[1], serializerV));
|
||||
}
|
||||
}
|
||||
// 未声明类型
|
||||
@ -95,7 +95,7 @@ public class TSerializer {
|
||||
declaredField.setAccessible(true);
|
||||
try {
|
||||
if (!declaredField.isAnnotationPresent(DoNotSerialize.class) && !Modifier.isStatic(declaredField.getModifiers())) {
|
||||
Object fieldObject = declaredField.get(serializable);
|
||||
Object fieldObject = Ref.getField(serializable, declaredField);
|
||||
if (fieldObject == null) {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user