Merge pull request #53 from EoD/advancement-sync-optional
make advancement sync optional
This commit is contained in:
commit
f43c47f78d
|
|
@ -16,6 +16,7 @@ public class JdbcConfig {
|
||||||
public static ForgeConfigSpec.ConfigValue<String> PASSWORD;
|
public static ForgeConfigSpec.ConfigValue<String> PASSWORD;
|
||||||
public static ForgeConfigSpec.ConfigValue<String> DATABASE_NAME;
|
public static ForgeConfigSpec.ConfigValue<String> DATABASE_NAME;
|
||||||
public static ForgeConfigSpec.ConfigValue<List<String>> SYNC_WORLD;
|
public static ForgeConfigSpec.ConfigValue<List<String>> SYNC_WORLD;
|
||||||
|
public static ForgeConfigSpec.BooleanValue SYNC_ADVANCEMENTS;
|
||||||
public static ForgeConfigSpec.BooleanValue USE_SSL;
|
public static ForgeConfigSpec.BooleanValue USE_SSL;
|
||||||
public static ForgeConfigSpec.BooleanValue SYNC_CHAT;
|
public static ForgeConfigSpec.BooleanValue SYNC_CHAT;
|
||||||
public static ForgeConfigSpec.BooleanValue IS_CHAT_SERVER;
|
public static ForgeConfigSpec.BooleanValue IS_CHAT_SERVER;
|
||||||
|
|
@ -37,6 +38,8 @@ public class JdbcConfig {
|
||||||
DATABASE_NAME = COMMON_BUILDER.comment("database name").define("db_name","playersync");
|
DATABASE_NAME = COMMON_BUILDER.comment("database name").define("db_name","playersync");
|
||||||
SERVER_ID = COMMON_BUILDER.comment("the server id should be unique").define("Server_id", new Random().nextInt(1,Integer.MAX_VALUE-1));
|
SERVER_ID = COMMON_BUILDER.comment("the server id should be unique").define("Server_id", new Random().nextInt(1,Integer.MAX_VALUE-1));
|
||||||
SYNC_WORLD = COMMON_BUILDER.comment("The worlds that will be synchronized. If running on a server, leave array empty.").define("sync_world", new ArrayList<>());
|
SYNC_WORLD = COMMON_BUILDER.comment("The worlds that will be synchronized. If running on a server, leave array empty.").define("sync_world", new ArrayList<>());
|
||||||
|
SYNC_ADVANCEMENTS = COMMON_BUILDER.comment("Whether to sync advancements between servers")
|
||||||
|
.define("sync_advancements", true);
|
||||||
SYNC_CHAT= COMMON_BUILDER.comment("Whether synchronize chat").define("sync_chat", true);
|
SYNC_CHAT= COMMON_BUILDER.comment("Whether synchronize chat").define("sync_chat", true);
|
||||||
IS_CHAT_SERVER = COMMON_BUILDER.comment("Whether recieve messages from other servers as host").define("IsChatServer",false);
|
IS_CHAT_SERVER = COMMON_BUILDER.comment("Whether recieve messages from other servers as host").define("IsChatServer",false);
|
||||||
CHAT_SERVER_IP = COMMON_BUILDER.define("ChatServerIP","127.0.0.1");
|
CHAT_SERVER_IP = COMMON_BUILDER.define("ChatServerIP","127.0.0.1");
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ public class VanillaSync {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onDataPackSyncEvent(OnDatapackSyncEvent event) throws SQLException, IOException {
|
public static void onDataPackSyncEvent(OnDatapackSyncEvent event) throws SQLException, IOException {
|
||||||
|
if (!JdbcConfig.SYNC_ADVANCEMENTS.get())
|
||||||
|
return; // advancement sync disabled
|
||||||
|
|
||||||
final ServerPlayer serverPlayer = event.getPlayer();
|
final ServerPlayer serverPlayer = event.getPlayer();
|
||||||
if (serverPlayer == null) {
|
if (serverPlayer == null) {
|
||||||
PlayerSync.LOGGER.debug("No player joining");
|
PlayerSync.LOGGER.debug("No player joining");
|
||||||
|
|
@ -364,33 +367,36 @@ public class VanillaSync {
|
||||||
CompoundTag effectTag = entry.getValue().save(new CompoundTag());
|
CompoundTag effectTag = entry.getValue().save(new CompoundTag());
|
||||||
effectMap.put(MobEffect.getId(entry.getKey()), serialize(effectTag.toString()));
|
effectMap.put(MobEffect.getId(entry.getKey()), serialize(effectTag.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advancements
|
// Advancements
|
||||||
File advancements = null;
|
File advancements = null;
|
||||||
File gameDir = Objects.requireNonNull(player.getServer()).getServerDirectory();
|
byte[] advancementBytes = new byte[0];
|
||||||
final MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
if (JdbcConfig.SYNC_ADVANCEMENTS.get()) {
|
||||||
if (server != null && server.isDedicatedServer() ) {
|
File gameDir = Objects.requireNonNull(player.getServer()).getServerDirectory();
|
||||||
PlayerSync.LOGGER.trace("Reading dedicated server advancements");
|
final MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||||
advancements = new File(gameDir, getSyncWorldForServer() + "/advancements" + "/" + player_uuid + ".json");
|
if (server != null && server.isDedicatedServer() ) {
|
||||||
} else {
|
PlayerSync.LOGGER.trace("Reading dedicated server advancements");
|
||||||
PlayerSync.LOGGER.debug("Reading non-dedicated server advancements");
|
advancements = new File(gameDir, getSyncWorldForServer() + "/advancements" + "/" + player_uuid + ".json");
|
||||||
File[] files = scanAdvancementsFile(player_uuid, gameDir);
|
} else {
|
||||||
long latestModifiedDate = 0;
|
PlayerSync.LOGGER.debug("Reading non-dedicated server advancements");
|
||||||
for (File file : files) {
|
File[] files = scanAdvancementsFile(player_uuid, gameDir);
|
||||||
if (file == null) continue;
|
long latestModifiedDate = 0;
|
||||||
if (file.lastModified() > latestModifiedDate) {
|
for (File file : files) {
|
||||||
latestModifiedDate = file.lastModified();
|
if (file == null) continue;
|
||||||
advancements = file;
|
if (file.lastModified() > latestModifiedDate) {
|
||||||
|
latestModifiedDate = file.lastModified();
|
||||||
|
advancements = file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (advancements != null) {
|
||||||
|
PlayerSync.LOGGER.debug("Storing advancements for " + player_uuid + " from " + advancements.toPath());
|
||||||
|
advancementBytes = Files.readAllBytes(advancements.toPath());
|
||||||
|
} else {
|
||||||
|
PlayerSync.LOGGER.error("Unable to save advancements for player " + player_uuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
byte[] bytes = new byte[0];
|
String json = new String(advancementBytes, StandardCharsets.UTF_8);
|
||||||
if (advancements != null) {
|
|
||||||
PlayerSync.LOGGER.debug("Storing advancements for " + player_uuid + " from " + advancements.toPath());
|
|
||||||
bytes = Files.readAllBytes(advancements.toPath());
|
|
||||||
} else {
|
|
||||||
PlayerSync.LOGGER.error("Unable to save advancements for player " + player_uuid);
|
|
||||||
}
|
|
||||||
String json = new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
PlayerSync.LOGGER.trace("Storing advancements for player " + player_uuid + ": " + json);
|
PlayerSync.LOGGER.trace("Storing advancements for player " + player_uuid + ": " + json);
|
||||||
|
|
||||||
// SQL Operation for player data
|
// SQL Operation for player data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user