-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.gradle
390 lines (315 loc) · 11.2 KB
/
config.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
// Main configuration file, shared across projects
// After these two comments, the first 10 lines should not contain code, they must be compatible with bash (ext. is stripped)
ext.minecraft="1.16.5"
ext.versionType="release"
ext.minmixin="0.7.10"
ext.mixinversion="0.8.3-SNAPSHOT"
ext.timeStartDev="2021-02-07T16:41:37+01:00"
ext.cyanversion="1.0.0.A15"
ext.forgeurltemplate="https://maven.minecraftforge.net/net/minecraftforge/forge/%game%-%forgeversion%/forge-%game%-%forgeversion%-installer.jar"
ext.timeRelease=OffsetDateTime.now().withNano(0).toString()
ext.modloader=""
ext.modkit="1.3"
buildscript {
repositories {
jcenter()
mavenCentral()
maven { name = "AerialWorks"; url = "https://aerialworks.ddns.net/maven" }
}
dependencies {
classpath group: 'com.google.code.gson', name: 'gson', version: '2.8.7'
classpath group: 'org.asf.cyan', name: 'CCFG', version: '1.0.0.A16'
classpath group: 'org.asf.aos.util.service', name: 'aosutil-service-SLIB-UTIL', version: '0.0.0.13'
}
}
import com.google.gson.JsonParser
import com.google.gson.JsonArray
public class Version {
private ArrayList<VersionSegment> segments = new ArrayList<VersionSegment>();
protected static class VersionSegment {
public String data = null;
public int value = -1;
public int separator = -1;
public boolean hasSeparator = false;
@Override
public String toString() {
return data + (separator != -1 ? (char) separator : "");
}
}
protected Version() {
}
/**
* Parses the given string into a version wrapper instance.
*
* @param version Version String
* @return Version instance.
*/
public static Version fromString(String version) {
Version ver = new Version();
return ver.parse(version);
}
private Version parse(String version) {
segments.clear();
boolean lastWasAlpha = false;
boolean first = true;
VersionSegment last = new VersionSegment();
segments.add(last);
for (char chr : version.toCharArray()) {
int ch = chr
if (!first) {
if (last.data != null) {
if ((Character.isAlphabetic(ch) && !lastWasAlpha) || (Character.isDigit(ch) && lastWasAlpha)) {
if (last.data.matches('^[0-9]+$'))
last.value = Integer.valueOf(last.data);
last.hasSeparator = true;
if (last.value == -1 && last.data != null && last.data.length() > 0
&& Character.isAlphabetic(last.data.charAt(0)))
last.value = last.data.charAt(0);
last = new VersionSegment();
segments.add(last);
}
}
}
if (!Character.isDigit(ch) && !Character.isAlphabetic(ch)) {
if (first) {
continue;
}
if (last.data != null) {
if (last.data.matches('^[0-9]+$'))
last.value = Integer.valueOf(last.data);
last.separator = ch;
last.hasSeparator = true;
last = new VersionSegment();
segments.add(last);
}
continue;
}
if (Character.isAlphabetic(ch) && lastWasAlpha) {
if (last.value == -1)
last.value = last.data.charAt(0);
last.data += ch;
continue;
}
if (last.data == null) {
last.data = "";
}
last.data += ch;
lastWasAlpha = Character.isAlphabetic(ch);
first = false;
}
if (last.data != null && last.data.matches('^[0-9]+$'))
last.value = Integer.valueOf(last.data);
if (last.value == -1 && last.data != null && last.data.length() > 0
&& Character.isAlphabetic(last.data.charAt(0)))
last.value = last.data.charAt(0);
return this;
}
/**
* Compares this version to another
*
* @param other Version to compare to
* @return 1 if greater, 0 if equal and -1 if less.
*/
public int compareTo(Version other) {
if (isEqualTo(other))
return 0;
if (isGreaterThan(other))
return 1;
if (isLessThan(other))
return -1;
return 0;
}
public boolean isEqualTo(Version other) {
if (other.segments.size() != segments.size())
return false;
int i = 0;
for (VersionSegment segment : segments) {
VersionSegment otherSegment = other.segments.get(i);
if (segment.value != otherSegment.value)
return false;
i++;
}
return true;
}
public boolean isGreaterThan(Version other) {
if (isEqualTo(other))
return false;
int i = 0;
boolean lastWasGreater = false;
for (VersionSegment segment : segments) {
if (i >= other.segments.size())
return true;
VersionSegment otherSegment = other.segments.get(i);
if (isSnapshot(otherSegment) && !isSnapshot(segment))
return true;
else if (!isSnapshot(segment) && isSnapshot(otherSegment))
return false;
if (segment.value < otherSegment.value)
return false;
else if (segment.value != otherSegment.value)
lastWasGreater = true;
i++;
}
if (i < other.segments.size()) {
if (lastWasGreater)
return true;
if (isSnapshot(other.segments.get(i)))
return true;
return false;
}
return true;
}
private boolean isSnapshot(VersionSegment t) {
return t.toString().toLowerCase().contains("snapshot") || t.toString().toLowerCase().contains("beta")
|| t.toString().toLowerCase().contains("alpha") || t.toString().toLowerCase().contains("pre");
}
public boolean isLessThan(Version other) {
if (isEqualTo(other))
return false;
boolean lastWasLess = false;
int i = 0;
for (VersionSegment segment : segments) {
if (i >= other.segments.size()) {
if (isSnapshot(segment) && !other.segments.stream().anyMatch({ t -> isSnapshot(t) })) {
break;
}
return lastWasLess;
}
VersionSegment otherSegment = other.segments.get(i);
if (isSnapshot(otherSegment) && !isSnapshot(segment))
return false;
else if (!isSnapshot(otherSegment) && isSnapshot(segment))
return true;
if (segment.value > otherSegment.value)
return lastWasLess;
lastWasLess = segment.value < otherSegment.value;
i++;
}
return true;
}
public boolean isGreaterOrEqualTo(Version other) {
int comp = compareTo(other);
return comp == 1 || comp == 0;
}
public boolean isLessOrEqualTo(Version other) {
int comp = compareTo(other);
return comp == -1 || comp == 0;
}
@Override
public String toString() {
String str = "";
for (VersionSegment segment : segments) {
str += segment.toString();
}
return str;
}
}
import org.asf.cyan.api.config.Configuration;
public class CyanUpdateInfo extends Configuration<CyanUpdateInfo> {
public String latestStableVersion;
public String latestAlphaVersion;
public String latestBetaVersion;
public String latestPreviewVersion;
public String[] longTermSupportVersions;
public String[] requiredUpgrade;
public HashMap<String, String> libraryVersions = new HashMap<String, String>();
public HashMap<String, String> changelogs = new HashMap<String, String>();
public HashMap<String, String> allVersions = new HashMap<String, String>();
public HashMap<String, String> byGameVersions = new HashMap<String, String>();
public HashMap<String, String> forgeSupport = new HashMap<String, String>();
public HashMap<String, String> fabricSupport = new HashMap<String, String>();
public HashMap<String, String> paperSupport = new HashMap<String, String>();
public HashMap<String, String> paperByMappings = new HashMap<String, String>();
public HashMap<String, String> spigotStableMappings = new HashMap<String, String>();
public HashMap<String, String> spigotLatestMappings = new HashMap<String, String>();
public HashMap<String, String> spigotTestingMappings = new HashMap<String, String>();
public CyanUpdateInfo(String content) {
readAll(content);
}
@Override
public String filename() {
return null;
}
@Override
public String folder() {
return null;
}
}
gradle.allprojects {
if (project.hasProperty("overrideGameVersion")) {
ext.minecraft=project.getProperty("overrideGameVersion")
}
def majorversion = minecraft
if (majorversion.split("\\.").length >= 3)
majorversion = majorversion.substring(0, majorversion.lastIndexOf("."))
ext.useJava16 = Version.fromString(majorversion).isGreaterOrEqualTo(Version.fromString("1.17"))
if (Version.fromString(majorversion).isGreaterOrEqualTo(Version.fromString("1.17")) && JavaVersion.current().compareTo(JavaVersion.VERSION_16) != 0 && JavaVersion.current().compareTo(JavaVersion.VERSION_16) != 1){
throw new RuntimeException("Cyan for Minecraft 1.17 requires Java 16 or greater.")
}
ext.exactgameversion=minecraft
if (project.hasProperty("setModLoader")) {
ext.modloader=project.getProperty("setModLoader")
}
if (project.hasProperty("setInheritsFromVersion")) {
ext.exactgameversion=project.getProperty("setInheritsFromVersion")
}
if (project.hasProperty("overrideReleaseType")) {
ext.versionType=project.getProperty("overrideReleaseType")
}
if (project.hasProperty("overrideMixinVersion")) {
ext.mixinversion=project.getProperty("overrideMixinVersion")
}
if (project.hasProperty("overrideMinMixinVersion")) {
ext.minmixin=project.getProperty("overrideMinMixinVersion")
}
ext.craftBukkitPOMUrl = "https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/raw/pom.xml?at=%commit%"
ext.spigotInfoUrl = "https://hub.spigotmc.org/versions/%mcver%.json";
if (modloader.startsWith("paper-")) {
def infoPath = "/org/asf/cyan/CyanVersionHolder/generic/CyanVersionHolder-generic-versions.ccfg";
def paperversion = modloader.substring("paper-".length())
if (paperversion.equals("latestsupported")) {
def useurl = "https://aerialworks.ddns.net/maven"
StringBuilder conf = new StringBuilder();
URL u = new URL(useurl + infoPath);
Scanner sc = new Scanner(u.openStream());
while (sc.hasNext())
conf.append(sc.nextLine()+System.lineSeparator());
sc.close();
CyanUpdateInfo info = new CyanUpdateInfo(conf.toString())
def mappingsVersion = info.spigotTestingMappings.get(minecraft)
def paper = ""
if (mappingsVersion == null) {
throw new IOException("Cannot find compatile paper mappings.");
}
paper = info.paperByMappings.get(mappingsVersion)
if (paper == null) {
URL url = new URL("https://papermc.io/api/v2/projects/paper/versions/" + minecraft);
InputStream strm = url.openStream()
JsonArray builds = JsonParser.parseString(new String(strm.readAllBytes())).getAsJsonObject().get("builds").getAsJsonArray();
strm.close()
paper = builds.get(builds.size() - 1).getAsString();
}
modloader = "paper-" + paper
ext.mappingsVersion = mappingsVersion
}
}
def modloaderVersion = minecraft
if (modloader.startsWith("paper-")) {
modloaderVersion = modloader.substring("paper-".length());
} else if (modloader.startsWith("forge-")) {
modloaderVersion = modloader.substring("forge-".length());
} else if (modloader.startsWith("fabric-loader-")) {
modloaderVersion = modloader.substring("fabric-loader-".length());
}
ext.exactgameversion = exactgameversion.replace("%modloader%", modloaderVersion)
ext.getCacheRoot = { ->
return getGradle().getGradleUserHomeDir().listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
if (name.equals("caches"))
return true;
return false;
}
})[0].getCanonicalFile();
}
}