-
Notifications
You must be signed in to change notification settings - Fork 1
/
setupAuth.gradle
88 lines (79 loc) · 3.07 KB
/
setupAuth.gradle
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
/**
* @author Earthcomputer
* To use your real account in the IDE, do the following:
* - Create a credentials.properties file in the root project directory if it doesn't already exist (it is ignored by the gitignore)
* - Insert minecraftUser=youremail@example.com and minecraftPass=yourminecraftpassword into the credentials file
* - Duplicate the Minecraft Client run configuration in your IDE. Configure it to run the setupAuth gradle task after build but before run
*/
buildscript {
repositories {
mavenCentral()
maven {
url 'https://libraries.minecraft.net/'
}
}
dependencies {
classpath 'com.mojang:authlib:2.1.28'
}
}
import com.google.gson.GsonBuilder
import com.mojang.authlib.Agent
import com.mojang.authlib.properties.PropertyMap
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService
project.ext.credentials = new Properties()
try {
project.ext.credentials.load(new FileReader(file('credentials.properties')))
} catch (IOException ignore) {
}
task setupAuth {
group = 'ide'
doLast {
def username = project.ext.credentials['minecraftUser']
def password = project.ext.credentials['minecraftPass']
def auth = new YggdrasilAuthenticationService(Proxy.NO_PROXY, '1').createUserAuthentication(Agent.MINECRAFT)
auth.username = username
auth.password = password
auth.logIn()
def accessToken = auth.authenticatedToken
def uuid = auth.selectedProfile.id.toString().replace('-', '')
username = auth.selectedProfile.name
def userType = auth.userType.name
def userProperties = new GsonBuilder().registerTypeAdapter(PropertyMap, new PropertyMap.Serializer()).create().toJson(auth.userProperties)
def categories = [:]
def category
minecraft.devLauncherConfig.eachLine { line ->
if (!line.empty && Character.isWhitespace(line.charAt(0))) {
category << line.trim()
} else {
category = []
categories[line] = category
}
}
def clientArgs = categories['clientArgs']
for (def i = 0; i < clientArgs.size(); i += 2) {
if (clientArgs[i] == '--accessToken' || clientArgs[i] == '--uuid' || clientArgs[i] == '--username' || clientArgs[i] == '--userType' || clientArgs[i] == '--userProperties') {
clientArgs.remove(i)
clientArgs.remove(i)
i -= 2
}
}
clientArgs << '--accessToken'
clientArgs << accessToken
clientArgs << '--uuid'
clientArgs << uuid
clientArgs << '--username'
clientArgs << username
clientArgs << '--userType'
clientArgs << userType
clientArgs << '--userProperties'
clientArgs << userProperties
def pw = minecraft.devLauncherConfig.newPrintWriter()
for (def ctgy : categories.keySet()) {
pw.println ctgy
for (def val : categories[ctgy]) {
pw.println('\t' + val)
}
}
pw.flush()
}
}