Skip to content

Commit

Permalink
Add syncIsHost config
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Aug 20, 2023
1 parent b94ca09 commit 2b5581f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ subprojects {
}

dependencies {
annotationProcessor 'systems.manifold:manifold-preprocessor:2023.1.11'
annotationProcessor 'systems.manifold:manifold-preprocessor:+'
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings parchment_not_avail ? loom.officialMojangMappings() : loom.layered() {
officialMojangMappings()
Expand Down
7 changes: 4 additions & 3 deletions common/src/main/java/cn/zbx1425/worldcomment/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,25 @@
public class Config {

public String redisUrl = "";
public boolean syncIsHost = true;

public String uplinkUrl = "";
public String uplinkAuthKey = "";

public void load(Path configPath) throws IOException {
if (!Files.exists(configPath)) {
return;
}
if (!Files.exists(configPath)) save(configPath);

JsonObject json = JsonParser.parseString(Files.readString(configPath)).getAsJsonObject();
redisUrl = json.get("redisUrl").getAsString();
syncIsHost = json.get("syncIsHost").getAsBoolean();
uplinkUrl = json.get("uplinkUrl").getAsString();
uplinkAuthKey = json.get("uplinkAuthKey").getAsString();
}

public void save(Path configPath) throws IOException {
JsonObject json = new JsonObject();
json.addProperty("redisUrl", redisUrl);
json.addProperty("syncIsHost", syncIsHost);
json.addProperty("uplinkUrl", uplinkUrl);
json.addProperty("uplinkAuthKey", uplinkAuthKey);

Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/cn/zbx1425/worldcomment/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void init(RegistriesWrapper registries) {
CONFIG.load(server.getServerDirectory().toPath()
.resolve("config").resolve("world-comment.json"));

DATABASE = new ServerWorldData(server);
DATABASE = new ServerWorldData(server, CONFIG.syncIsHost);
if (!CONFIG.redisUrl.isEmpty()) {
DATABASE.peerChannel = new RedisSynchronizer(CONFIG.redisUrl, DATABASE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ public class ServerWorldData {
public final MinecraftServer server;
public final Path basePath;

public boolean isHost = true;
public boolean isHost;

public final CommentCache comments = new CommentCache();

public final FileSerializer fileSerializer;
public Synchronizer peerChannel;

public ServerWorldData(MinecraftServer server) {
public ServerWorldData(MinecraftServer server, boolean isHost) {
this.server = server;
this.basePath = Path.of(server.getWorldPath(LevelResource.ROOT).toString(), "world-comment");
fileSerializer = new FileSerializer(basePath);
this.isHost = isHost;
this.peerChannel = Synchronizer.NOOP;
}

Expand Down

0 comments on commit 2b5581f

Please sign in to comment.