9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-23 16:49:19 +00:00

Introduce new lockstep syncing system, modularize sync modes (#178)

* Start work on modular sync systems

* Add experimental lockstep sync system, close #69

* Refactor RedisMessageType enum

* Fixup lockstep syncing

* Bump to 3.1

* Update docs with details about the new Sync Modes

* Sync mode config key is `mode` instead of `type`

* Add server to data snapshot overview

* API: Add API for setting data syncers

* Fixup weird statistic matching logic
This commit is contained in:
William
2023-10-05 18:05:02 +01:00
committed by GitHub
parent 03ca335293
commit cae17f6e68
37 changed files with 777 additions and 226 deletions

View File

@@ -28,6 +28,7 @@ import net.william278.desertwell.util.UpdateChecker;
import net.william278.desertwell.util.Version;
import net.william278.husksync.adapter.DataAdapter;
import net.william278.husksync.config.Locales;
import net.william278.husksync.config.Server;
import net.william278.husksync.config.Settings;
import net.william278.husksync.data.Data;
import net.william278.husksync.data.Identifier;
@@ -36,6 +37,7 @@ import net.william278.husksync.database.Database;
import net.william278.husksync.event.EventDispatcher;
import net.william278.husksync.migrator.Migrator;
import net.william278.husksync.redis.RedisManager;
import net.william278.husksync.sync.DataSyncer;
import net.william278.husksync.user.ConsoleUser;
import net.william278.husksync.user.OnlineUser;
import net.william278.husksync.util.LegacyConverter;
@@ -90,6 +92,11 @@ public interface HuskSync extends Task.Supplier, EventDispatcher {
@NotNull
RedisManager getRedisManager();
/**
* Returns the implementing adapter for serializing data
*
* @return the {@link DataAdapter}
*/
@NotNull
DataAdapter getDataAdapter();
@@ -130,6 +137,21 @@ public interface HuskSync extends Task.Supplier, EventDispatcher {
return getSerializers().keySet();
}
/**
* Returns the data syncer implementation
*
* @return the {@link DataSyncer} implementation
*/
@NotNull
DataSyncer getDataSyncer();
/**
* Set the data syncer implementation
*
* @param dataSyncer the {@link DataSyncer} implementation
*/
void setDataSyncer(@NotNull DataSyncer dataSyncer);
/**
* Returns a list of available data {@link Migrator}s
*
@@ -167,6 +189,11 @@ public interface HuskSync extends Task.Supplier, EventDispatcher {
void setSettings(@NotNull Settings settings);
@NotNull
String getServerName();
void setServer(@NotNull Server server);
/**
* Returns the plugin {@link Locales}
*
@@ -255,7 +282,7 @@ public interface HuskSync extends Task.Supplier, EventDispatcher {
String getPlatformType();
/**
* Returns the legacy data converter, if it exists
* Returns the legacy data converter if it exists
*
* @return the {@link LegacyConverter}
*/
@@ -269,6 +296,9 @@ public interface HuskSync extends Task.Supplier, EventDispatcher {
// Load settings
setSettings(Annotaml.create(new File(getDataFolder(), "config.yml"), Settings.class).get());
// Load server name
setServer(Annotaml.create(new File(getDataFolder(), "server.yml"), Server.class).get());
// Load locales from language preset default
final Locales languagePresets = Annotaml.create(
Locales.class,
@@ -305,12 +335,31 @@ public interface HuskSync extends Task.Supplier, EventDispatcher {
}
}
/**
* Get the set of UUIDs of "locked players", for which events will be canceled.
* </p>
* Players are locked while their items are being set (on join) or saved (on quit)
*/
@NotNull
Set<UUID> getLockedPlayers();
default boolean isLocked(@NotNull UUID uuid) {
return getLockedPlayers().contains(uuid);
}
default void lockPlayer(@NotNull UUID uuid) {
getLockedPlayers().add(uuid);
}
default void unlockPlayer(@NotNull UUID uuid) {
getLockedPlayers().remove(uuid);
}
@NotNull
Gson getGson();
boolean isDisabling();
@NotNull
default Gson createGson() {
return Converters.registerOffsetDateTime(new GsonBuilder()).create();