2022-10-15 00:34:58 +00:00
|
|
|
|
package love.distributedrebirth.bassboonyd;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
2022-10-17 14:42:12 +00:00
|
|
|
|
import love.distributedrebirth.bassboonyd.clazz.BãßBȍőnAuthor注;
|
2022-10-15 00:34:58 +00:00
|
|
|
|
|
|
|
|
|
@BãßBȍőnAuthor注(name = "للَّٰهِilLצسُو", copyright = "©Δ∞ 仙上主天")
|
|
|
|
|
public class BãßBȍőnSpiderʸᴰ {
|
|
|
|
|
|
|
|
|
|
private final Map<Class<?>, SpiderSilk> spiderWeb = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
protected BãßBȍőnSpiderʸᴰ() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasEggType(Class<?> eggType) {
|
|
|
|
|
return spiderWeb.containsKey(eggType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SpiderSilk silkRoad(Class<?> eggType) {
|
|
|
|
|
SpiderSilk silkRoad = spiderWeb.get(eggType);
|
|
|
|
|
if (silkRoad == null) {
|
|
|
|
|
throw new IllegalStateException("No silk road found for type: "+eggType);
|
|
|
|
|
}
|
|
|
|
|
return silkRoad;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void registrateEgg(Class<?> eggType, SpiderSilk spiderSilk) {
|
|
|
|
|
if (spiderWeb.containsKey(eggType)) {
|
|
|
|
|
throw new IllegalStateException("Can't registate class twice: "+eggType);
|
|
|
|
|
}
|
|
|
|
|
spiderWeb.put(eggType, spiderSilk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void registrateEgg(Class<?> eggType, Method m) {
|
|
|
|
|
registrateEgg(eggType, createSenseWire(m));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SpiderSilk createSenseWire(Method m) {
|
|
|
|
|
boolean valid = false;
|
|
|
|
|
Class<?>[] para = m.getParameterTypes();
|
|
|
|
|
if (para.length == 0) {
|
|
|
|
|
valid = true;
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 1 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
valid = true;
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 2 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
valid = true;
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 3 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1]) && String.class.isAssignableFrom(para[2])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
valid = true;
|
|
|
|
|
}
|
|
|
|
|
if (!valid) {
|
|
|
|
|
throw new IllegalStateException("Unknown method parameters on: "+m.getDeclaringClass().getSimpleName()+"."+m.toGenericString());
|
|
|
|
|
}
|
|
|
|
|
return new SpiderSilk() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object senseWire(Object boon, String name, String description) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
|
|
|
Class<?>[] para = m.getParameterTypes();
|
|
|
|
|
if (para.length == 0) {
|
|
|
|
|
return m.invoke(null);
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 1 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
return m.invoke(null, boon);
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 2 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
return m.invoke(null, boon, name);
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 3 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1]) && String.class.isAssignableFrom(para[2])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
return m.invoke(null, boon, name, description);
|
|
|
|
|
}
|
|
|
|
|
throw new IllegalStateException("Unknown method parameters on: "+m.getDeclaringClass().getSimpleName()+"."+m.toGenericString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isNamed() {
|
|
|
|
|
Class<?>[] para = m.getParameterTypes();
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 2 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-10-17 16:59:42 +00:00
|
|
|
|
if (para.length == 3 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1]) && String.class.isAssignableFrom(para[2])) {
|
2022-10-15 00:34:58 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface SpiderSilk {
|
|
|
|
|
|
|
|
|
|
boolean isNamed();
|
|
|
|
|
|
|
|
|
|
Object senseWire(Object boon, String name, String description) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException;
|
|
|
|
|
}
|
|
|
|
|
}
|