diff --git a/patches/api/Use-ASM-for-event-executors.patch b/patches/api/Use-ASM-for-event-executors.patch index 62c926bef9..9d54cb44d3 100644 --- a/patches/api/Use-ASM-for-event-executors.patch +++ b/patches/api/Use-ASM-for-event-executors.patch @@ -147,14 +147,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + methodGenerator.returnValue(); + methodGenerator.endMethod(); + // Generate the execute method -+ methodGenerator = new GeneratorAdapter(writer.visitMethod(ACC_PUBLIC, "execute", "(Lorg/bukkit/event/Listener;Lorg/bukkit/event/Event;)V", null, null), ACC_PUBLIC, "execute", "(Lorg/bukkit/event/Listener;Lorg/bukkit/event/Listener;)V");; ++ methodGenerator = new GeneratorAdapter(writer.visitMethod(ACC_PUBLIC, "execute", "(Lorg/bukkit/event/Listener;Lorg/bukkit/event/Event;)V", null, null), ACC_PUBLIC, "execute", "(Lorg/bukkit/event/Listener;Lorg/bukkit/event/Listener;)V"); + methodGenerator.loadArg(0); + methodGenerator.checkCast(Type.getType(m.getDeclaringClass())); + methodGenerator.loadArg(1); + methodGenerator.checkCast(Type.getType(m.getParameterTypes()[0])); + methodGenerator.visitMethodInsn(m.getDeclaringClass().isInterface() ? INVOKEINTERFACE : INVOKEVIRTUAL, Type.getInternalName(m.getDeclaringClass()), m.getName(), Type.getMethodDescriptor(m), m.getDeclaringClass().isInterface()); -+ if (m.getReturnType() != void.class) { -+ methodGenerator.pop(); ++ // The only purpose of this switch statement is to generate the correct pop instruction, should the event handler method return something other than void. ++ // Non-void event handlers will be unsupported in a future release. ++ switch (Type.getType(m.getReturnType()).getSize()) { ++ // case 0 is omitted because the only type that has size 0 is void - no pop instruction needed. ++ case 1 -> methodGenerator.pop(); // handles reference types and most primitives ++ case 2 -> methodGenerator.pop2(); // handles long and double + } + methodGenerator.returnValue(); + methodGenerator.endMethod(); diff --git a/patches/api/Warn-on-strange-EventHandler-return-types.patch b/patches/api/Warn-on-strange-EventHandler-return-types.patch index 588ba35f89..317f07ceb1 100644 --- a/patches/api/Warn-on-strange-EventHandler-return-types.patch +++ b/patches/api/Warn-on-strange-EventHandler-return-types.patch @@ -15,8 +15,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (m.getReturnType() != Void.TYPE) { + final org.bukkit.plugin.java.JavaPlugin plugin = org.bukkit.plugin.java.JavaPlugin.getProvidingPlugin(m.getDeclaringClass()); + org.bukkit.Bukkit.getLogger().warning("@EventHandler method " + m.getDeclaringClass().getName() + (Modifier.isStatic(m.getModifiers()) ? '.' : '#') + m.getName() -+ + " returns non-void type " + m.getReturnType().getName() + ". This is an unsupported behavior which will be removed in a future version of Paper." -+ + "This should be reported to the developers of " + plugin.getDescription().getFullName() + ", (" + String.join(",", plugin.getDescription().getAuthors()) + ')'); ++ + " returns non-void type " + m.getReturnType().getName() + ". This is unsupported behavior and will no longer work in a future version of Paper." ++ + " This should be reported to the developers of " + plugin.getDescription().getFullName() + " (" + String.join(",", plugin.getDescription().getAuthors()) + ')'); + } if (Modifier.isStatic(m.getModifiers())) { return new StaticMethodHandleEventExecutor(eventClass, m);