JohnnyJayJay / spigot-maps

A library to simplify the use of customised maps in Spigot.
GNU Lesser General Public License v3.0
48 stars 4 forks source link

NoSuchMethodError for anything below 1.13.2 #6

Closed JohnnyJayJay closed 4 years ago

JohnnyJayJay commented 4 years ago

Describe the bug Creating RenderedMaps on legacy versions yields a NoSuchMethodError. This is because prior to 1.13.2, MapView#getId() returned a short instead of an int. Since the library is currently compiled against newer versions, it always looks for a getId() method that returns an int.

The obvious fix would be to compile the library against different spigot versions. But that is something I want to avoid from 2.0 on. As an alternative, reflection/MethodHandles that are initialised differently based on the Minecraft version could be used.

To Reproduce Steps to reproduce the behavior:

  1. Include version 2.0 of this library
  2. Create a RenderedMap

Expected behavior It should work without any issues.

Screenshots, Code & Stack Traces

java.lang.NoSuchMethodError: org.bukkit.map.MapView.getId()I
        at com.github.johnnyjayjay.spigotmaps.RenderedMap.lambda$new$0(RenderedMap.java:32) ~[?:?]
        at java.util.ArrayList.forEach(Unknown Source) ~[?:1.8.0_261]
        at com.github.johnnyjayjay.spigotmaps.RenderedMap.<init>(RenderedMap.java:32) ~[?:?]
        at com.github.johnnyjayjay.spigotmaps.RenderedMap.create(RenderedMap.java:54) ~[?:?]
        at com.github.johnnyjayjay.spigotmaps.MapBuilder.build(MapBuilder.java:55) ~[?:?]
        at me.d3lt3x.maps.main.Main.createImage(Main.java:61) ~[?:?]
        at me.d3lt3x.maps.main.Main.onCommand(Main.java:36) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_261]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 16 more

Spigot Version: 1.8.8, but same for anything below 1.13.2.

Additional context /