forked from MeteorDevelopment/meteor-client
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAddonManager.java
More file actions
94 lines (75 loc) · 3.56 KB
/
Copy pathAddonManager.java
File metadata and controls
94 lines (75 loc) · 3.56 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
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/
package meteordevelopment.meteorclient.addons;
import meteordevelopment.meteorclient.MeteorClient;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.fabricmc.loader.api.metadata.Person;
import java.util.ArrayList;
import java.util.List;
public class AddonManager {
public static final List<MeteorAddon> ADDONS = new ArrayList<>();
public static void init() {
// Meteor pseudo addon
{
MeteorClient.ADDON = new MeteorAddon() {
@Override
public void onInitialize() {}
@Override
public String getPackage() {
return "meteordevelopment.meteorclient";
}
@Override
public String getWebsite() {
return "https://meteorclient.com";
}
@Override
public GithubRepo getRepo() {
return new GithubRepo("MeteorDevelopment", "meteor-client");
}
@Override
public String getCommit() {
String commit = MeteorClient.MOD_META.getCustomValue(MeteorClient.MOD_ID + ":commit").getAsString();
return commit.isEmpty() ? null : commit;
}
};
ModMetadata metadata = FabricLoader.getInstance().getModContainer(MeteorClient.MOD_ID).get().getMetadata();
MeteorClient.ADDON.id = metadata.getId();
MeteorClient.ADDON.name = metadata.getName();
MeteorClient.ADDON.authors = new String[metadata.getAuthors().size()];
if (metadata.containsCustomValue(MeteorClient.MOD_ID + ":color")) {
MeteorClient.ADDON.color.parse(metadata.getCustomValue(MeteorClient.MOD_ID + ":color").getAsString());
}
int i = 0;
for (Person author : metadata.getAuthors()) {
MeteorClient.ADDON.authors[i++] = author.getName();
}
ADDONS.add(MeteorClient.ADDON);
}
// Addons
for (EntrypointContainer<MeteorAddon> entrypoint : FabricLoader.getInstance().getEntrypointContainers("meteor", MeteorAddon.class)) {
ModMetadata metadata = entrypoint.getProvider().getMetadata();
MeteorAddon addon;
try {
addon = entrypoint.getEntrypoint();
} catch (Throwable throwable) {
throw new RuntimeException("Exception during addon init \"%s\".".formatted(metadata.getName()), throwable);
}
addon.id = metadata.getId();
addon.name = metadata.getName();
if (metadata.getAuthors().isEmpty()) throw new RuntimeException("Addon \"%s\" requires at least 1 author to be defined in it's fabric.mod.json. See https://fabricmc.net/wiki/documentation:fabric_mod_json_spec".formatted(addon.name));
addon.authors = new String[metadata.getAuthors().size()];
if (metadata.containsCustomValue(MeteorClient.MOD_ID + ":color")) {
addon.color.parse(metadata.getCustomValue(MeteorClient.MOD_ID + ":color").getAsString());
}
int i = 0;
for (Person author : metadata.getAuthors()) {
addon.authors[i++] = author.getName();
}
ADDONS.add(addon);
}
}
}