CryptoMorin / XSeries

Library for cross-version Minecraft Bukkit support and various efficient API methods.
https://www.spigotmc.org/threads/378136/
MIT License
403 stars 126 forks source link

XSeries not working on pre-release versions #145

Closed wouterdedroog closed 2 years ago

wouterdedroog commented 2 years ago

Hi, I've already started working on getting my plugin ready to support 1.18, and I've used the the SpigotMC build for Pre-release 5 to test my changes. Whilst testing, I ran into a small issue with the version parsing that prevented my plugin from working as expected. I've worked around this issue by temporarily hardcoding the value of the Data.VERSION to 18.

I got the following error:

Error occurred while enabling MinetopiaSDB v2.4.4 (Is it up to date?)
java.lang.ExceptionInInitializerError: null
        at nl.minetopiasdb.shaded.xseries.XMaterial.<init>(XMaterial.java:1512) ~[?:?]
        at nl.minetopiasdb.shaded.xseries.XMaterial.<init>(XMaterial.java:1521) ~[?:?]
        at nl.minetopiasdb.shaded.xseries.XMaterial.<clinit>(XMaterial.java:69) ~[?:?]
        at nl.minetopiasdb.plugin.data.configs.config.ConfigValue.<clinit>(ConfigValue.java:51) ~[?:?]
        at nl.minetopiasdb.plugin.data.configs.config.ConfigManager.addDefaults(ConfigManager.java:29) ~[?:?]
        at nl.minetopiasdb.plugin.Main.onEnable(Main.java:233) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-api-1.18-pre5-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-api-1.18-pre5-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-api-1.18-pre5-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugin(CraftServer.java:525) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at org.bukkit.craftbukkit.v1_18_R1.CraftServer.enablePlugins(CraftServer.java:439) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:611) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:412) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:262) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:993) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:303) ~[spigot-1.18-pre5-R0.1-SNAPSHOT.jar:3294-Spigot-6234669-7c4707e]
        at java.lang.Thread.run(Thread.java:833) [?:?]
Caused by: java.lang.NumberFormatException: For input string: "18 Pre-release 5"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:67) ~[?:?]
        at java.lang.Integer.parseInt(Integer.java:668) ~[?:?]
        at java.lang.Integer.parseInt(Integer.java:786) ~[?:?]
        at nl.minetopiasdb.shaded.xseries.XMaterial$Data.<clinit>(XMaterial.java:2154) ~[?:?]
        ... 17 more

I'm relocating the XSeries dependency to prevent conflicts, which is why the package names might look off. This is by no means a high-priority issue, since it only affects pre-release versions that probably aren't supported anyway. For me it wasn't a concern, since I could simply hardcode the value

This issue is caused by the following line, and could probably be prevented by replacing the .substring(2) with a variation of .substring(2, 4), since this will cause issues with versions <= 1.9. If wanted, I can quickly create a PR for this.

https://github.com/CryptoMorin/XSeries/blob/4f7dfe56d640d6c297c3cd8347b936f33ab29c37/src/main/java/com/cryptomorin/xseries/XMaterial.java#L2154

Thanks for the amazing work you do! <3

CryptoMorin commented 2 years ago

Sure go ahead.

I think replacing getMajorVersion and all the substring stuff with a simple Regex would be more reliable and maintainable at this point. This is really just parsed statically, so performance doesn't matter at all. You should also avoid caching the compiled regex and remove getMajorVersion altogether because Idk why anyone would want to use them.

It's really sad that there's no standardized way of getting version details with the Spigot API.