+ SimpleVersionControl 可以替换多个版本了

This commit is contained in:
坏黑 2018-09-29 22:37:45 +08:00
parent 6627c4a661
commit e8d068f7d9
3 changed files with 15 additions and 5 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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<String> 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<String> getFrom() {
return from;
}
public String getTo() {
return to;
}
public String replace(String origin) {
for (String from : from) {
origin = origin.replace("/" + from + "/", "/" + to + "/");
}
return origin;
}
}