Guarmanda / LootChest

Plugin to reload chest with hologram, particles, and editing menu
GNU General Public License v3.0
11 stars 23 forks source link

1.20.6 plugin crashes on paper #63

Closed GorgeousOne closed 5 months ago

GorgeousOne commented 5 months ago

Starting the plugin on paper/purpur throws an error message:

[INFO]: [LootChest] Enabling LootChest v2.4.0
[INFO]: [LootChest] Server version: 1.20
[INFO]: [LootChest] Loading config files...
[INFO]: [LootChest] Checking for update...
[INFO]: [LootChest] Starting particles...
[ERROR]: Error occurred while enabling LootChest v2.4.0 (Is it up to date?)
java.lang.ExceptionInInitializerError: null
        at LootChest.jar/fr.black_eyes.lootchest.particles.ParticleTypes.<clinit>(ParticleTypes.java:18) ~[LootChest.jar:?]
        at LootChest.jar/fr.black_eyes.lootchest.particles.ParticleType.of(ParticleType.java:16) ~[LootChest.jar:?]
        at LootChest.jar/fr.black_eyes.lootchest.particles.Particle.<init>(Particle.java:171) ~[LootChest.jar:?]
        at LootChest.jar/fr.black_eyes.lootchest.particles.Particle.<clinit>(Particle.java:30) ~[LootChest.jar:?]
        at LootChest.jar/fr.black_eyes.lootchest.Main.initParticles(Main.java:502) ~[LootChest.jar:?]
        at LootChest.jar/fr.black_eyes.lootchest.Main.onEnable(Main.java:204) ~[LootChest.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:287) ~[purpur-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:202) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:109) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:519) ~[purpur-api-1.20.6-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.CraftServer.enablePlugin(CraftServer.java:618) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:567) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:678) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:440) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:357) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1150) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:326) ~[purpur-1.20.6.jar:1.20.6-2229-4873495]
        at java.base/java.lang.Thread.run(Thread.java:1570) ~[?:?]
Caused by: java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 22
        at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55) ~[?:?]
        at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52) ~[?:?]
        at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213) ~[?:?]
        at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210) ~[?:?]
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98) ~[?:?]
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112) ~[?:?]
        at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349) ~[?:?]
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4914) ~[?:?]
        at java.base/java.lang.String.substring(String.java:2876) ~[?:?]
        at java.base/java.lang.String.substring(String.java:2849) ~[?:?]
        at LootChest.jar/fr.black_eyes.lootchest.particles.FastReflection.<clinit>(FastReflection.java:18) ~[LootChest.jar:?]
        ... 18 more
[INFO]: [LootChest] Disabling LootChest v2.4.0
[INFO]: [LootChest] Backed up data file in case of crash

I think the index out of bound exception originates from how you try to find out the server version in FastReflection.

2 of my plugins had the same issue because on paper 1.20.6 Bukkit.getServer().getClass().getPackage().getName() somehow returns an empty string. The only solution I found was to use Bukkit.getBukkitVersion() instead. The function can not be used statically so I switched from static final variables to just static variables that all get initialized in the plugin's onEnable().

Would it be an option to fix the bug for paper?

Guarmanda commented 5 months ago

Thanks for this solution. Yes, paper removed some class, there is an official anouncement about this, and it breaks many plugins using reflection. I met this error during my tests yesterday and will solve it today hopefully

Guarmanda commented 5 months ago

Last push solved this