+ 一些半成品,修复了一些碧油鸡
This commit is contained in:
		@@ -50,6 +50,10 @@ public class AsmClassTransformer extends ClassVisitor implements Opcodes {
 | 
			
		||||
        return new Builder().toVersion(Bukkit.getServer().getClass().getName().split("\\.")[3]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Builder builder(String ver) {
 | 
			
		||||
        return new Builder().toVersion(ver);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
 | 
			
		||||
        MethodVisitor visitor = super.visitMethod(access, name, replace(descriptor), replace(signature), replace(exceptions));
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,6 @@ import java.util.Arrays;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author sky
 | 
			
		||||
@@ -35,16 +34,6 @@ public class TabooLibLoader implements Listener {
 | 
			
		||||
 | 
			
		||||
    static HashMap<String, List<Class>> pluginClasses = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    @EventHandler (priority = EventPriority.LOWEST)
 | 
			
		||||
    public void onEnable(PluginEnableEvent e) {
 | 
			
		||||
        pluginClasses.remove(e.getPlugin().getName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler (priority = EventPriority.MONITOR)
 | 
			
		||||
    public void onDisable(PluginDisableEvent e) {
 | 
			
		||||
        setupClasses(e.getPlugin());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static void setup() {
 | 
			
		||||
        testInternet();
 | 
			
		||||
        setupDataFolder();
 | 
			
		||||
@@ -166,4 +155,14 @@ public class TabooLibLoader implements Listener {
 | 
			
		||||
        Metrics metrics = new Metrics(TabooLib.instance());
 | 
			
		||||
        metrics.addCustomChart(new Metrics.SingleLineChart("plugins_using_taboolib", () -> Math.toIntExact(Arrays.stream(Bukkit.getPluginManager().getPlugins()).filter(plugin -> plugin.getDescription().getDepend().contains("TabooLib")).count())));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.LOWEST)
 | 
			
		||||
    public void onEnable(PluginEnableEvent e) {
 | 
			
		||||
        pluginClasses.remove(e.getPlugin().getName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR)
 | 
			
		||||
    public void onDisable(PluginDisableEvent e) {
 | 
			
		||||
        setupClasses(e.getPlugin());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,8 @@ package me.skymc.taboolib.anvil;
 | 
			
		||||
 | 
			
		||||
import com.ilummc.tlib.util.asm.AsmClassLoader;
 | 
			
		||||
import me.skymc.taboolib.TabooLib;
 | 
			
		||||
import me.skymc.taboolib.listener.TListener;
 | 
			
		||||
import me.skymc.taboolib.object.Instantiable;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
@@ -11,7 +12,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
 | 
			
		||||
/**
 | 
			
		||||
 * @author sky
 | 
			
		||||
 */
 | 
			
		||||
@TListener
 | 
			
		||||
@Instantiable("AnvilContainerAPI")
 | 
			
		||||
public class AnvilContainerAPI implements Listener {
 | 
			
		||||
 | 
			
		||||
    private static Class<?> impl;
 | 
			
		||||
@@ -19,6 +20,7 @@ public class AnvilContainerAPI implements Listener {
 | 
			
		||||
    public AnvilContainerAPI() {
 | 
			
		||||
        try {
 | 
			
		||||
            impl = AsmClassLoader.createNewClass("me.skymc.taboolib.anvil.AnvilContainer", AnvilContainerAsm.create(TabooLib.getVersion()));
 | 
			
		||||
            Bukkit.getPluginManager().registerEvents(this, TabooLib.instance());
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -8,16 +8,12 @@ import org.objectweb.asm.*;
 | 
			
		||||
public class AnvilContainerAsm {
 | 
			
		||||
 | 
			
		||||
    public static byte[] create(String version) {
 | 
			
		||||
 | 
			
		||||
        ClassWriter cw = new ClassWriter(0);
 | 
			
		||||
        FieldVisitor fv;
 | 
			
		||||
        MethodVisitor mv;
 | 
			
		||||
        AnnotationVisitor av0;
 | 
			
		||||
 | 
			
		||||
        cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "me/skymc/taboolib/anvil/AnvilContainer", null, "net/minecraft/server/" + version + "/ContainerAnvil", null);
 | 
			
		||||
 | 
			
		||||
        cw.visitSource("AnvilContainer.java", null);
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lnet/minecraft/server/" + version + "/EntityHuman;)V", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
@@ -139,7 +135,6 @@ public class AnvilContainerAsm {
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        cw.visitEnd();
 | 
			
		||||
 | 
			
		||||
        return cw.toByteArray();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package me.skymc.taboolib.common.pathfinder;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2018-09-19 19:42
 | 
			
		||||
 */
 | 
			
		||||
public abstract class SimpleAI {
 | 
			
		||||
 | 
			
		||||
    public abstract boolean shouldExecute();
 | 
			
		||||
 | 
			
		||||
    public boolean continueExecute() {
 | 
			
		||||
        return shouldExecute();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void startTask() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void resetTask() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateTask() {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,88 @@
 | 
			
		||||
package me.skymc.taboolib.common.pathfinder;
 | 
			
		||||
 | 
			
		||||
import com.ilummc.tlib.util.asm.AsmClassLoader;
 | 
			
		||||
import me.skymc.taboolib.TabooLib;
 | 
			
		||||
import me.skymc.taboolib.common.pathfinder.internal.ParentPathfinderGoalAsm;
 | 
			
		||||
import me.skymc.taboolib.nms.NMSUtils;
 | 
			
		||||
import me.skymc.taboolib.object.Instantiable;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2018-09-19 20:31
 | 
			
		||||
 */
 | 
			
		||||
@Instantiable("SimpleAISelector")
 | 
			
		||||
public class SimpleAISelector {
 | 
			
		||||
 | 
			
		||||
    private static Class<?> parentPathfinderGoal;
 | 
			
		||||
    private static Class<?> pathfinderGoalFollowOwner;
 | 
			
		||||
    private static Class<?> pathfinderGoalSelector;
 | 
			
		||||
    private static Class<?> pathfinderGoal;
 | 
			
		||||
    private static Class<?> entityInsentient;
 | 
			
		||||
    private static Field targetSelector;
 | 
			
		||||
    private static Field goalSelector;
 | 
			
		||||
    private static Field navigation;
 | 
			
		||||
    private static Method a;
 | 
			
		||||
 | 
			
		||||
    public SimpleAISelector() {
 | 
			
		||||
        try {
 | 
			
		||||
            parentPathfinderGoal = AsmClassLoader.createNewClass("me.skymc.taboolib.common.pathfinder.internal.ParentPathfinderGoal", ParentPathfinderGoalAsm.create(TabooLib.getVersion()));
 | 
			
		||||
            pathfinderGoalFollowOwner = NMSUtils.getNMSClass("PathfinderGoalFollowOwner");
 | 
			
		||||
            pathfinderGoalSelector = NMSUtils.getNMSClass("PathfinderGoalSelector");
 | 
			
		||||
            pathfinderGoal = NMSUtils.getNMSClass("PathfinderGoal");
 | 
			
		||||
            entityInsentient = NMSUtils.getNMSClass("EntityInsentient");
 | 
			
		||||
            targetSelector = entityInsentient.getField("targetSelector");
 | 
			
		||||
            goalSelector = entityInsentient.getField("goalSelector");
 | 
			
		||||
            navigation = entityInsentient.getField("navigation");
 | 
			
		||||
            a = pathfinderGoalSelector.getDeclaredMethod("a", Integer.TYPE, pathfinderGoal);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getNavigation(LivingEntity entity) {
 | 
			
		||||
        try {
 | 
			
		||||
            return navigation.get(entity.getClass().getMethod("getHandle").invoke(entity));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getGoalSelector(LivingEntity entity) {
 | 
			
		||||
        try {
 | 
			
		||||
            return goalSelector.get(entity.getClass().getMethod("getHandle").invoke(entity));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Object getTargetSelector(LivingEntity entity) {
 | 
			
		||||
        try {
 | 
			
		||||
            return targetSelector.get(entity.getClass().getMethod("getHandle").invoke(entity));
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setGoalAI(LivingEntity entity, Object ai, int priority) {
 | 
			
		||||
        try {
 | 
			
		||||
            a.invoke(getGoalSelector(entity), priority, ai);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setTargetAI(LivingEntity entity, Object ai, int priority) {
 | 
			
		||||
        try {
 | 
			
		||||
            a.invoke(getTargetSelector(entity), priority, ai);
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,41 @@
 | 
			
		||||
package me.skymc.taboolib.common.pathfinder.internal;
 | 
			
		||||
 | 
			
		||||
import me.skymc.taboolib.common.pathfinder.SimpleAI;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2018-09-19 22:31
 | 
			
		||||
 */
 | 
			
		||||
public class ParentPathfinderGoal extends net.minecraft.server.v1_12_R1.PathfinderGoal {
 | 
			
		||||
 | 
			
		||||
    private final SimpleAI simpleAI;
 | 
			
		||||
 | 
			
		||||
    public ParentPathfinderGoal(SimpleAI simpleAI) {
 | 
			
		||||
        this.simpleAI = simpleAI;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean a() {
 | 
			
		||||
        return simpleAI.shouldExecute();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean b() {
 | 
			
		||||
        return simpleAI.continueExecute();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void c() {
 | 
			
		||||
        simpleAI.startTask();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void d() {
 | 
			
		||||
        simpleAI.resetTask();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void e() {
 | 
			
		||||
        simpleAI.updateTask();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,143 @@
 | 
			
		||||
package me.skymc.taboolib.common.pathfinder.internal;
 | 
			
		||||
 | 
			
		||||
import org.objectweb.asm.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author sky
 | 
			
		||||
 */
 | 
			
		||||
public class ParentPathfinderGoalAsm {
 | 
			
		||||
 | 
			
		||||
    public static byte[] create(String version) {
 | 
			
		||||
 | 
			
		||||
        ClassWriter cw = new ClassWriter(0);
 | 
			
		||||
        FieldVisitor fv;
 | 
			
		||||
        MethodVisitor mv;
 | 
			
		||||
        AnnotationVisitor av0;
 | 
			
		||||
 | 
			
		||||
        cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", null, "net/minecraft/server/" + version + "/PathfinderGoal", null);
 | 
			
		||||
 | 
			
		||||
        cw.visitSource("ParentPathfinderGoal.java", null);
 | 
			
		||||
 | 
			
		||||
        {
 | 
			
		||||
            fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;", null, null);
 | 
			
		||||
            fv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "(Lme/skymc/taboolib/common/pathfinder/SimpleAI;)V", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
            Label l0 = new Label();
 | 
			
		||||
            mv.visitLabel(l0);
 | 
			
		||||
            mv.visitLineNumber(13, l0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "net/minecraft/server/" + version + "/PathfinderGoal", "<init>", "()V", false);
 | 
			
		||||
            Label l1 = new Label();
 | 
			
		||||
            mv.visitLabel(l1);
 | 
			
		||||
            mv.visitLineNumber(14, l1);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 1);
 | 
			
		||||
            mv.visitFieldInsn(Opcodes.PUTFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;");
 | 
			
		||||
            Label l2 = new Label();
 | 
			
		||||
            mv.visitLabel(l2);
 | 
			
		||||
            mv.visitLineNumber(15, l2);
 | 
			
		||||
            mv.visitInsn(Opcodes.RETURN);
 | 
			
		||||
            Label l3 = new Label();
 | 
			
		||||
            mv.visitLabel(l3);
 | 
			
		||||
            mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l3, 0);
 | 
			
		||||
            mv.visitLocalVariable("simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;", null, l0, l3, 1);
 | 
			
		||||
            mv.visitMaxs(2, 2);
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "a", "()Z", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
            Label l0 = new Label();
 | 
			
		||||
            mv.visitLabel(l0);
 | 
			
		||||
            mv.visitLineNumber(19, l0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;");
 | 
			
		||||
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAI", "shouldExecute", "()Z", false);
 | 
			
		||||
            mv.visitInsn(Opcodes.IRETURN);
 | 
			
		||||
            Label l1 = new Label();
 | 
			
		||||
            mv.visitLabel(l1);
 | 
			
		||||
            mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l1, 0);
 | 
			
		||||
            mv.visitMaxs(1, 1);
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "b", "()Z", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
            Label l0 = new Label();
 | 
			
		||||
            mv.visitLabel(l0);
 | 
			
		||||
            mv.visitLineNumber(24, l0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;");
 | 
			
		||||
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAI", "continueExecute", "()Z", false);
 | 
			
		||||
            mv.visitInsn(Opcodes.IRETURN);
 | 
			
		||||
            Label l1 = new Label();
 | 
			
		||||
            mv.visitLabel(l1);
 | 
			
		||||
            mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l1, 0);
 | 
			
		||||
            mv.visitMaxs(1, 1);
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "c", "()V", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
            Label l0 = new Label();
 | 
			
		||||
            mv.visitLabel(l0);
 | 
			
		||||
            mv.visitLineNumber(29, l0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;");
 | 
			
		||||
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAI", "startTask", "()V", false);
 | 
			
		||||
            Label l1 = new Label();
 | 
			
		||||
            mv.visitLabel(l1);
 | 
			
		||||
            mv.visitLineNumber(30, l1);
 | 
			
		||||
            mv.visitInsn(Opcodes.RETURN);
 | 
			
		||||
            Label l2 = new Label();
 | 
			
		||||
            mv.visitLabel(l2);
 | 
			
		||||
            mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l2, 0);
 | 
			
		||||
            mv.visitMaxs(1, 1);
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "d", "()V", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
            Label l0 = new Label();
 | 
			
		||||
            mv.visitLabel(l0);
 | 
			
		||||
            mv.visitLineNumber(34, l0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;");
 | 
			
		||||
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAI", "resetTask", "()V", false);
 | 
			
		||||
            Label l1 = new Label();
 | 
			
		||||
            mv.visitLabel(l1);
 | 
			
		||||
            mv.visitLineNumber(35, l1);
 | 
			
		||||
            mv.visitInsn(Opcodes.RETURN);
 | 
			
		||||
            Label l2 = new Label();
 | 
			
		||||
            mv.visitLabel(l2);
 | 
			
		||||
            mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l2, 0);
 | 
			
		||||
            mv.visitMaxs(1, 1);
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        {
 | 
			
		||||
            mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "e", "()V", null, null);
 | 
			
		||||
            mv.visitCode();
 | 
			
		||||
            Label l0 = new Label();
 | 
			
		||||
            mv.visitLabel(l0);
 | 
			
		||||
            mv.visitLineNumber(39, l0);
 | 
			
		||||
            mv.visitVarInsn(Opcodes.ALOAD, 0);
 | 
			
		||||
            mv.visitFieldInsn(Opcodes.GETFIELD, "me/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal", "simpleAI", "Lme/skymc/taboolib/common/pathfinder/SimpleAI;");
 | 
			
		||||
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "me/skymc/taboolib/common/pathfinder/SimpleAI", "updateTask", "()V", false);
 | 
			
		||||
            Label l1 = new Label();
 | 
			
		||||
            mv.visitLabel(l1);
 | 
			
		||||
            mv.visitLineNumber(40, l1);
 | 
			
		||||
            mv.visitInsn(Opcodes.RETURN);
 | 
			
		||||
            Label l2 = new Label();
 | 
			
		||||
            mv.visitLabel(l2);
 | 
			
		||||
            mv.visitLocalVariable("this", "Lme/skymc/taboolib/common/pathfinder/internal/ParentPathfinderGoal;", null, l0, l2, 0);
 | 
			
		||||
            mv.visitMaxs(1, 1);
 | 
			
		||||
            mv.visitEnd();
 | 
			
		||||
        }
 | 
			
		||||
        cw.visitEnd();
 | 
			
		||||
 | 
			
		||||
        return cw.toByteArray();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -48,8 +48,7 @@ public class PlayerContainerLoader implements Listener {
 | 
			
		||||
                    field.setAccessible(true);
 | 
			
		||||
                    try {
 | 
			
		||||
                        pluginContainer.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(new Container(field.get(pluginClass), annotation.uniqueId()));
 | 
			
		||||
                    } catch (IllegalAccessException e) {
 | 
			
		||||
                        e.printStackTrace();
 | 
			
		||||
                    } catch (IllegalAccessException ignored) {
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
package me.skymc.taboolib.common.versioncontrol;
 | 
			
		||||
 | 
			
		||||
import org.objectweb.asm.ClassVisitor;
 | 
			
		||||
import org.objectweb.asm.FieldVisitor;
 | 
			
		||||
import org.objectweb.asm.MethodVisitor;
 | 
			
		||||
import org.objectweb.asm.Opcodes;
 | 
			
		||||
 | 
			
		||||
import java.util.stream.IntStream;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 我不信 ClassNotFound 的邪,自己写了一个发现还是一样。。。
 | 
			
		||||
 *
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2018-09-19 21:17
 | 
			
		||||
 */
 | 
			
		||||
public class SimpleClassVisitor extends ClassVisitor {
 | 
			
		||||
 | 
			
		||||
    private final SimpleVersionControl simpleVersionControl;
 | 
			
		||||
 | 
			
		||||
    public SimpleClassVisitor(SimpleVersionControl simpleVersionControl, ClassVisitor classVisitor) {
 | 
			
		||||
        super(Opcodes.ASM6, classVisitor);
 | 
			
		||||
        this.simpleVersionControl = simpleVersionControl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
 | 
			
		||||
        super.visit(version, access, name, signature, translate(superName), translate(interfaces));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
 | 
			
		||||
        return super.visitField(access, name, translate(descriptor), translate(signature), value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
 | 
			
		||||
        return new SimpleMethodVisitor(simpleVersionControl, super.visitMethod(access, name, translate(descriptor), translate(signature), translate(exceptions)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String translate(String target) {
 | 
			
		||||
        return target == null ? null : target.replace("/" + simpleVersionControl.getFrom() + "/", "/" + simpleVersionControl.getTo() + "/");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String[] translate(String[] target) {
 | 
			
		||||
        if (target == null) {
 | 
			
		||||
            return target;
 | 
			
		||||
        }
 | 
			
		||||
        IntStream.range(0, target.length).forEach(i -> target[i] = translate(target[i]));
 | 
			
		||||
        return target;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,60 @@
 | 
			
		||||
package me.skymc.taboolib.common.versioncontrol;
 | 
			
		||||
 | 
			
		||||
import org.objectweb.asm.Label;
 | 
			
		||||
import org.objectweb.asm.MethodVisitor;
 | 
			
		||||
import org.objectweb.asm.Opcodes;
 | 
			
		||||
 | 
			
		||||
import java.util.stream.IntStream;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 我不信 ClassNotFound 的邪,自己写了一个发现还是一样。。。
 | 
			
		||||
 *
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2018-9-19 21:33
 | 
			
		||||
 */
 | 
			
		||||
public class SimpleMethodVisitor extends MethodVisitor {
 | 
			
		||||
 | 
			
		||||
    private final SimpleVersionControl simpleVersionControl;
 | 
			
		||||
 | 
			
		||||
    public SimpleMethodVisitor(SimpleVersionControl simpleVersionControl, MethodVisitor methodVisitor) {
 | 
			
		||||
        super(Opcodes.ASM6, methodVisitor);
 | 
			
		||||
        this.simpleVersionControl = simpleVersionControl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
 | 
			
		||||
        super.visitMethodInsn(opcode, translate(owner), name, translate(descriptor), isInterface);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void visitLdcInsn(Object value) {
 | 
			
		||||
        super.visitLdcInsn(value instanceof String ? translate((String) value) : value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void visitTypeInsn(int opcode, String type) {
 | 
			
		||||
        super.visitTypeInsn(opcode, translate(type));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
 | 
			
		||||
        super.visitFieldInsn(opcode, translate(owner), name, translate(descriptor));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) {
 | 
			
		||||
        super.visitLocalVariable(name, translate(descriptor), translate(signature), start, end, index);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String translate(String target) {
 | 
			
		||||
        return target == null ? null : target.replaceAll("/" + simpleVersionControl.getFrom() + "/", "/" + simpleVersionControl.getTo() + "/");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String[] translate(String[] target) {
 | 
			
		||||
        if (target == null) {
 | 
			
		||||
            return target;
 | 
			
		||||
        }
 | 
			
		||||
        IntStream.range(0, target.length).forEach(i -> target[i] = translate(target[i]));
 | 
			
		||||
        return target;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,79 @@
 | 
			
		||||
package me.skymc.taboolib.common.versioncontrol;
 | 
			
		||||
 | 
			
		||||
import com.ilummc.tlib.util.asm.AsmClassLoader;
 | 
			
		||||
import me.skymc.taboolib.TabooLib;
 | 
			
		||||
import org.objectweb.asm.ClassReader;
 | 
			
		||||
import org.objectweb.asm.ClassVisitor;
 | 
			
		||||
import org.objectweb.asm.ClassWriter;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 我不信 ClassNotFound 的邪,自己写了一个发现还是一样。。。
 | 
			
		||||
 *
 | 
			
		||||
 * @Author sky
 | 
			
		||||
 * @Since 2018-09-19 21:05
 | 
			
		||||
 */
 | 
			
		||||
public class SimpleVersionControl {
 | 
			
		||||
 | 
			
		||||
    private String target;
 | 
			
		||||
    private String from;
 | 
			
		||||
    private String to;
 | 
			
		||||
 | 
			
		||||
    SimpleVersionControl() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static SimpleVersionControl create() {
 | 
			
		||||
        return new SimpleVersionControl().to(TabooLib.getVersion());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static SimpleVersionControl create(String toVersion) {
 | 
			
		||||
        return new SimpleVersionControl().to(toVersion);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SimpleVersionControl target(Class<?> target) {
 | 
			
		||||
        this.target = target.getName();
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SimpleVersionControl target(String target) {
 | 
			
		||||
        this.target = target;
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SimpleVersionControl from(String from) {
 | 
			
		||||
        this.from = from.startsWith("v") ? from : "v" + from;
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SimpleVersionControl to(String to) {
 | 
			
		||||
        this.to = to.startsWith("v") ? to : "v" + to;
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Class<?> translate() throws IOException {
 | 
			
		||||
        ClassReader classReader = new ClassReader(target);
 | 
			
		||||
        ClassWriter classWriter = new ClassWriter(0);
 | 
			
		||||
        ClassVisitor classVisitor = new SimpleClassVisitor(this, classWriter);
 | 
			
		||||
        classReader.accept(classVisitor, 0);
 | 
			
		||||
        return AsmClassLoader.createNewClass(target, classWriter.toByteArray());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // *********************************
 | 
			
		||||
    //
 | 
			
		||||
    //        Getter and Setter
 | 
			
		||||
    //
 | 
			
		||||
    // *********************************
 | 
			
		||||
 | 
			
		||||
    public String getTarget() {
 | 
			
		||||
        return target;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getFrom() {
 | 
			
		||||
        return from;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getTo() {
 | 
			
		||||
        return to;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -187,4 +187,14 @@ public class ItemBuilder {
 | 
			
		||||
        }
 | 
			
		||||
        return buildItem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 从文本中获取物品(name:名字;lore:描述||描述;material:材质)
 | 
			
		||||
     *
 | 
			
		||||
     * @param str
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static ItemStack fromString(String str) {
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -59,8 +59,7 @@ public class TListenerHandler implements Listener {
 | 
			
		||||
                        // 实例化监听器
 | 
			
		||||
                        Listener listener = plugin.getClass().equals(pluginClass) ? (Listener) plugin : (Listener) ReflectionUtils.instantiateObject(pluginClass);
 | 
			
		||||
                        listeners.computeIfAbsent(plugin.getName(), name -> new ArrayList<>()).add(listener);
 | 
			
		||||
                    } catch (Exception e) {
 | 
			
		||||
                        e.printStackTrace();
 | 
			
		||||
                    } catch (Exception ignored) {
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -75,6 +75,7 @@ ENABLE-UUID: false
 | 
			
		||||
HIDE-NOTIFY: true
 | 
			
		||||
 | 
			
		||||
# 数据库信息
 | 
			
		||||
# 该功能在当前版本下无法使用,请勿启用
 | 
			
		||||
MYSQL:
 | 
			
		||||
  # 是否启用数据库
 | 
			
		||||
  ENABLE: false
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user