Skip to content

Commit d83d2c3

Browse files
kashikeDenWav
authored andcommitted
forge: Suggest the correct annotation to subscribe to an event when the wrong one is used (#265)
1 parent 39512c8 commit d83d2c3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main/kotlin/com/demonwav/mcdev/platform/forge/ForgeModule.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,20 @@ class ForgeModule internal constructor(facet: MinecraftFacet) : AbstractModule(f
6969
val annotation = method.modifierList.findAnnotation(ForgeConstants.EVENT_HANDLER_ANNOTATION)
7070

7171
if (annotation != null) {
72-
return "Parameter is not a subclass of net.minecraftforge.fml.common.event.FMLEvent\n" +
73-
"Compiling and running this listener may result in a runtime exception"
72+
return formatWrongEventMessage(ForgeConstants.FML_EVENT, ForgeConstants.SUBSCRIBE_EVENT_ANNOTATION,
73+
ForgeConstants.EVENT == eventClass.qualifiedName)
7474
}
7575

76-
return "Parameter is not a subclass of net.minecraftforge.fml.common.eventhandler.Event\n" +
77-
"Compiling and running this listener may result in a runtime exception"
76+
return formatWrongEventMessage(ForgeConstants.EVENT, ForgeConstants.EVENT_HANDLER_ANNOTATION,
77+
ForgeConstants.FML_EVENT == eventClass.qualifiedName)
78+
}
79+
80+
private fun formatWrongEventMessage(expected: String, suggested: String, wrong: Boolean): String {
81+
val base = "Parameter is not a subclass of $expected\n"
82+
if (wrong) {
83+
return base + "This method should be annotated with $suggested"
84+
}
85+
return base + "Compiling and running this listener may result in a runtime exception"
7886
}
7987

8088
override fun isStaticListenerSupported(method: PsiMethod) = true

0 commit comments

Comments
 (0)