Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Support for PlaceholderAPI Expansions #710

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
3 changes: 3 additions & 0 deletions src/main/kotlin/com/demonwav/mcdev/asset/PlatformAssets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ object PlatformAssets : Assets() {
val MCP_ICON_2X = loadIcon("/assets/icons/platform/[email protected]")
val MCP_ICON_DARK = loadIcon("/assets/icons/platform/MCP_dark.png")
val MCP_ICON_2X_DARK = loadIcon("/assets/icons/platform/MCP@2x_dark.png")

val PLACEHOLDERAPI_ICON = loadIcon("/assets/icons/platform/[email protected]")
val PLACEHOLDERAPI_ICON_2X = loadIcon("/assets/icons/platform/[email protected]")
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MavenBuildSystem(
directories = createDirectories(rootDirectory)

val text = when (configuration.type) {
PlatformType.BUKKIT, PlatformType.SPIGOT, PlatformType.PAPER ->
PlatformType.BUKKIT, PlatformType.SPIGOT, PlatformType.PAPER, PlatformType.PLACEHOLDERAPI ->
BukkitTemplate.applyPomTemplate(project)
PlatformType.BUNGEECORD, PlatformType.WATERFALL ->
BungeeCordTemplate.applyPomTemplate(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class MinecraftModuleBuilder : JavaModuleBuilder() {
SpongeProjectSettingsWizard(creator),
ForgeProjectSettingsWizard(creator),
LiteLoaderProjectSettingsWizard(creator),
BungeeCordProjectSettingsWizard(creator)
BungeeCordProjectSettingsWizard(creator),
PlaceholderApiProjectSettingsWizard(creator)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.demonwav.mcdev.creator.PlaceholderApiProjectSettingsWizard">
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="545" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="a6cf1" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="10" vgap="10">
<margin top="5" left="10" bottom="10" right="10"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none" title-justification="1" title-position="3"/>
<children>
<component id="778f7" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Required Settings"/>
</properties>
</component>
<component id="d2a96" class="javax.swing.JSeparator">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<maximum-size width="-1" height="5"/>
</grid>
</constraints>
<properties/>
</component>
<grid id="c1d37" layout-manager="GridLayoutManager" row-count="3" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="5" vgap="5">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="e7052" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Expansion Name"/>
</properties>
</component>
<component id="5b8d8" class="javax.swing.JTextField" binding="expansionNameField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="5875e" class="javax.swing.JTextField" binding="expansionVersionField">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="75b6c" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Class Name"/>
</properties>
</component>
<component id="c76d2" class="javax.swing.JTextField" binding="mainClassField">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="true"/>
</properties>
</component>
<component id="d3cfe" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Expansion Version"/>
</properties>
</component>
<grid id="ab82c" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="c5948" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="17"/>
</grid>
</constraints>
<properties>
<horizontalAlignment value="4"/>
<horizontalTextPosition value="4"/>
<text value=""/>
</properties>
</component>
<hspacer id="65705">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="2aeb8" class="javax.swing.JComboBox" binding="minecraftVersionBox">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<model/>
</properties>
</component>
<component id="a8a36" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="17"/>
</grid>
</constraints>
<properties>
<horizontalAlignment value="4"/>
<horizontalTextPosition value="4"/>
<text value=" Minecraft Version"/>
</properties>
</component>
</children>
</grid>
<component id="add4c" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Author Name"/>
</properties>
</component>
<component id="11667" class="javax.swing.JTextField" binding="expansionAuthorField">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
<component id="f1d01" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="assets/icons/platform/[email protected]"/>
<text value="&lt;html&gt;&lt;font size=&quot;5&quot;&gt;PlaceholderAPI Settings&lt;/font&gt;&lt;/html&gt;"/>
</properties>
</component>
</children>
</grid>
<component id="503f2" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Optional Settings"/>
</properties>
</component>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,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() {}
}
Loading