@@ -12,6 +12,7 @@ package com.demonwav.mcdev.creator
1212
1313import com.demonwav.mcdev.exception.BadListSetupException
1414import com.demonwav.mcdev.exception.EmptyInputSetupException
15+ import com.demonwav.mcdev.exception.InvalidMainClassNameException
1516import com.demonwav.mcdev.exception.SetupException
1617import com.intellij.ide.util.projectWizard.ModuleWizardStep
1718import com.intellij.openapi.ui.MessageType
@@ -37,9 +38,26 @@ abstract class MinecraftModuleWizardStep : ModuleWizardStep() {
3738 throw EmptyInputSetupException (pluginVersionField)
3839 }
3940
40- if (mainClassField.text.trim { it <= ' ' }.isEmpty()) {
41+ if (mainClassField.text.trim { it <= ' ' }.isEmpty()) { // empty
4142 throw EmptyInputSetupException (mainClassField)
4243 }
44+ if (! mainClassField.text.contains(' .' )) { // default package
45+ throw InvalidMainClassNameException (mainClassField)
46+ }
47+ if (mainClassField.text.contains(" \\ s+" .toRegex())) { // whitespace
48+ throw InvalidMainClassNameException (mainClassField)
49+ }
50+ if (mainClassField.text.first().isJavaIdentifierStart() && // invalid character
51+ mainClassField.text.asSequence().drop(1 ).all { it.isJavaIdentifierPart() }) {
52+ throw InvalidMainClassNameException (mainClassField)
53+ }
54+ if (mainClassField.text.first() == ' .' ) { // idk why this doesn't fail in the above check, but w/e
55+ throw InvalidMainClassNameException (mainClassField)
56+ }
57+ if (mainClassField.text.split(' .' ).any { keywords.contains(it) }) { // keyword identifier
58+ throw InvalidMainClassNameException (mainClassField)
59+ }
60+
4361 if (! authorsField.text.matches(pattern)) {
4462 throw BadListSetupException (authorsField)
4563 }
@@ -60,5 +78,11 @@ abstract class MinecraftModuleWizardStep : ModuleWizardStep() {
6078
6179 companion object {
6280 val pattern = " (\\ s*(\\ w+)\\ s*(,\\ s*\\ w+\\ s*)*,?|\\ [?\\ s*(\\ w+)\\ s*(,\\ s*\\ w+\\ s*)*])?" .toRegex()
81+ val keywords = setOf (
82+ " abstract" , " continue" , " for" , " new" , " switch" , " assert" , " default" , " goto" , " package" , " synchronized" , " boolean" , " do" , " if" ,
83+ " private" , " this" , " break" , " double" , " implements" , " protected" , " throw" , " byte" , " else" , " import" , " public" , " throws" , " case" ,
84+ " enum" , " instanceof" , " return" , " transient" , " catch" , " extends" , " int" , " short" , " try" , " char" , " final" , " interface" , " static" ,
85+ " void" , " class" , " finally" , " long" , " strictfp" , " volatile" , " const" , " float" , " native" , " super" , " while"
86+ )
6387 }
6488}
0 commit comments