Skip to content

Commit 4d9f523

Browse files
Configure task to replace server.properties and not update it
1 parent 24c860b commit 4d9f523

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

build.gradle.kts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import xyz.jpenilla.resourcefactory.bukkit.BukkitPluginYaml
22

3+
import java.nio.file.Files
4+
import java.nio.file.StandardCopyOption
5+
36
plugins {
47
java
58
`java-library`
@@ -94,3 +97,32 @@ publishing {
9497
tasks.named("publishMavenJavaPublicationToMavenLocal") {
9598
dependsOn(tasks.named("build"))
9699
}
100+
101+
val serverPropertiesFile = layout.projectDirectory.file("run/server.properties")
102+
val backupPropertiesFile = layout.buildDirectory.file("server.properties.backup")
103+
104+
tasks.register("backupServerProperties") {
105+
doLast {
106+
val source = serverPropertiesFile.asFile
107+
val destination = backupPropertiesFile.get().asFile
108+
if (source.exists()) {
109+
Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)
110+
println("Backed up server.properties to build directory.")
111+
}
112+
}
113+
}
114+
115+
tasks.register("restoreServerProperties") {
116+
doLast {
117+
val source = backupPropertiesFile.get().asFile
118+
val destination = serverPropertiesFile.asFile
119+
if (source.exists()) {
120+
Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)
121+
}
122+
}
123+
}
124+
125+
tasks.named("runServer") {
126+
dependsOn("backupServerProperties")
127+
finalizedBy("restoreServerProperties")
128+
}

0 commit comments

Comments
 (0)