-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathPlaceholderApiProjectSettingsWizard.kt
More file actions
91 lines (74 loc) · 2.84 KB
/
PlaceholderApiProjectSettingsWizard.kt
File metadata and controls
91 lines (74 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2020 minecraft-dev
*
* MIT License
*/
@file:Suppress("Duplicates")
package com.demonwav.mcdev.creator
import com.demonwav.mcdev.platform.ProjectConfiguration
import com.demonwav.mcdev.platform.placeholderapi.PlaceholderApiProjectConfiguration
import com.demonwav.mcdev.util.firstOfType
import javax.swing.JComboBox
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JTextField
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.swing.Swing
import kotlinx.coroutines.withContext
import org.apache.commons.lang.WordUtils
class PlaceholderApiProjectSettingsWizard(private val creator: MinecraftProjectCreator) : MinecraftModuleWizardStep() {
private lateinit var panel: JPanel
private lateinit var expansionNameField: JTextField
private lateinit var expansionVersionField: JTextField
private lateinit var mainClassField: JTextField
private lateinit var expansionAuthorField: JTextField
private lateinit var minecraftVersionBox: JComboBox<String>
private var config: PlaceholderApiProjectConfiguration? = null
override fun getComponent(): JComponent {
return panel
}
override fun updateStep() {
config = creator.configs.firstOfType()
if (config == null) {
return
}
val buildSystem = creator.buildSystem ?: return
val name = WordUtils.capitalize(buildSystem.artifactId.replace('-', ' '))
expansionNameField.text = name
expansionVersionField.text = buildSystem.version
val conf = config ?: return
if (creator.configs.indexOf(conf) != 0) {
expansionNameField.isEditable = false
expansionVersionField.isEditable = false
}
mainClassField.text = buildSystem.groupId.replace("-", "").toLowerCase() + "." +
buildSystem.artifactId.replace("-", "").toLowerCase() + "." + name.replace(" ", "")
CoroutineScope(Dispatchers.Swing).launch {
try {
withContext(Dispatchers.IO) { getVersionSelector(conf.type) }.set(minecraftVersionBox)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
override fun onStepLeaving() {
val conf = config ?: return
conf.base = ProjectConfiguration.BaseConfigs(
expansionNameField.text,
expansionVersionField.text,
mainClassField.text
)
conf.setAuthors(this.expansionAuthorField.text)
conf.mcVersion = minecraftVersionBox.selectedItem as? String ?: ""
}
override fun isStepVisible(): Boolean {
return creator.configs.any { it is PlaceholderApiProjectConfiguration }
}
override fun updateDataModel() {}
}