0

I'm using CGLib to dynamicly change a TileEntity (Minecraft). In the InvocationHandler I call the Lua functions for the interface, but I want the methods that already exist to be called in Java. This is my invoke method:

    public Object invoke(Object arg0, Method arg1, Object[] arg2)
            throws Throwable {
        for (Method m : BaseTileEntity.class.getMethods()) {
            if (m.equals(arg1)) {
                return m.invoke(arg0, arg2);
            }
        }
        return ((BaseTileEntity)arg0).file.call(arg1.getName(), arg2).arg(1);
    }

The problem is that invoking the method will call the same method and not the original method. Is there a way to call the original method?

Rule
  • 105
  • 1
  • 10
  • Well, I'm not sure if it actually overrides invoke(). I'm implementing a callback interface of CGLib. – Rule Mar 16 '13 at 15:37

1 Answers1

2

Found out how to call the original method: implement MethodInterceptor instead of InvocationHandler. The method of MethodInterceptor has an extra argument that can call the original method using .invokeSuper(arg0, arg2).

Rule
  • 105
  • 1
  • 10