Use git username for devenv username
This commit is contained in:
parent
293d677a84
commit
c240f9cc1a
@ -4,6 +4,7 @@ import java.util.Date
|
|||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
||||||
import kotlin.text.Regex
|
import kotlin.text.Regex
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
val mod_version: String by project
|
val mod_version: String by project
|
||||||
val mc_version: String by project
|
val mc_version: String by project
|
||||||
@ -211,6 +212,36 @@ minecraft {
|
|||||||
source(sourceSets["main"])
|
source(sourceSets["main"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val usernameStream = FastByteArrayOutputStream()
|
||||||
|
|
||||||
|
val gotUsername = exec {
|
||||||
|
commandLine("git", "config", "--global", "--get", "user.name")
|
||||||
|
workingDir(".")
|
||||||
|
standardOutput = usernameStream
|
||||||
|
}.exitValue == 0
|
||||||
|
|
||||||
|
if (gotUsername) {
|
||||||
|
val originalUsername = usernameStream.array.copyOfRange(0, usernameStream.length).toString(Charsets.UTF_8).trim()
|
||||||
|
|
||||||
|
if (originalUsername.isNotEmpty()) {
|
||||||
|
var username = originalUsername
|
||||||
|
var speculatedUUID = UUID.nameUUIDFromBytes("OfflinePlayer:$username".toByteArray(Charsets.UTF_8))
|
||||||
|
var counter = 1
|
||||||
|
|
||||||
|
while (speculatedUUID.hashCode() and 1 == 1) {
|
||||||
|
username = originalUsername + "_".repeat(counter)
|
||||||
|
speculatedUUID = UUID.nameUUIDFromBytes("OfflinePlayer:$username".toByteArray(Charsets.UTF_8))
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
|
||||||
|
args("--username", username)
|
||||||
|
} else {
|
||||||
|
args("--username", "Dev_${System.getProperty("user.name")}")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
args("--username", "Dev_${System.getProperty("user.name")}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
create("server") {
|
create("server") {
|
||||||
|
Loading…
Reference in New Issue
Block a user