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, 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; } }