Skip to content

Commit 928e7f4

Browse files
committed
pack authors can be a list
1 parent 2b06b39 commit 928e7f4

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/main/java/com/cleanroommc/groovyscript/helper/GroovyHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraftforge.fml.common.Loader;
1010

1111
import java.io.File;
12+
import java.util.List;
1213

1314
public class GroovyHelper {
1415

@@ -56,6 +57,10 @@ public static String getPackVersion() {
5657
return GroovyScript.getRunConfig().getVersion();
5758
}
5859

60+
public static List<String> getPackAuthors() {
61+
return GroovyScript.getRunConfig().getPackAuthors();
62+
}
63+
5964
public static boolean isDebug() {
6065
return GroovyScript.getRunConfig().isDebug();
6166
}

src/main/java/com/cleanroommc/groovyscript/sandbox/RunConfig.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static JsonObject createDefaultJson() {
6363

6464
private final String packName;
6565
private final String packId;
66-
private final String packAuthor;
6766
private final String version;
67+
private final List<String> packAuthors;
6868
private final Map<String, List<String>> loaderPaths = new Object2ObjectOpenHashMap<>();
6969
private final List<String> packmodeList = new ArrayList<>();
7070
private final Set<String> packmodeSet = new ObjectOpenHashSet<>();
@@ -94,19 +94,36 @@ public RunConfig(JsonObject json) {
9494
name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, id).replace('_', ' ');
9595
}
9696
this.packName = name;
97-
this.packAuthor = JsonHelper.getString(json, "", "packAuthor", "author");
9897
this.packId = id;
9998
this.version = JsonHelper.getString(json, "1.0.0", "version", "ver");
99+
JsonElement authors = null;
100+
if (json.has("author")) authors = json.get("author");
101+
else if (json.has("packAuthors")) authors = json.get("packAuthors");
102+
if (authors != null) {
103+
List<String> packAuthors = new ArrayList<>();
104+
if (authors.isJsonPrimitive()) {
105+
// author list in a single string separated by a comma
106+
packAuthors.addAll(Arrays.stream(StringUtils.split(authors.getAsString(), ","))
107+
.map(String::trim)
108+
.filter(s -> !s.isEmpty())
109+
.collect(Collectors.toList()));
110+
} else if (authors.isJsonArray()) {
111+
// authors in a json list, each entry is an author
112+
for (JsonElement author : authors.getAsJsonArray()) {
113+
if (author.isJsonPrimitive()) {
114+
packAuthors.add(author.getAsString());
115+
}
116+
}
117+
}
118+
this.packAuthors = Collections.unmodifiableList(packAuthors);
119+
} else {
120+
this.packAuthors = Collections.emptyList();
121+
}
100122
modMetadata.modId = this.packId;
101123
modMetadata.name = this.packName;
102124
modMetadata.version = this.version;
103125
modMetadata.parent = GroovyScript.ID;
104-
modMetadata.authorList.addAll(
105-
Arrays.stream(StringUtils.split(this.packAuthor, ","))
106-
.map(String::trim)
107-
.filter(s -> !s.isEmpty())
108-
.collect(Collectors.toList())
109-
);
126+
modMetadata.authorList.addAll(this.packAuthors);
110127
}
111128

112129
@ApiStatus.Internal
@@ -223,6 +240,10 @@ public String getVersion() {
223240
return version;
224241
}
225242

243+
public List<String> getPackAuthors() {
244+
return packAuthors;
245+
}
246+
226247
public boolean isDebug() {
227248
return debug;
228249
}

0 commit comments

Comments
 (0)