DiscordSRV

DiscordSRV

86.8k Downloads

NoClassDefFoundError when using alert with Essentials AFK event

granny opened this issue ยท 0 comments

commented

Expected behavior

No error should appear when a player leaves the server after being AFK.

Actual behavior

An error appears when a player leaves the server after being AFK.

Steps to reproduce

  1. Make sure the server is in offline mode and EssentialsX is installed
  2. Configure your alerts.yml to include this trigger:
      - Trigger: AfkStatusChangeEvent
        Channel: global
        Embed:
          Color: "#869600"
          Author:
            ImageUrl: "https://crafatar.com/avatars/${#event.getAffected().getBase().getUniqueId()}?overlay"
            Name: '${#event.getAffected().getName() + " is " + (#event.value ? "now" : "no longer") + " AFK"}'
  3. /discordsrv reload if you added the alert after already starting your server
  4. Join the server
  5. Run /afk to set yourself as AFK in EssX's system
  6. Leave the server
  7. Observe this error in console:
    java.lang.NoClassDefFoundError: org/bukkit/Achievement
            at java.lang.Class.getDeclaredMethods0(Native Method) ~[?:?]
            at java.lang.Class.privateGetDeclaredMethods(Class.java:3402) ~[?:?]
            at java.lang.Class.privateGetPublicMethods(Class.java:3427) ~[?:?]
            at java.lang.Class.getMethods(Class.java:2019) ~[?:?]
            at org.springframework.expression.spel.support.ReflectiveMethodResolver.getMethods(ReflectiveMethodResolver.java:272) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.support.ReflectiveMethodResolver.getMethods(ReflectiveMethodResolver.java:253) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.support.ReflectiveMethodResolver.resolve(ReflectiveMethodResolver.java:118) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:206) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:135) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:55) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:387) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:92) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:117) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:308) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.util.SpELExpressionBuilder.evaluate(SpELExpressionBuilder.java:73) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.util.SpELExpressionBuilder.evaluate(SpELExpressionBuilder.java:67) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.util.NamedValueFormatter.lambda$formatExpressions$1(NamedValueFormatter.java:98) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.util.NamedValueFormatter.format(NamedValueFormatter.java:57) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.util.NamedValueFormatter.formatExpressions(NamedValueFormatter.java:92) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.modules.alerts.AlertListener.lambda$process$9(AlertListener.java:461) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.DiscordSRV.lambda$translateMessage$63(DiscordSRV.java:2005) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at java.util.Optional.map(Optional.java:260) ~[?:?]
            at github.scarsz.discordsrv.DiscordSRV.translateMessage(DiscordSRV.java:2005) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.modules.alerts.AlertListener.process(AlertListener.java:496) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at github.scarsz.discordsrv.modules.alerts.AlertListener.lambda$runAlertsForEvent$2(AlertListener.java:262) ~[DiscordSRV-Build-1.26.0-SNAPSHOT-d85927b.jar:?]
            at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftTask.run(CraftTask.java:101) ~[purpur-1.19.1.jar:git-Purpur-1748]
            at org.bukkit.craftbukkit.v1_19_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[purpur-1.19.1.jar:git-Purpur-1748]
            at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[purpur-1.19.1.jar:?]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
            at java.lang.Thread.run(Thread.java:833) ~[?:?]
    Caused by: java.lang.ClassNotFoundException: org.bukkit.Achievement
            at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:153) ~[purpur-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:105) ~[purpur-api-1.19.1-R0.1-SNAPSHOT.jar:?]
            at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
            ... 31 more
    

Server software and version

git-Purpur-1748 (MC: 1.19.1)

Checks

  • I am not using an outdated version of DiscordSRV.
  • I asked in DiscordSRV's Discord server to see whether this issue is in fact a bug that needs to be fixed.

Anything else

This error appears because SpEL (the expression language we use for alerts) attempts to get all the methods from a class when it's referenced. In this case, EssX's OfflinePlayer class is being referenced and it's trying to resolve the Achievement methods even if it can't be resolved.

@Vankka proposed replacing SpEL's method resolver with ASM's ClassVisitor.