From e8d068f7d9e938296027e102cc431c54222b3d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sat, 29 Sep 2018 22:37:45 +0800 Subject: [PATCH] =?UTF-8?q?+=20SimpleVersionControl=20=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=A4=9A=E4=B8=AA=E7=89=88=E6=9C=AC=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../versioncontrol/SimpleClassVisitor.java | 2 +- .../versioncontrol/SimpleMethodVisitor.java | 2 +- .../versioncontrol/SimpleVersionControl.java | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java index 40b179c..3be025e 100644 --- a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java +++ b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleClassVisitor.java @@ -43,7 +43,7 @@ public class SimpleClassVisitor extends ClassVisitor { } private String translate(String target) { - return target == null ? null : target.replace("/" + simpleVersionControl.getFrom() + "/", "/" + simpleVersionControl.getTo() + "/"); + return target == null ? null : simpleVersionControl.replace(target); } private String[] translate(String[] target) { diff --git a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java index 1584caa..c9b6a8c 100644 --- a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java +++ b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleMethodVisitor.java @@ -47,7 +47,7 @@ public class SimpleMethodVisitor extends MethodVisitor { } private String translate(String target) { - return target == null ? null : target.replaceAll("/" + simpleVersionControl.getFrom() + "/", "/" + simpleVersionControl.getTo() + "/"); + return target == null ? null : simpleVersionControl.replace(target); } private String[] translate(String[] target) { diff --git a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java index 156d09d..3e2f9bd 100644 --- a/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java +++ b/src/main/java/me/skymc/taboolib/common/versioncontrol/SimpleVersionControl.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.common.versioncontrol; +import com.google.common.collect.Lists; import com.ilummc.tlib.util.asm.AsmClassLoader; import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; @@ -10,6 +11,8 @@ import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * 我不信 ClassNotFound 的邪,自己写了一个发现还是一样。。。 @@ -20,7 +23,7 @@ import java.io.IOException; public class SimpleVersionControl { private String target; - private String from; + private List from = Lists.newArrayList(); private String to; private Plugin plugin; @@ -46,7 +49,7 @@ public class SimpleVersionControl { } public SimpleVersionControl from(String from) { - this.from = from.startsWith("v") ? from : "v" + from; + this.from.add(from.startsWith("v") ? from : "v" + from); return this; } @@ -80,11 +83,18 @@ public class SimpleVersionControl { return target; } - public String getFrom() { + public List getFrom() { return from; } public String getTo() { return to; } + + public String replace(String origin) { + for (String from : from) { + origin = origin.replace("/" + from + "/", "/" + to + "/"); + } + return origin; + } }