gdxapp4d/gdxapp4d-lib-bassboonyd/src/main/java/love/distributedrebirth/bassboonyd/BãßBȍőnSpider.java

100 lines
3.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package love.distributedrebirth.bassboonyd;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import love.distributedrebirth.bassboonyd.clazz.BãßBȍőnAuthor注;
@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;
}
if (para.length == 1 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0])) {
valid = true;
}
if (para.length == 2 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1])) {
valid = true;
}
if (para.length == 3 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1]) && String.class.isAssignableFrom(para[2])) {
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);
}
if (para.length == 1 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0])) {
return m.invoke(null, boon);
}
if (para.length == 2 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1])) {
return m.invoke(null, boon, name);
}
if (para.length == 3 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1]) && String.class.isAssignableFrom(para[2])) {
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();
if (para.length == 2 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1])) {
return true;
}
if (para.length == 3 && BãßBȍőnʸᴰ.class.isAssignableFrom(para[0]) && String.class.isAssignableFrom(para[1]) && String.class.isAssignableFrom(para[2])) {
return true;
}
return false;
}
};
}
public interface SpiderSilk {
boolean isNamed();
Object senseWire(Object boon, String name, String description) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException;
}
}