-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
161 lines (148 loc) · 6.6 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
161 lines (148 loc) · 6.6 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import com.google.gson.Gson
import com.google.gson.JsonObject
import org.apache.log4j.LogManager
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import javax.net.ssl.HttpsURLConnection
// Inspired by https://gitlab.com/supersaiyansubtlety-group/minecraft-mods/sss_mod_gradle/-/blob/18a6c4c0fa75603fe7ba0e508439a55381ead45e/plugin/src/main/java/net/sssubtlety/sss_mod_gradle/plugin/RunConfigHelperPlugin.java
val mixinJavaagentArgFile = file(".gradle/mixin-javaagent-arg.txt")
plugins {
id("net.fabricmc.fabric-loom") version System.getProperty("loom_version")
id("java")
kotlin("jvm").version(System.getProperty("kotlin_version"))
}
base { archivesName.set(project.extra["archives_base_name"] as String) }
version = project.extra["mod_version"] as String
group = project.extra["maven_group"] as String
repositories {
maven("https://jitpack.io")
maven {
name = "Terraformers"
setUrl("https://maven.terraformersmc.com/")
}
}
dependencies {
minecraft("com.mojang", "minecraft", project.extra["minecraft_version"] as String)
implementation("net.fabricmc", "fabric-loader", project.extra["loader_version"] as String)
implementation("net.fabricmc.fabric-api", "fabric-api", project.extra["fabric_version"] as String)
implementation("net.fabricmc", "fabric-language-kotlin", project.extra["fabric_language_kotlin_version"] as String)
compileOnly("com.terraformersmc:modmenu:${project.extra["modmenu_version"]}")
api("org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0")
include("org.eclipse.lsp4j:org.eclipse.lsp4j:0.24.0")
include("org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.24.0")
include("org.eclipse.xtext:org.eclipse.xtext.xbase.lib:2.40.0")
api("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.24.0")
include("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:0.24.0")
include("org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc.debug:0.24.0")
// Only use within PartialIdGeneratorServiceImpl or other services with the purpose of interacting with PartialIdAutocomplete
compileOnly("com.github.Papierkorb2292:PartialIdAutocomplete:1.2.0") {
exclude("com.terraformersmc", "modmenu")
}
// Only for tests in dev environment
implementation("io.github.java-diff-utils:java-diff-utils:4.12")
implementation("com.fasterxml.jackson.core:jackson-core:2.20.0")
implementation("com.fasterxml.jackson.core:jackson-annotations:2.20")
implementation("com.fasterxml.jackson.core:jackson-databind:2.20.0")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.20.0")
}
loom {
accessWidenerPath.fileValue(file("src/main/resources/command_crafter.accesswidener"))
splitEnvironmentSourceSets()
mods {
create("commandcrafter") {
sourceSet("main")
sourceSet("client")
}
}
runs {
create("gametest") {
server()
ideConfigGenerated(true)
source(sourceSets["main"])
name("Game Test")
vmArg("-Dfabric-api.gametest")
vmArg("-Dfabric-api.gametest.report-file=${project.layout.buildDirectory}/junit.xml")
runDir("build/gametest")
}
getByName("client") {
vmArg("@$mixinJavaagentArgFile")
val devUsername = project.extra["dev_username"] as String
programArg("--username=$devUsername")
val uuid = fetchPlayerUUID(devUsername)
if(uuid != null)
programArg("--uuid=$uuid")
}
getByName("server") {
vmArg("@$mixinJavaagentArgFile")
}
}
}
tasks {
val javaVersion = JavaVersion.toVersion((project.extra["java_version"] as String).toInt())
withType<JavaCompile> {
options.encoding = "UTF-8"
sourceCompatibility = javaVersion.toString()
targetCompatibility = javaVersion.toString()
options.release.set(javaVersion.toString().toInt())
}
withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(javaVersion.toString()))
}
}
jar { from("LICENSE") { rename { "${it}_${base.archivesName.get()}" } } }
jar { from("README.md") }
jar { from("GSON_LICENSE") }
jar { from("LSP4J_LICENSE") }
processResources {
filesMatching("fabric.mod.json") {
expand("version" to project.extra["mod_version"] as String)
}
}
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(javaVersion.toString())) }
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
withSourcesJar()
}
val createMixinJavaArgFileTask = register("createMixinJavaAgentArgFile") {
val compileClasspathFiles = files(configurations.named("compileClasspath"))
val mixinLibraryFile = compileClasspathFiles.filter { file ->
file.toString().contains("sponge-mixin")
}.singleFile
Files.write(Path.of(mixinJavaagentArgFile.absolutePath), listOf("-javaagent:${mixinLibraryFile.absolutePath}"))
}
getByName("ideaSyncTask").dependsOn(createMixinJavaArgFileTask)
getByName("processResources").dependsOn(createMixinJavaArgFileTask)
}
fun fetchPlayerUUID(playerName: String): UUID? {
val logger = LogManager.getLogger("PlayerFetcher")
try {
val url = URI("https://api.mojang.com/users/profiles/minecraft/$playerName").toURL()
val con = url.openConnection() as HttpsURLConnection
con.requestMethod = "GET"
val statusCode = con.responseCode
if(statusCode != 200) {
logger.error("Received unexpected status code when fetching UUID for player $playerName: $statusCode")
return null
}
val responseJson = Gson().fromJson(con.inputStream.reader(), JsonObject::class.java)
if(responseJson.has("errorMessage")) {
logger.error("Received unexpected error when fetching UUID for player $playerName: ${responseJson.get("errorMessage").asString}")
return null
}
val uuidStringWithoutDashes = responseJson.get("id").asString
val mostSignificant =
uuidStringWithoutDashes.substring(0, uuidStringWithoutDashes.length / 2).toULong(16).toLong()
val leastSignificant =
uuidStringWithoutDashes.substring(uuidStringWithoutDashes.length / 2).toULong(16).toLong()
return UUID(mostSignificant, leastSignificant)
} catch(e: Exception) {
logger.error("Encountered unexpected error when fetching UUID for player $playerName", e)
return null
}
}