Skip to content

Commit 1ca4085

Browse files
committed
modpack groups!
1 parent a9cbaa6 commit 1ca4085

47 files changed

Lines changed: 2058 additions & 985 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/src/main/java/pl/skidam/automodpack_core/Constants.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package pl.skidam.automodpack_core;
22

3+
import java.nio.file.Path;
34
import org.apache.logging.log4j.LogManager;
45
import org.apache.logging.log4j.Logger;
56
import pl.skidam.automodpack_core.config.Jsons;
67
import pl.skidam.automodpack_core.loader.*;
78
import pl.skidam.automodpack_core.modpack.ModpackExecutor;
89
import pl.skidam.automodpack_core.protocol.netty.NettyServer;
910

10-
import java.nio.file.Path;
11-
1211
// More or less constants
1312
// TODO cleanup
1413
public class Constants {
14+
1515
public static final Logger LOGGER = LogManager.getLogger("AutoModpack");
1616
public static final String MOD_ID = "automodpack"; // For real its "automodpack_mod" but we use this for resource locations etc.
1717
public static Boolean DEBUG = false;
@@ -28,8 +28,8 @@ public class Constants {
2828
public static Path MODS_DIR;
2929
public static ModpackExecutor modpackExecutor;
3030
public static NettyServer hostServer;
31-
public static Jsons.ServerConfigFieldsV2 serverConfig;
32-
public static Jsons.ClientConfigFieldsV2 clientConfig;
31+
public static Jsons.ServerConfigFieldsV3 serverConfig;
32+
public static Jsons.ClientConfigFieldsV3 clientConfig;
3333
public static Jsons.KnownHostsFields knownHosts;
3434
public static final Path automodpackDir = Path.of("automodpack");
3535
public static final Path storeDir = automodpackDir.resolve("store");
@@ -38,10 +38,8 @@ public class Constants {
3838
// Main - required
3939
// Addons - optional addon packs
4040
// Switches - optional or required packs, chosen by the player, only one can be installed at a time
41-
public static final Path hostContentModpackDir = hostModpackDir.resolve("main");
4241
public static Path hostModpackContentFile = hostModpackDir.resolve("automodpack-content.json");
4342
public static Path serverConfigFile = automodpackDir.resolve("automodpack-server.json");
44-
public static Path clientLocalMetadataFile = automodpackDir.resolve("automodpack-client-metadata.json");
4543
public static Path cacheDir = automodpackDir.resolve("cache");
4644
public static Path hashCacheDBFile = cacheDir.resolve("hash-cache.db");
4745
public static Path modCacheDBFile = cacheDir.resolve("mod-cache.db");
@@ -54,10 +52,10 @@ public class Constants {
5452
public static final Path serverCertFile = privateDir.resolve("cert.crt");
5553
public static final Path serverPrivateKeyFile = privateDir.resolve("key.pem");
5654

57-
5855
// Client
5956
public static final Path modpackContentTempFile = automodpackDir.resolve("automodpack-content.json.temp");
6057
public static final Path clientConfigFile = automodpackDir.resolve("automodpack-client.json");
58+
public static final Path clientSelectionFile = automodpackDir.resolve("automodpack-client-selection.json");
6159
public static final Path clientSecretsFile = privateDir.resolve("automodpack-client-secrets.json");
6260
public static final Path modpacksDir = automodpackDir.resolve("modpacks");
6361

core/src/main/java/pl/skidam/automodpack_core/Server.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package pl.skidam.automodpack_core;
22

3+
import static pl.skidam.automodpack_core.Constants.*;
4+
5+
import java.nio.file.Path;
6+
import java.util.HashSet;
7+
import java.util.LinkedHashMap;
8+
import java.util.Set;
39
import pl.skidam.automodpack_core.config.ConfigTools;
410
import pl.skidam.automodpack_core.config.Jsons;
5-
import pl.skidam.automodpack_core.modpack.ModpackExecutor;
611
import pl.skidam.automodpack_core.modpack.ModpackContent;
12+
import pl.skidam.automodpack_core.modpack.ModpackExecutor;
713
import pl.skidam.automodpack_core.protocol.netty.NettyServer;
814

9-
import java.nio.file.Path;
10-
import java.util.HashSet;
11-
12-
import static pl.skidam.automodpack_core.Constants.*;
13-
1415
public class Server {
1516

1617
// TODO Finish this class that it will be able to host the server without mod
1718
public static void main(String[] args) {
18-
1919
if (args.length < 1) {
2020
LOGGER.error("Modpack id not provided!");
2121
return;
@@ -35,9 +35,8 @@ public static void main(String[] args) {
3535
serverConfigFile = modpackDir.resolve("automodpack-server.json");
3636
serverCoreConfigFile = modpackDir.resolve("automodpack-core.json");
3737

38-
serverConfig = ConfigTools.load(serverConfigFile, Jsons.ServerConfigFieldsV2.class);
38+
serverConfig = ConfigTools.load(serverConfigFile, Jsons.ServerConfigFieldsV3.class);
3939
if (serverConfig != null) {
40-
serverConfig.syncedFiles = new HashSet<>();
4140
serverConfig.validateSecrets = false;
4241
ConfigTools.save(serverConfigFile, serverConfig);
4342

@@ -60,8 +59,7 @@ public static void main(String[] args) {
6059
mainModpackDir.toFile().mkdirs();
6160

6261
ModpackExecutor modpackExecutor = new ModpackExecutor();
63-
ModpackContent modpackContent = new ModpackContent(serverConfig.modpackName, null, mainModpackDir, serverConfig.syncedFiles, serverConfig.allowEditsInFiles, serverConfig.forceCopyFilesToStandardLocation, modpackExecutor.getExecutor());
64-
boolean generated = modpackExecutor.generateNew(modpackContent);
62+
boolean generated = modpackExecutor.generateNew();
6563

6664
if (generated) {
6765
LOGGER.info("Modpack generated!");

core/src/main/java/pl/skidam/automodpack_core/config/ConfigTools.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
21
package pl.skidam.automodpack_core.config;
32

4-
import com.google.gson.*;
5-
import pl.skidam.automodpack_core.utils.AddressHelpers;
3+
import static pl.skidam.automodpack_core.Constants.*;
64

5+
import com.google.gson.*;
76
import java.lang.reflect.Type;
87
import java.net.InetSocketAddress;
98
import java.nio.file.Files;
109
import java.nio.file.Path;
1110
import java.nio.file.StandardOpenOption;
12-
13-
import static pl.skidam.automodpack_core.Constants.*;
11+
import pl.skidam.automodpack_core.utils.AddressHelpers;
1412

1513
public class ConfigTools {
1614

17-
public static Gson GSON = new GsonBuilder()
18-
.disableHtmlEscaping()
19-
.setPrettyPrinting()
20-
.registerTypeAdapter(InetSocketAddress.class, new InetSocketAddressTypeAdapter())
21-
.create();
15+
public static Gson GSON = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().registerTypeAdapter(InetSocketAddress.class, new InetSocketAddressTypeAdapter()).create();
16+
17+
private static class InetSocketAddressTypeAdapter implements JsonSerializer<InetSocketAddress>, JsonDeserializer<InetSocketAddress> {
2218

23-
private static class InetSocketAddressTypeAdapter implements JsonSerializer<InetSocketAddress>,JsonDeserializer<InetSocketAddress> {
2419
@Override
2520
public JsonElement serialize(InetSocketAddress src, Type typeOfSrc, JsonSerializationContext context) {
2621
return new JsonPrimitive(src.getHostString() + ":" + src.getPort());
@@ -50,14 +45,14 @@ public static <T> T softLoad(Path configFile, Class<T> configClass) {
5045
String json = Files.readString(configFile);
5146
return GSON.fromJson(json, configClass);
5247
}
53-
} catch (Exception ignored) { }
48+
} catch (Exception ignored) {}
5449
return null;
5550
}
5651

5752
public static <T> T load(Path configFile, Class<T> configClass) {
5853
try {
5954
if (!Files.isDirectory(configFile.getParent())) {
60-
Files.createDirectories(configFile.getParent());
55+
Files.createDirectories(configFile.getParent());
6156
}
6257

6358
if (Files.isRegularFile(configFile)) {
@@ -80,7 +75,8 @@ public static <T> T load(Path configFile, Class<T> configClass) {
8075
e.printStackTrace();
8176
}
8277

83-
try { // create new config
78+
try {
79+
// create new config
8480
T obj = getConfigObject(configClass);
8581
save(configFile, obj);
8682
return obj;
@@ -94,7 +90,7 @@ public static <T> T load(Path configFile, Class<T> configClass) {
9490
public static <T> T load(String json, Class<T> configClass) {
9591
try {
9692
if (json != null) {
97-
return GSON.fromJson(json, configClass);
93+
return GSON.fromJson(json, configClass);
9894
}
9995
} catch (Exception e) {
10096
LOGGER.error("Couldn't load config! " + configClass);
@@ -121,21 +117,20 @@ public static void save(Path configFile, Object configObject) {
121117
}
122118
}
123119

124-
125120
// Modpack content stuff
126-
public static Jsons.ModpackContentFields loadModpackContent(Path modpackContentFile) {
121+
public static Jsons.ModpackContent loadModpackContent(Path modpackContentFile) {
127122
try {
128123
if (Files.isRegularFile(modpackContentFile)) {
129124
String json = Files.readString(modpackContentFile);
130-
return GSON.fromJson(json, Jsons.ModpackContentFields.class);
125+
return GSON.fromJson(json, Jsons.ModpackContent.class);
131126
}
132127
} catch (Exception e) {
133128
LOGGER.error("Couldn't load modpack content! {}", modpackContentFile.toAbsolutePath().normalize(), e);
134129
}
135130
return null;
136131
}
137132

138-
public static void saveModpackContent(Path modpackContentFile, Jsons.ModpackContentFields configObject) {
133+
public static void saveModpackContent(Path modpackContentFile, Jsons.ModpackContent configObject) {
139134
try {
140135
if (!Files.isDirectory(modpackContentFile.getParent())) {
141136
Files.createDirectories(modpackContentFile.getParent());
@@ -147,4 +142,33 @@ public static void saveModpackContent(Path modpackContentFile, Jsons.ModpackCont
147142
e.printStackTrace();
148143
}
149144
}
145+
146+
public static Jsons.ClientSelectionManagerFields loadClientSelectionManager(Path selectionFile) {
147+
try {
148+
if (Files.isRegularFile(selectionFile)) {
149+
String json = Files.readString(selectionFile);
150+
Jsons.ClientSelectionManagerFields obj = GSON.fromJson(json, Jsons.ClientSelectionManagerFields.class);
151+
if (obj == null) {
152+
return new Jsons.ClientSelectionManagerFields();
153+
}
154+
return obj;
155+
}
156+
} catch (Exception e) {
157+
LOGGER.debug("Couldn't load client selection manager file (this is normal on first startup): {}", e.getMessage());
158+
}
159+
return new Jsons.ClientSelectionManagerFields();
160+
}
161+
162+
public static void saveClientSelectionManager(Path selectionFile, Jsons.ClientSelectionManagerFields configObject) {
163+
try {
164+
if (!Files.isDirectory(selectionFile.getParent())) {
165+
Files.createDirectories(selectionFile.getParent());
166+
}
167+
168+
Files.writeString(selectionFile, GSON.toJson(configObject), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
169+
} catch (Exception e) {
170+
LOGGER.error("Couldn't save client selection manager!");
171+
e.printStackTrace();
172+
}
173+
}
150174
}

core/src/main/java/pl/skidam/automodpack_core/config/ConfigUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static void normalizeServerConfig(Jsons.ServerConfigFieldsV2 config, bool
1414
}
1515
}
1616

17+
// TODO adapt yourself
1718
public static void normalizeServerConfig(Jsons.ServerConfigFieldsV2 config) {
1819
Set<String> fixedSyncedFiles = new HashSet<>(config.syncedFiles.size());
1920
Set<String> fixedAllowEditsInFiles = new HashSet<>(config.allowEditsInFiles.size());

0 commit comments

Comments
 (0)