@Override public Object invoke(Object proxy, Method method, Object[] args) { Hook hook = new Hook(); Method customMethod = null; Object[] customArgs = new Object[args.length + 1]; // Get a string representation of this invokation. String key = MethodCache.getKey(this.original, method.getName(), args); // Look for a custom handler. if (this.mapping.containsKey(key)) { customArgs[0] = hook; System.arraycopy(args, 0, customArgs, 1, args.length); Method cached = MethodCache.getMethod(this.custom, this.mapping.get(key), customArgs); if (cached != null) customMethod = cached; } if (customMethod == null && !key.equals("ls.d(mw)") && !key.equals("ls.s()")) System.out.println(key + " => " + method); // Go ahead. Object toReturn = null; try { if (customMethod != null) toReturn = customMethod.invoke(this.custom, customArgs); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } try { if (!hook.isCancelled()) toReturn = method.invoke(this.original, args); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } return toReturn; }