2021-04-05 23:05:58 +00:00
|
|
|
import org.bukkit.configuration.file.YamlConfiguration
|
|
|
|
|
2021-04-05 22:35:59 +00:00
|
|
|
import java.util.regex.Pattern
|
2021-04-05 00:45:28 +00:00
|
|
|
import scala.io.Source
|
|
|
|
import scala.util.Using
|
|
|
|
|
2021-04-03 22:32:27 +00:00
|
|
|
name := "Chroma-Discord"
|
|
|
|
|
2021-04-05 00:45:28 +00:00
|
|
|
version := "1.1"
|
2021-04-03 22:32:27 +00:00
|
|
|
|
|
|
|
scalaVersion := "2.13.5"
|
|
|
|
|
|
|
|
resolvers += "spigot-repo" at "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
|
|
|
|
resolvers += "jitpack.io" at "https://jitpack.io"
|
|
|
|
resolvers += Resolver.mavenLocal
|
|
|
|
|
|
|
|
libraryDependencies ++= Seq(
|
|
|
|
"org.spigotmc" % "spigot-api" % "1.12.2-R0.1-SNAPSHOT" % Provided,
|
|
|
|
"org.spigotmc" % "spigot" % "1.12.2-R0.1-SNAPSHOT" % Provided,
|
|
|
|
"org.spigotmc." % "spigot" % "1.14.4-R0.1-SNAPSHOT" % Provided,
|
|
|
|
"com.destroystokyo.paper" % "paper" % "1.16.3-R0.1-SNAPSHOT" % Provided,
|
|
|
|
|
|
|
|
"com.discord4j" % "discord4j-core" % "3.1.4",
|
|
|
|
"org.slf4j" % "slf4j-jdk14" % "1.7.21",
|
|
|
|
"com.vdurmont" % "emoji-java" % "4.0.0",
|
|
|
|
"org.mockito" % "mockito-core" % "3.5.13",
|
|
|
|
"io.projectreactor" %% "reactor-scala-extensions" % "0.7.0",
|
|
|
|
|
|
|
|
"com.github.TBMCPlugins.ChromaCore" % "Chroma-Core" % "v1.0.0" % Provided,
|
|
|
|
"net.ess3" % "EssentialsX" % "2.17.1" % Provided,
|
|
|
|
"com.github.lucko.LuckPerms" % "bukkit" % "master-SNAPSHOT" % Provided,
|
|
|
|
)
|
|
|
|
|
|
|
|
assemblyJarName in assembly := "Chroma-Discord.jar"
|
|
|
|
assemblyShadeRules in assembly := Seq(
|
|
|
|
"io.netty", "com.fasterxml", "org.mockito", "org.slf4j"
|
|
|
|
).map { p =>
|
|
|
|
ShadeRule.rename(s"$p.**" -> "btndvtm.dp.@0").inAll
|
|
|
|
}
|
|
|
|
|
|
|
|
assemblyMergeStrategy in assembly := {
|
|
|
|
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
|
|
|
|
// https://stackoverflow.com/a/55557287/457612
|
|
|
|
case "module-info.class" => MergeStrategy.discard
|
|
|
|
case x => (assemblyMergeStrategy in assembly).value(x)
|
|
|
|
}
|
|
|
|
|
2021-04-06 00:25:23 +00:00
|
|
|
val saveConfigComments = TaskKey[Seq[File]]("saveConfigComments")
|
|
|
|
saveConfigComments := {
|
2021-04-05 00:45:28 +00:00
|
|
|
val sv = (Compile / sources).value
|
2021-04-06 00:25:23 +00:00
|
|
|
val cdataRegex = Pattern.compile("(?:def|val|var) (\\w+)(?::[^=]+)? = (?:(?:get(?:I)?Config)|(?:DPUtils.\\w+Data))") //Hack: DPUtils
|
2021-04-05 22:35:59 +00:00
|
|
|
val clRegex = Pattern.compile("class (\\w+) extends (\\w+)")
|
2021-04-06 00:25:23 +00:00
|
|
|
val objRegex = Pattern.compile("object (\\w+)")
|
2021-04-05 23:05:58 +00:00
|
|
|
val config = new YamlConfiguration()
|
2021-04-05 00:45:28 +00:00
|
|
|
for (file <- sv) {
|
|
|
|
Using(Source.fromFile(file)) { src =>
|
2021-04-05 23:05:58 +00:00
|
|
|
var clKey: String = null
|
2021-04-05 22:35:59 +00:00
|
|
|
var comment: String = null
|
|
|
|
var justCommented: Boolean = false
|
2021-04-05 00:45:28 +00:00
|
|
|
for (line <- src.getLines) {
|
2021-04-05 22:35:59 +00:00
|
|
|
val clMatcher = clRegex.matcher(line)
|
2021-04-06 00:25:23 +00:00
|
|
|
if (clKey == null && clMatcher.find()) { //First occurrence
|
2021-04-05 23:05:58 +00:00
|
|
|
clKey = if (clMatcher.group(2).contains("Component"))
|
2021-04-06 00:25:23 +00:00
|
|
|
"components." + clMatcher.group(1)
|
2021-04-05 23:05:58 +00:00
|
|
|
else
|
|
|
|
"global"
|
2021-04-06 00:25:23 +00:00
|
|
|
/*println("Class: "+clKey)
|
|
|
|
println("Comment: "+comment)
|
|
|
|
println("Just commented: "+justCommented)
|
|
|
|
if (comment != null) { //Not checking justCommented because the object may have the comment and not extend anything
|
|
|
|
config.set(s"$clKey.generalDescriptionInsteadOfAConfig", comment.trim)
|
|
|
|
justCommented = false
|
|
|
|
comment = null
|
|
|
|
println("Found class comment for " + clKey)
|
|
|
|
}*/
|
|
|
|
} else if (line.contains("/**")) {
|
2021-04-05 22:35:59 +00:00
|
|
|
comment = ""
|
|
|
|
justCommented = false
|
2021-04-05 23:05:58 +00:00
|
|
|
} else if (line.contains("*/") && comment != null)
|
2021-04-05 22:35:59 +00:00
|
|
|
justCommented = true
|
2021-04-05 23:05:58 +00:00
|
|
|
else if (comment != null) {
|
2021-04-05 22:35:59 +00:00
|
|
|
if (justCommented) {
|
2021-04-06 00:25:23 +00:00
|
|
|
if (clKey != null) {
|
|
|
|
val matcher = cdataRegex.matcher(line)
|
|
|
|
if (matcher.find())
|
|
|
|
config.set(s"$clKey.${matcher.group(1)}", comment.trim)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
val matcher = objRegex.matcher(line)
|
|
|
|
if (matcher.find())
|
|
|
|
config.set(s"${matcher.group(1)}.generalDescriptionInsteadOfAConfig", comment.trim)
|
|
|
|
}
|
2021-04-05 22:35:59 +00:00
|
|
|
justCommented = false
|
|
|
|
comment = null
|
|
|
|
}
|
2021-04-05 23:05:58 +00:00
|
|
|
else comment += line.replaceFirst("^\\s*\\*\\s+", "") + "\n"
|
2021-04-05 22:35:59 +00:00
|
|
|
}
|
2021-04-05 00:45:28 +00:00
|
|
|
}
|
2021-04-06 00:25:23 +00:00
|
|
|
config.save("target/configHelp.yml")
|
2021-04-05 00:45:28 +00:00
|
|
|
}.recover[Unit]({ case t => t.printStackTrace() })
|
|
|
|
}
|
2021-04-06 00:25:23 +00:00
|
|
|
Seq(file("target/configHelp.yml"))
|
2021-04-05 00:45:28 +00:00
|
|
|
}
|
2021-04-06 00:25:23 +00:00
|
|
|
|
|
|
|
resourceGenerators in Compile += saveConfigComments
|