-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
plugin/src/main/kotlin/xyz/jpenilla/resourcefactory/bungee/BungeePluginYml.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package xyz.jpenilla.resourcefactory.bungee | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.SetProperty | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Optional | ||
import org.gradle.kotlin.dsl.newInstance | ||
import org.gradle.kotlin.dsl.property | ||
import org.gradle.kotlin.dsl.setProperty | ||
import org.spongepowered.configurate.objectmapping.ConfigSerializable | ||
import org.spongepowered.configurate.yaml.NodeStyle | ||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader | ||
import xyz.jpenilla.resourcefactory.ConfigurateSingleFileResourceFactory | ||
import xyz.jpenilla.resourcefactory.ResourceFactory | ||
import xyz.jpenilla.resourcefactory.nullIfEmpty | ||
import java.nio.file.Path | ||
|
||
fun Project.bungeePluginYml(op: BungeePluginYml.() -> Unit = {}): BungeePluginYml { | ||
val yml = BungeePluginYml(objects) | ||
yml.copyProjectMeta(this) | ||
yml.op() | ||
return yml | ||
} | ||
|
||
class BungeePluginYml constructor( | ||
@Transient | ||
private val objects: ObjectFactory | ||
) : ConfigurateSingleFileResourceFactory.ObjectMapper.ValueProvider { | ||
|
||
@get:Input | ||
val name: Property<String> = objects.property() | ||
|
||
@get:Input | ||
val main: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val version: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val description: Property<String> = objects.property() | ||
|
||
@get:Input | ||
@get:Optional | ||
val author: Property<String> = objects.property() | ||
|
||
@get:Input | ||
val depends: SetProperty<String> = objects.setProperty() | ||
|
||
@get:Input | ||
val softDepends: SetProperty<String> = objects.setProperty() | ||
|
||
override fun asConfigSerializable(): Any { | ||
return Serializable(this) | ||
} | ||
|
||
fun copyProjectMeta(project: Project) { | ||
name.convention(project.name) | ||
description.convention(project.description) | ||
version.convention(project.version as String?) | ||
} | ||
|
||
fun resourceFactory(): ResourceFactory { | ||
val factory = objects.newInstance( | ||
ConfigurateSingleFileResourceFactory.ObjectMapper::class, | ||
{ path: Path -> | ||
YamlConfigurationLoader.builder() | ||
.path(path) | ||
.nodeStyle(NodeStyle.BLOCK) | ||
.build() | ||
} | ||
) | ||
factory.path.set("bungee.yml") | ||
factory.value.set(this) | ||
return factory | ||
} | ||
|
||
@ConfigSerializable | ||
class Serializable(yml: BungeePluginYml) { | ||
val name = yml.name.get() | ||
val main = yml.main.get() | ||
val version = yml.version.orNull | ||
val author = yml.author.orNull | ||
val depends = yml.depends.nullIfEmpty() | ||
val softDepends = yml.softDepends.nullIfEmpty() | ||
val description = yml.description.orNull | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,5 +35,8 @@ sourceSets.main { | |
icon("icon.png") | ||
depends("some_other_mod", "*") | ||
} | ||
bungeePluginYml { | ||
main = "test" | ||
} | ||
} | ||
} |