monun / kommand

GNU General Public License v3.0
96 stars 22 forks source link

java.lang.ClassCastException 예외 #47

Open dev-alphagot opened 1 year ago

dev-alphagot commented 1 year ago

서버 버전: Purpur 1.20.1 Kommand 버전 3.1.6

[14:07:46 ERROR]: Error occurred while enabling icbs v0.1.0-SNAPSHOT (Is it up to date?)
java.lang.ExceptionInInitializerError: null
        at io.github.monun.kommand.Kommand.<clinit>(Kommand.kt) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.monun.kommand.PluginKommand.register(Kommand.kt:48) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.monun.kommand.PluginKommand.invoke(Kommand.kt:53) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.devalphagot.icbs.kommands.GiftCommand$kommand$1.invoke(GiftCommand.kt:20) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.devalphagot.icbs.kommands.GiftCommand$kommand$1.invoke(GiftCommand.kt:19) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.monun.kommand.KommandKt.kommand(Kommand.kt:59) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.devalphagot.icbs.kommands.GiftCommand.kommand(GiftCommand.kt:19) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.devalphagot.icbs.Main.onEnable(Main.kt:55) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:281) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:189) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:104) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:507) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugin(CraftServer.java:653) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at org.bukkit.craftbukkit.v1_20_R1.CraftServer.enablePlugins(CraftServer.java:564) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at org.bukkit.craftbukkit.v1_20_R1.CraftServer.reload(CraftServer.java:1133) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at org.bukkit.Bukkit.reload(Bukkit.java:951) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:54) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168) ~[purpur-api-1.20.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchCommand(CraftServer.java:1020) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at org.bukkit.craftbukkit.v1_20_R1.CraftServer.dispatchServerCommand(CraftServer.java:983) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at net.minecraft.server.dedicated.DedicatedServer.handleConsoleInputs(DedicatedServer.java:541) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at net.minecraft.server.dedicated.DedicatedServer.tickChildren(DedicatedServer.java:488) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1421) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1192) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:323) ~[purpur-1.20.1.jar:git-Purpur-2016]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: java.lang.ClassCastException: class io.github.monun.kommand.v1_20_1.NMSKommand
        at java.lang.Class.asSubclass(Class.java:3924) ~[?:?]
        at io.github.monun.kommand.loader.LibraryLoader.loadNMS(LibraryLoader.kt:74) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.monun.kommand.loader.LibraryLoader.loadNMS$default(LibraryLoader.kt:54) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.monun.kommand.Kommand$Companion.<init>(Kommand.kt:27) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        at io.github.monun.kommand.Kommand$Companion.<clinit>(Kommand.kt) ~[iowa-class-battleship-0.1.0-SNAPSHOT-offline.jar:?]
        ... 26 more

플러그인 켜질 때 저 오류가 나오는데 원인이 뭔가요?

yoonseo6399 commented 1 year ago

저도 똑같은 오류가 나네요..

monun commented 1 year ago

Paper 이외의 서버에선 동작을 확신 할 수 없습니다 Paper로 시도 해 보시고 이슈 작성시 코드도 함께 올려주세요

yoonseo6399 commented 1 year ago

저같은경우 paper 1.19.2-R0.1 버전으로 실행했고 `

class PetCommand(plugin : Pet) {
    init {
        plugin.kommand {
            register("pet"){
                then("kill"){
                    then("userName" to string()){
                        executes {context ->
                            val userName : String by context
                            if(userName == "all") PetEntity.list.forEach(PetEntity::kill)
                            else                  PetEntity.list.filter { it.owner.displayName == userName }.forEach(PetEntity::kill)
                        }
                    }
                }
                then("spawn"){
                    then("playerName" to player()){
                        then("petType" to dynamicByEnum(EnumSet.allOf(PetType::class.java))){
                            then("petName" to string()){
                                executes { context ->
                                    val playerName : Player by context
                                    val petType : PetType by context
                                    val petName : String by context
                                    PetEntity(playerName,petType,petName)
                                    player.sendMessage("Pet spawn complete")
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Register 부분의 loadNMS부분에서 오류가 나더라구요

실행 코드입니다 loadNMS 코드를 복붙해서 문제가 뭔가 보니 classLoader가 Class.forName으로 로드한 클레스은 URLClassLoader고 매개변수인 type은 PluginClassLoader로 달랐습니다

왜이런걸까요...?

monun commented 1 year ago

제 프로젝트에선 정확한 확인이 어렵습니다 저장소 공유해주시면 복제해서 확인해보겠습니다

zlfn commented 1 year ago

@dev-alphagot @yoonseo6399 오류 재현을 해봤는데, 라이브러리를 shadowJar로 참조할 경우 동일한 에러가 발생함을 확인하였습니다. shadowJar 대신 plugin.yml에 libraries를 추가하는 방식으로 바꿔보세요.

jung27 commented 1 year ago

저 같은 경우에는 libraries에 추가하는 방식으로 라이브러리가 다운로드 된 것을 확인했음에도 위와 같은 에러가 출력되었습니다.