├── .circleci
└── config.yml
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle.kts
├── datasync-api
└── src
│ └── main
│ └── java
│ └── org
│ └── anvilpowered
│ └── datasync
│ └── api
│ ├── DataSync.java
│ ├── key
│ └── DataKeyService.java
│ ├── member
│ ├── MemberManager.java
│ ├── MemberRepository.java
│ ├── MongoMemberRepository.java
│ └── XodusMemberRepository.java
│ ├── misc
│ └── SyncUtils.java
│ ├── model
│ ├── member
│ │ └── Member.java
│ └── snapshot
│ │ └── Snapshot.java
│ ├── registry
│ └── DataSyncKeys.java
│ ├── serializer
│ ├── ExperienceSerializer.java
│ ├── GameModeSerializer.java
│ ├── HealthSerializer.java
│ ├── HungerSerializer.java
│ ├── InventorySerializer.java
│ ├── Serializer.java
│ ├── SnapshotSerializer.java
│ └── user
│ │ ├── UserSerializerComponent.java
│ │ ├── UserSerializerManager.java
│ │ └── UserTransitCache.java
│ ├── snapshot
│ ├── SnapshotManager.java
│ └── SnapshotRepository.java
│ ├── snapshotoptimization
│ ├── SnapshotOptimizationManager.java
│ └── SnapshotOptimizationService.java
│ └── task
│ └── SerializationTaskService.java
├── datasync-common
├── build.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── anvilpowered
│ └── datasync
│ ├── api
│ └── DataSyncImpl.java
│ └── common
│ ├── command
│ ├── CommonSyncCommandNode.java
│ ├── optimize
│ │ └── CommonOptimizeCommandNode.java
│ └── snapshot
│ │ └── CommonSnapshotCommandNode.java
│ ├── key
│ └── CommonDataKeyService.java
│ ├── member
│ ├── CommonMemberManager.java
│ ├── CommonMemberRepository.java
│ ├── CommonMongoMemberRepository.java
│ └── CommonXodusMemberRepository.java
│ ├── misc
│ └── CommonSyncUtils.java
│ ├── model
│ ├── member
│ │ ├── MongoMember.java
│ │ └── XodusMember.java
│ └── snapshot
│ │ ├── MongoSnapshot.java
│ │ └── XodusSnapshot.java
│ ├── module
│ └── CommonModule.java
│ ├── plugin
│ └── DataSyncPluginInfo.java
│ ├── registry
│ ├── CommonConfigurationService.java
│ └── CommonRegistry.java
│ ├── serializer
│ ├── CommonExperienceSerializer.java
│ ├── CommonGameModeSerializer.java
│ ├── CommonHealthSerializer.java
│ ├── CommonHungerSerializer.java
│ ├── CommonInventorySerializer.java
│ ├── CommonSerializer.java
│ ├── CommonSnapshotSerializer.java
│ └── user
│ │ ├── CommonUserSerializerComponent.java
│ │ ├── CommonUserSerializerManager.java
│ │ └── CommonUserTransitCache.java
│ ├── snapshot
│ ├── CommonMongoSnapshotRepository.java
│ ├── CommonSnapshotManager.java
│ ├── CommonSnapshotRepository.java
│ └── CommonXodusSnapshotRepository.java
│ ├── snapshotoptimization
│ ├── CommonSnapshotOptimizationManager.java
│ └── CommonSnapshotOptimizationService.java
│ └── task
│ └── CommonSerializationTaskService.java
├── datasync-sponge
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── anvilpowered
│ │ └── datasync
│ │ └── sponge
│ │ ├── DataSyncSponge.java
│ │ ├── command
│ │ ├── SpongeSyncCommandNode.java
│ │ ├── SpongeSyncLockCommand.java
│ │ ├── SpongeSyncReloadCommand.java
│ │ ├── SpongeSyncTestCommand.java
│ │ ├── SpongeSyncUploadCommand.java
│ │ ├── optimize
│ │ │ ├── SpongeOptimizeCommandNode.java
│ │ │ ├── SpongeOptimizeInfoCommand.java
│ │ │ ├── SpongeOptimizeStartCommand.java
│ │ │ └── SpongeOptimizeStopCommand.java
│ │ └── snapshot
│ │ │ ├── SpongeSnapshotCommandNode.java
│ │ │ ├── SpongeSnapshotCreateCommand.java
│ │ │ ├── SpongeSnapshotDeleteCommand.java
│ │ │ ├── SpongeSnapshotInfoCommand.java
│ │ │ ├── SpongeSnapshotListCommand.java
│ │ │ ├── SpongeSnapshotRestoreCommand.java
│ │ │ └── SpongeSnapshotViewCommand.java
│ │ ├── event
│ │ └── SerializerInitializationEvent.java
│ │ ├── keys
│ │ └── SpongeDataKeyService.java
│ │ ├── listener
│ │ └── SpongePlayerListener.java
│ │ ├── module
│ │ └── SpongeModule.java
│ │ ├── registry
│ │ └── SpongeConfigurationService.java
│ │ ├── serializer
│ │ ├── SpongeExperienceSerializer.java
│ │ ├── SpongeGameModeSerializer.java
│ │ ├── SpongeHealthSerializer.java
│ │ ├── SpongeHungerSerializer.java
│ │ ├── SpongeInventorySerializer.java
│ │ ├── SpongeSnapshotSerializer.java
│ │ └── user
│ │ │ └── SpongeUserSerializerComponent.java
│ │ ├── snapshotoptimization
│ │ └── SpongeSnapshotOptimizationService.java
│ │ ├── task
│ │ └── SpongeSerializationTaskService.java
│ │ └── util
│ │ └── Utils.java
│ └── test
│ └── java
│ └── rocks
│ └── milspecsg
│ └── msdatasync
│ └── tests
│ └── ExampleTests.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── icon.png
└── settings.gradle
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2 # use CircleCI 2.0
2 | jobs: # a collection of steps
3 | build:
4 | environment:
5 | # Configure the JVM and Gradle to avoid OOM errors
6 | _JAVA_OPTIONS: "-Xmx3g"
7 | GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2"
8 | docker: # run the steps with Docker
9 | - image: circleci/openjdk:8u222-jdk-stretch # ...with this image as the primary container; this is where all `steps` will run
10 | steps: # a collection of executable commands
11 | - checkout # check out source code to working directory
12 | - run:
13 | name: "Pull Submodules"
14 | command: |
15 | git submodule init
16 | git submodule update --remote
17 | # Read about caching dependencies: https://circleci.com/docs/2.0/caching/
18 | - restore_cache:
19 | key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
20 | - restore_cache:
21 | key: v1-gradle-cache-{{ checksum "build.gradle" }}
22 | - run:
23 | name: Run rocks.milspecsg.msdatasync.tests # See: https://circleci.com/docs/2.0/parallelism-faster-jobs/
24 | # Use "./gradlew test" instead if tests are not run in parallel
25 | command: |
26 | echo "Running gradle tests"
27 | ./gradlew test
28 | - save_cache:
29 | paths:
30 | - ~/.gradle/wrapper
31 | key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
32 | - save_cache:
33 | paths:
34 | - ~/.gradle/caches
35 | key: v1-gradle-cache-{{ checksum "build.gradle" }}
36 | - run:
37 | name: Save test results
38 | command: |
39 | mkdir -p ~/test-results/junit/
40 | find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} ~/test-results/junit/ \;
41 | when: always
42 | - store_test_results:
43 | path: ~/test-results
44 | - store_artifacts:
45 | path: ~/test-results/junit
46 | - run:
47 | name: Assemble JAR
48 | command: |
49 | # Skip this for other nodes
50 | if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
51 | ./gradlew assemble -PbuildNumber=$CIRCLE_BUILD_NUM
52 | fi
53 | # As the JAR was only assembled in the first build container, build/libs will be empty in all the other build containers.
54 | - store_artifacts:
55 | path: sponge/build/libs
56 | # See https://circleci.com/docs/2.0/deployment-integrations/ for deploy examples
57 | workflows:
58 | version: 2
59 | workflow:
60 | jobs:
61 | - build
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Intellij ###
2 | .idea/
3 | *.iws
4 | out/
5 | *.iml
6 | .idea_modules/
7 | atlassian-ide-plugin.xml
8 |
9 | ### Eclipse ###
10 | .metadata
11 | bin/
12 | tmp/
13 | *.tmp
14 | *.bak
15 | *.swp
16 | *~.nib
17 | local.properties
18 | .settings/
19 | .loadpath
20 | .recommenders
21 | .externalToolBuilders/
22 | *.launch
23 | .factorypath
24 | .recommenders/
25 | .apt_generated/
26 | .project
27 | .classpath
28 |
29 | ### Linux ###
30 | *~
31 | .fuse_hidden*
32 | .directory
33 | .Trash-*
34 | .nfs*
35 |
36 | ### macOS ###
37 | .DS_Store
38 | .AppleDouble
39 | .LSOverride
40 | Icon
41 | ._*
42 | .DocumentRevisions-V100
43 | .fseventsd
44 | .Spotlight-V100
45 | .TemporaryItems
46 | .Trashes
47 | .VolumeIcon.icns
48 | .com.apple.timemachine.donotpresent
49 | .AppleDB
50 | .AppleDesktop
51 | Network Trash Folder
52 | Temporary Items
53 | .apdisk
54 |
55 | ### NetBeans ###
56 | nbproject/private/
57 | build/
58 | nbbuild/
59 | dist/
60 | nbdist/
61 | .nb-gradle/
62 |
63 | ### Windows ###
64 | # Windows thumbnail cache files
65 | Thumbs.db
66 | ehthumbs.db
67 | ehthumbs_vista.db
68 | *.stackdump
69 | [Dd]esktop.ini
70 | $RECYCLE.BIN/
71 | *.lnk
72 |
73 | ### Gradle ###
74 | .gradle
75 | # build/ already defined under netbeans
76 | out/
77 | gradle-app.setting
78 | !gradle-wrapper.jar
79 | .gradletasknamecache
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MSDataSync
2 |
3 |
4 |
5 | #### Quick Links
6 | [Join our development discord](https://discord.gg/8RUzuwu)
7 |
8 | [Ore page](https://ore.spongepowered.org/Cableguy20/DataSync)
9 |
10 | [Installation Guide](https://github.com/AnvilPowered/DataSync/wiki/Installation)
11 |
12 | Have you ever had problems with players losing items?
13 |
14 | Do you run a multi server network where every server needs to share inventories and other player data?
15 |
16 | ### Look no further
17 |
18 | _MSDataSync_ is an advanced player data backup plugin that lets you store, manage, edit and rollback player data!
19 |
20 | (Compatible with forge and vanilla)
21 |
22 | # Features
23 |
24 | ## Backup player data
25 |
26 | - _MSDataSync_ creates automated snapshots with an interval specified in your config
27 |
28 | - As of this writing, a snapshot will include (by default)
29 | - Inventory
30 | - Health
31 | - Hunger
32 | - Experience
33 | - Game mode
34 |
35 | - You can manually create a snapshot for a player with `/sync snapshot create `
36 |
37 | - Or create a snapshot for everyone on the server with `/sync up`
38 |
39 | - By default, _MSDataSync_ will load the latest snapshot when a player leaves and create a snapshot when a player joins.
40 | This can be disabled in the config.
41 |
42 | ## Restore player data
43 |
44 | - The old way
45 |
46 | ```
47 | Player: HeLp I LOst mY sTuFf!!!!! OWnER!!!!!!
48 |
49 | Owner: screenshots or it didnt happen, sorry bud
50 |
51 | Player: this server is dumb, im never coming back!
52 |
53 | Player has left the game
54 | ```
55 |
56 | - With _MSDataSync_
57 |
58 | ```
59 | Player: HeLp I LOst mY sTuFf!!!!! OWnER!!!!!!
60 |
61 | Owner: when did this happen?
62 |
63 | Player: just now, can you help plz
64 |
65 | [Owner runs /sync snapshot restore Player]
66 |
67 | [Player gets restored to the latest snapshot]
68 |
69 | Player: thanks!
70 | ```
71 |
72 | - Browse through snapshots by date and restore, edit or delete it (separate permissions for viewing and editing)
73 |
74 | ## Optimize backups
75 |
76 | _MSDataSync_ automatically deletes old snapshots for optimal storage efficiency. The default optimization strategy will:
77 | - Keep all snapshots within the last hour
78 | - Keep up to one snapshot per hour for the last 24 hours (not including the first hour)
79 | - Keep up to one snapshot per day for the last 7 days (not including the first day)
80 | - Delete all snapshots older than 7 days
81 |
82 | ## Comes with child lock
83 |
84 | Don't you hate running dangerous commands by accident! Me too.
85 | We included a child lock so you would be slightly less likely to accidentally break stuff!
86 | - `/sync lock []`
87 |
88 | ## Reload command actually works
89 |
90 | Changed any settings? Just run `/sync reload` and the plugin will reload
91 | - Database connection gets reopened (with updated db settings from config)
92 | - Sync task is restarted (with updated settings from config)
93 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | java
3 | }
4 |
5 | allprojects {
6 | group = "org.anvilpowered"
7 | version = "0.8.1-SNAPSHOT"
8 | }
9 |
10 | subprojects {
11 | apply(plugin = "java")
12 | java {
13 | sourceCompatibility = JavaVersion.VERSION_1_8
14 | targetCompatibility = JavaVersion.VERSION_1_8
15 | }
16 | repositories {
17 | mavenCentral()
18 | maven("https://oss.sonatype.org/content/repositories/snapshots")
19 | maven("https://repo.spongepowered.org/maven")
20 | maven("https://jetbrains.bintray.com/xodus")
21 | }
22 | dependencies {
23 | testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.0")
24 | testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.0")
25 | compileOnly("org.anvilpowered:anvil-api:0.3") {
26 | exclude(group = "org.jetbrains.xodus")
27 | }
28 | implementation("org.jetbrains.xodus:xodus-openAPI:1.3.232")
29 | }
30 | // test {
31 | // useJUnitPlatform()
32 | // }
33 | // if (project.hasProperty("buildNumber") && version.toString().contains("-SNAPSHOT")) {
34 | // version = version.toString().replace("-SNAPSHOT", "-RC${buildNumber}")
35 | // }
36 | }
37 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/DataSync.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api;
20 |
21 | import com.google.common.base.Preconditions;
22 | import com.google.inject.Injector;
23 | import com.google.inject.Module;
24 | import org.anvilpowered.anvil.api.Environment;
25 | import org.anvilpowered.anvil.api.registry.Registry;
26 | import org.anvilpowered.anvil.base.plugin.BasePlugin;
27 |
28 | public class DataSync extends BasePlugin {
29 |
30 | protected static Environment environment;
31 | private static final String NOT_LOADED = "DataSync has not been loaded yet!";
32 |
33 | DataSync(String name, Injector injector, Module module) {
34 | super(name, injector, module);
35 | }
36 |
37 | public static Environment getEnvironment() {
38 | return Preconditions.checkNotNull(environment, NOT_LOADED);
39 | }
40 |
41 | public static Registry getRegistry() {
42 | return getEnvironment().getInjector().getInstance(Registry.class);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/key/DataKeyService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.key;
20 |
21 | import java.util.Optional;
22 |
23 | public interface DataKeyService {
24 |
25 | void addMapping(K key, String name);
26 |
27 | void removeMapping(K key);
28 |
29 | Optional getName(K key);
30 | }
31 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/member/MemberManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.member;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Manager;
22 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
23 | import org.checkerframework.checker.nullness.qual.Nullable;
24 |
25 | import java.util.UUID;
26 | import java.util.concurrent.CompletableFuture;
27 |
28 | public interface MemberManager
29 | extends Manager> {
30 |
31 | @Override
32 | default String getDefaultIdentifierSingularUpper() {
33 | return "Member";
34 | }
35 |
36 | @Override
37 | default String getDefaultIdentifierPluralUpper() {
38 | return "Members";
39 | }
40 |
41 | @Override
42 | default String getDefaultIdentifierSingularLower() {
43 | return "member";
44 | }
45 |
46 | @Override
47 | default String getDefaultIdentifierPluralLower() {
48 | return "members";
49 | }
50 |
51 | CompletableFuture deleteSnapshot(UUID userUUID, @Nullable String snapshot);
52 |
53 | TString info(UUID userUUID, Snapshot> snapshot);
54 |
55 | CompletableFuture info(UUID userUUID, @Nullable String snapshot);
56 |
57 | CompletableFuture> list(UUID userUUID);
58 | }
59 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/member/MemberRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.member;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Repository;
22 | import org.anvilpowered.datasync.api.model.member.Member;
23 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
24 | import org.checkerframework.checker.nullness.qual.Nullable;
25 |
26 | import java.time.Instant;
27 | import java.util.List;
28 | import java.util.Optional;
29 | import java.util.UUID;
30 | import java.util.concurrent.CompletableFuture;
31 |
32 | public interface MemberRepository<
33 | TKey,
34 | TDataStore>
35 | extends Repository, TDataStore> {
36 |
37 | /**
38 | * Gets the corresponding {@code Member} from the database.
39 | * If not present, creates a new one and saves it to the database
40 | *
41 | * @param userUUID Mojang issued {@code uuid} of {@code User} to getRequiredRankIndex corresponding {@code Member}
42 | * @return a ready-to-use {@code Member} that corresponds with the given {@code uuid}
43 | */
44 | CompletableFuture>> getOneOrGenerateForUser(UUID userUUID);
45 |
46 | CompletableFuture>> getOneForUser(UUID userUUID);
47 |
48 | CompletableFuture> getIdForUser(UUID userUUID);
49 |
50 | CompletableFuture> getUUID(TKey id);
51 |
52 | CompletableFuture> getSnapshotIds(TKey id);
53 |
54 | CompletableFuture> getSnapshotIdsForUser(UUID userUUID);
55 |
56 | CompletableFuture> getSnapshotCreationTimes(TKey id);
57 |
58 | CompletableFuture> getSnapshotCreationTimesForUser(UUID userUUID);
59 |
60 | CompletableFuture deleteSnapshot(TKey id, TKey snapshotId);
61 |
62 | CompletableFuture deleteSnapshot(TKey id, Instant createdUtc);
63 |
64 | CompletableFuture deleteSnapshotForUser(UUID userUUID, TKey snapshotId);
65 |
66 | CompletableFuture deleteSnapshotForUser(UUID userUUID, Instant createdUtc);
67 |
68 | CompletableFuture addSnapshot(TKey id, TKey snapshotId);
69 |
70 | CompletableFuture addSnapshotForUser(UUID userUUID, TKey snapshotId);
71 |
72 | CompletableFuture>> getSnapshot(TKey id, Instant createdUtc);
73 |
74 | CompletableFuture>> getSnapshotForUser(UUID userUUID, Instant createdUtc);
75 |
76 | CompletableFuture>> getSnapshot(TKey id, @Nullable String snapshot);
77 |
78 | CompletableFuture>> getSnapshotForUser(UUID userUUID,
79 | @Nullable String snapshot);
80 |
81 | CompletableFuture> getClosestSnapshots(TKey id, Instant createdUtc);
82 |
83 | CompletableFuture> getClosestSnapshotsForUser(UUID userUUID, Instant createdUtc);
84 |
85 | CompletableFuture>> getLatestSnapshot(TKey id);
86 |
87 | CompletableFuture>> getLatestSnapshotForUser(UUID userUUID);
88 |
89 | CompletableFuture>> getPrevious(TKey id, TKey snapshotId);
90 |
91 | CompletableFuture>> getPreviousForUser(UUID userUUID, TKey snapshotId);
92 |
93 | CompletableFuture>> getPreviousForUser(UUID userUUID, Instant createdUtc);
94 |
95 | CompletableFuture>> getNext(TKey id, TKey snapshotId);
96 |
97 | CompletableFuture>> getNextForUser(UUID userUUID, TKey snapshotId);
98 |
99 | CompletableFuture>> getNextForUser(UUID userUUID, Instant createdUtc);
100 |
101 | CompletableFuture setSkipDeserialization(TKey id, boolean skipDeserialization);
102 | }
103 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/member/MongoMemberRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.member;
20 |
21 | import dev.morphia.Datastore;
22 | import dev.morphia.query.Query;
23 | import org.anvilpowered.anvil.api.datastore.MongoRepository;
24 | import org.anvilpowered.datasync.api.model.member.Member;
25 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
26 | import org.bson.types.ObjectId;
27 |
28 | import java.time.Instant;
29 | import java.util.List;
30 | import java.util.Optional;
31 | import java.util.UUID;
32 | import java.util.concurrent.CompletableFuture;
33 |
34 | public interface MongoMemberRepository
35 | extends MemberRepository,
36 | MongoRepository> {
37 |
38 | CompletableFuture> getSnapshotIds(Query> query);
39 |
40 | CompletableFuture> getSnapshotCreationTimes(Query> query);
41 |
42 | CompletableFuture deleteSnapshot(Query> query, ObjectId snapshotId);
43 |
44 | CompletableFuture deleteSnapshot(Query> query, Instant createdUtc);
45 |
46 | CompletableFuture addSnapshot(Query> query, ObjectId snapshotId);
47 |
48 | CompletableFuture>> getSnapshot(Query> query, Instant createdUtc);
49 |
50 | CompletableFuture> getClosestSnapshots(Query> query, Instant createdUtc);
51 |
52 | Query> asQuery(UUID userUUID);
53 | }
54 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/member/XodusMemberRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.member;
20 |
21 | import jetbrains.exodus.entitystore.Entity;
22 | import jetbrains.exodus.entitystore.EntityId;
23 | import jetbrains.exodus.entitystore.PersistentEntityStore;
24 | import jetbrains.exodus.entitystore.StoreTransaction;
25 | import org.anvilpowered.anvil.api.datastore.XodusRepository;
26 | import org.anvilpowered.datasync.api.model.member.Member;
27 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
28 |
29 | import java.time.Instant;
30 | import java.util.List;
31 | import java.util.Optional;
32 | import java.util.UUID;
33 | import java.util.concurrent.CompletableFuture;
34 | import java.util.function.Function;
35 |
36 | public interface XodusMemberRepository
37 | extends MemberRepository,
38 | XodusRepository> {
39 |
40 | CompletableFuture> getSnapshotIds(Function super StoreTransaction, ? extends Iterable> query);
41 |
42 | CompletableFuture> getSnapshotCreationTimes(Function super StoreTransaction, ? extends Iterable> query);
43 |
44 | CompletableFuture deleteSnapshot(Function super StoreTransaction, ? extends Iterable> query, EntityId snapshotId);
45 |
46 | CompletableFuture deleteSnapshot(Function super StoreTransaction, ? extends Iterable> query, Instant createdUtc);
47 |
48 | CompletableFuture addSnapshot(Function super StoreTransaction, ? extends Iterable> query, EntityId snapshotId);
49 |
50 | CompletableFuture>> getSnapshot(Function super StoreTransaction, ? extends Iterable> query, Instant createdUtc);
51 |
52 | CompletableFuture> getClosestSnapshots(Function super StoreTransaction, ? extends Iterable> query, Instant createdUtc);
53 |
54 | Function super StoreTransaction, ? extends Iterable> asQuery(UUID userUUID);
55 | }
56 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/misc/SyncUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.misc;
20 |
21 | import java.util.List;
22 | import java.util.Optional;
23 |
24 | public interface SyncUtils {
25 |
26 | Optional> decodeOptimizationStrategy(List> list);
27 | }
28 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/model/member/Member.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.model.member;
20 |
21 | import org.anvilpowered.anvil.api.model.ObjectWithId;
22 |
23 | import java.util.List;
24 | import java.util.UUID;
25 |
26 | public interface Member extends ObjectWithId {
27 |
28 | UUID getUserUUID();
29 | void setUserUUID(UUID userUUID);
30 |
31 | List getSnapshotIds();
32 | void setSnapshotIds(List snapshotIds);
33 |
34 | boolean isSkipDeserialization();
35 | void setSkipDeserialization(boolean skipDeserialization);
36 | }
37 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/model/snapshot/Snapshot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.model.snapshot;
20 |
21 | import org.anvilpowered.anvil.api.model.ObjectWithId;
22 |
23 | import java.util.List;
24 | import java.util.Map;
25 |
26 | public interface Snapshot extends ObjectWithId {
27 |
28 | String getName();
29 | void setName(String name);
30 |
31 | String getServer();
32 | void setServer(String server);
33 |
34 | List getModulesUsed();
35 | void setModulesUsed(List modulesUsed);
36 |
37 | List getModulesFailed();
38 | void setModulesFailed(List modulesFailed);
39 |
40 | Map getKeys();
41 | void setKeys(Map keys);
42 |
43 | byte[] getInventory();
44 | void setInventory(byte[] inventory);
45 | }
46 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/ExperienceSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | public interface ExperienceSerializer
22 | extends Serializer {
23 | }
24 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/GameModeSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | public interface GameModeSerializer
22 | extends Serializer {
23 | }
24 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/HealthSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | public interface HealthSerializer
22 | extends Serializer {
23 | }
24 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/HungerSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | public interface HungerSerializer
22 | extends Serializer {
23 | }
24 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/InventorySerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
22 |
23 | public interface InventorySerializer<
24 | TUser,
25 | TInventory,
26 | TItemStackSnapshot>
27 | extends Serializer {
28 |
29 | /**
30 | * Moves data from {@code inventory} into {@code member}
31 | *
32 | * @param snapshot {@link Snapshot} to add data to
33 | * @param inventory Player to get data from
34 | * @param maxSlots Maximum number of slots that will get serialized
35 | * @return Whether serialization was successful
36 | */
37 | boolean serializeInventory(Snapshot> snapshot, TInventory inventory, int maxSlots);
38 |
39 | /**
40 | * Moves data from {@code inventory} into {@code member}
41 | *
42 | * @param snapshot {@link Snapshot} to add data to
43 | * @param inventory Player to get data from
44 | * @return Whether serialization was successful
45 | */
46 | boolean serializeInventory(Snapshot> snapshot, TInventory inventory);
47 |
48 | /**
49 | * Moves data from {@code member} into {@code inventory}
50 | *
51 | * @param snapshot {@link Snapshot} to get data from
52 | * @param inventory Player to add data to
53 | * @param fallbackItemStackSnapshot Item stack to put into unused slots. To be made uneditable
54 | * @return Whether deserialization was successful
55 | */
56 | boolean deserializeInventory(Snapshot> snapshot, TInventory inventory, TItemStackSnapshot fallbackItemStackSnapshot);
57 |
58 | /**
59 | * Moves data from {@code member} into {@code inventory}
60 | *
61 | * @param snapshot {@link Snapshot} to get data from
62 | * @param inventory Player to add data to
63 | * @return Whether deserialization was successful
64 | */
65 | boolean deserializeInventory(Snapshot> snapshot, TInventory inventory);
66 |
67 | TItemStackSnapshot getDefaultFallbackItemStackSnapshot();
68 |
69 | TItemStackSnapshot getExitWithoutSavingItemStackSnapshot();
70 | }
71 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/Serializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
22 |
23 | public interface Serializer {
24 |
25 | /**
26 | * @return Name of {@link Serializer}.
27 | * Should follow format "plugin:name"
28 | * For example "datasync:inventory"
29 | */
30 | String getName();
31 |
32 | /**
33 | * Moves data from {@code player} into {@code member}
34 | *
35 | * @param snapshot {@link Snapshot} to add data to
36 | * @param user User to get data from
37 | * @return Whether serialization was successful
38 | */
39 | boolean serialize(Snapshot> snapshot, TUser user);
40 |
41 | /**
42 | * Moves data from {@code member} into {@code player}
43 | *
44 | * @param snapshot {@link Snapshot} to get data from
45 | * @param user User to add data to
46 | * @return Whether deserialization was successful
47 | */
48 | boolean deserialize(Snapshot> snapshot, TUser user);
49 | }
50 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/SnapshotSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer;
20 |
21 | public interface SnapshotSerializer
22 | extends Serializer {
23 |
24 | void registerSerializer(Serializer serializer);
25 |
26 | boolean isSerializerEnabled(String name);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/user/UserSerializerComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer.user;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Component;
22 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
23 | import org.anvilpowered.datasync.api.serializer.Serializer;
24 |
25 | import java.util.Optional;
26 | import java.util.concurrent.CompletableFuture;
27 |
28 | public interface UserSerializerComponent<
29 | TKey,
30 | TUser,
31 | TDataStore>
32 | extends Component,
33 | Serializer {
34 |
35 | CompletableFuture>> serialize(TUser user, String name);
36 |
37 | CompletableFuture>> deserialize(TUser user, CompletableFuture waitFuture);
38 | }
39 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/user/UserSerializerManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer.user;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Manager;
22 | import org.checkerframework.checker.nullness.qual.Nullable;
23 |
24 | import java.util.Collection;
25 | import java.util.UUID;
26 | import java.util.concurrent.CompletableFuture;
27 |
28 | public interface UserSerializerManager<
29 | TUser,
30 | TString>
31 | extends Manager> {
32 |
33 | @Override
34 | default String getDefaultIdentifierSingularUpper() {
35 | return "User serializer";
36 | }
37 |
38 | @Override
39 | default String getDefaultIdentifierPluralUpper() {
40 | return "User serializers";
41 | }
42 |
43 | @Override
44 | default String getDefaultIdentifierSingularLower() {
45 | return "user serializer";
46 | }
47 |
48 | @Override
49 | default String getDefaultIdentifierPluralLower() {
50 | return "user serializers";
51 | }
52 |
53 | CompletableFuture serialize(Collection extends TUser> users);
54 |
55 | CompletableFuture serialize(TUser user, String name);
56 |
57 | CompletableFuture serialize(TUser user);
58 |
59 | CompletableFuture serializeSafe(TUser user, String name);
60 |
61 | CompletableFuture deserialize(TUser user, String event, CompletableFuture waitFuture);
62 |
63 | CompletableFuture deserialize(TUser user, String event);
64 |
65 | CompletableFuture deserialize(TUser user);
66 |
67 | CompletableFuture deserializeJoin(TUser user);
68 |
69 | CompletableFuture restore(UUID userUUID, @Nullable String snapshot);
70 | }
71 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/serializer/user/UserTransitCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.serializer.user;
20 |
21 | import java.util.UUID;
22 | import java.util.concurrent.CompletableFuture;
23 |
24 | /**
25 | * All methods are thread-safe
26 | */
27 | public interface UserTransitCache {
28 |
29 | /**
30 | * Declares that the user with the provided {@link UUID} has started the joining process.
31 | *
32 | * @param userUUID The {@link UUID} of the joining user
33 | * @param waitFuture A future that returns {@code true} when the player is ready to be deserialized, otherwise {@code false}
34 | */
35 | void joinStart(UUID userUUID, CompletableFuture waitFuture);
36 |
37 | /**
38 | * Declares that the user with the provided {@link UUID} has ended the joining process.
39 | *
40 | * @param userUUID The {@link UUID} of the joining user
41 | */
42 | void joinEnd(UUID userUUID);
43 |
44 | /**
45 | * Check whether the user with the provided {@link UUID} is in the process of joining.
46 | *
47 | * @param userUUID The {@link UUID} of the user to check
48 | * @return Whether the user with the provided {@link UUID} is in the process of joining
49 | */
50 | boolean isJoining(UUID userUUID);
51 | }
52 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/snapshot/SnapshotManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.snapshot;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Manager;
22 |
23 | public interface SnapshotManager extends Manager> {
24 |
25 | @Override
26 | default String getDefaultIdentifierSingularUpper() {
27 | return "Snapshot";
28 | }
29 |
30 | @Override
31 | default String getDefaultIdentifierPluralUpper() {
32 | return "Snapshots";
33 | }
34 |
35 | @Override
36 | default String getDefaultIdentifierSingularLower() {
37 | return "snapshot";
38 | }
39 |
40 | @Override
41 | default String getDefaultIdentifierPluralLower() {
42 | return "snapshots";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/snapshot/SnapshotRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.snapshot;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Repository;
22 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
23 |
24 | import java.util.Optional;
25 | import java.util.concurrent.CompletableFuture;
26 |
27 | public interface SnapshotRepository<
28 | TKey,
29 | TDataKey,
30 | TDataStore>
31 | extends Repository, TDataStore> {
32 |
33 | boolean setSnapshotValue(Snapshot> snapshot, TDataKey key, Optional> optionalValue);
34 |
35 | Optional> getSnapshotValue(Snapshot> snapshot, TDataKey key);
36 |
37 | CompletableFuture setInventory(TKey id, byte[] inventory);
38 |
39 | CompletableFuture parseAndSetInventory(Object id, byte[] inventory);
40 | }
41 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/snapshotoptimization/SnapshotOptimizationManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.snapshotoptimization;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Manager;
22 |
23 | public interface SnapshotOptimizationManager<
24 | TUser,
25 | TString,
26 | TCommandSource>
27 | extends Manager> {
28 |
29 | @Override
30 | default String getDefaultIdentifierSingularUpper() {
31 | return "Snapshot optimization";
32 | }
33 |
34 | @Override
35 | default String getDefaultIdentifierPluralUpper() {
36 | return "Snapshot optimizations";
37 | }
38 |
39 | @Override
40 | default String getDefaultIdentifierSingularLower() {
41 | return "snapshot optimization";
42 | }
43 |
44 | @Override
45 | default String getDefaultIdentifierPluralLower() {
46 | return "snapshot optimizations";
47 | }
48 |
49 | TString info();
50 |
51 | TString stop();
52 | }
53 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/snapshotoptimization/SnapshotOptimizationService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.snapshotoptimization;
20 |
21 | import org.anvilpowered.anvil.api.datastore.Component;
22 |
23 | import java.util.Collection;
24 | import java.util.UUID;
25 |
26 | public interface SnapshotOptimizationService<
27 | TKey,
28 | TUser,
29 | TCommandSource,
30 | TDataStore>
31 | extends Component {
32 |
33 | int getTotalMembers();
34 |
35 | int getMembersCompleted();
36 |
37 | int getSnapshotsDeleted();
38 |
39 | int getSnapshotsUploaded();
40 |
41 | boolean isOptimizationTaskRunning();
42 |
43 | boolean stopOptimizationTask();
44 |
45 | void addLockedPlayer(final UUID uuid);
46 |
47 | void removeLockedPlayer(final UUID uuid);
48 |
49 | boolean optimize(final Collection extends TUser> users, final TCommandSource source, final String name);
50 |
51 | boolean optimize(final TCommandSource source);
52 | }
53 |
--------------------------------------------------------------------------------
/datasync-api/src/main/java/org/anvilpowered/datasync/api/task/SerializationTaskService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api.task;
20 |
21 | public interface SerializationTaskService {
22 |
23 | /**
24 | * Starts serialization task
25 | */
26 | void startSerializationTask();
27 |
28 | /**
29 | * Stops serialization task
30 | */
31 | void stopSerializationTask();
32 |
33 | /**
34 | * @return Serialization task
35 | */
36 | Runnable getSerializationTask();
37 | }
38 |
--------------------------------------------------------------------------------
/datasync-common/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | implementation project(':datasync-api')
3 | implementation configurate_hocon
4 | }
5 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/api/DataSyncImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.api;
20 |
21 | import com.google.common.reflect.TypeToken;
22 | import com.google.inject.Injector;
23 | import com.google.inject.Module;
24 | import org.anvilpowered.anvil.api.Environment;
25 | import org.anvilpowered.datasync.api.key.DataKeyService;
26 | import org.anvilpowered.datasync.api.task.SerializationTaskService;
27 | import org.anvilpowered.datasync.common.plugin.DataSyncPluginInfo;
28 |
29 | @SuppressWarnings("UnstableApiUsage")
30 | public class DataSyncImpl extends DataSync {
31 |
32 | protected DataSyncImpl(Injector injector, Module module) {
33 | super(DataSyncPluginInfo.id, injector, module);
34 | }
35 |
36 | protected void applyToBuilder(Environment.Builder builder) {
37 | builder.addEarlyServices(
38 | new TypeToken>(getClass()) {
39 | })
40 | .addEarlyServices(SerializationTaskService.class)
41 | .withRootCommand();
42 | }
43 |
44 | @Override
45 | protected void whenReady(Environment environment) {
46 | super.whenReady(environment);
47 | DataSync.environment = environment;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/command/CommonSyncCommandNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.command;
20 |
21 | import com.google.inject.Inject;
22 | import org.anvilpowered.anvil.api.Environment;
23 | import org.anvilpowered.anvil.api.command.CommandNode;
24 | import org.anvilpowered.anvil.api.command.CommandService;
25 | import org.anvilpowered.anvil.api.registry.Registry;
26 | import org.anvilpowered.datasync.common.plugin.DataSyncPluginInfo;
27 |
28 | import java.util.Arrays;
29 | import java.util.Collections;
30 | import java.util.HashMap;
31 | import java.util.List;
32 | import java.util.Map;
33 | import java.util.Objects;
34 | import java.util.function.Function;
35 | import java.util.function.Predicate;
36 |
37 | public abstract class CommonSyncCommandNode
38 | implements CommandNode {
39 |
40 | protected static final List LOCK_ALIAS = Arrays.asList("lock", "l");
41 | protected static final List RELOAD_ALIAS = Collections.singletonList("reload");
42 | protected static final List TEST_ALIAS = Collections.singletonList("test");
43 | protected static final List UPLOAD_ALIAS = Arrays.asList("upload", "up");
44 | protected static final List HELP_ALIAS = Collections.singletonList("help");
45 | protected static final List VERSION_ALIAS = Collections.singletonList("version");
46 |
47 | protected static final String LOCK_DESCRIPTION = "Lock / Unlock sensitive commands.";
48 | protected static final String RELOAD_DESCRIPTION = "Reloads DataSync.";
49 | protected static final String TEST_DESCRIPTION = "Uploads and then downloads a snapshot.";
50 | protected static final String UPLOAD_DESCRIPTION = "Uploads all players on server.";
51 | protected static final String HELP_DESCRIPTION = "Shows this help page.";
52 | protected static final String VERSION_DESCRIPTION = "Shows plugin version.";
53 | protected static final String ROOT_DESCRIPTION
54 | = String.format("%s root command", DataSyncPluginInfo.name);
55 |
56 | protected static final String RELOAD_USAGE = "[-a|--all|-r|--regex] [plugin]";
57 |
58 | protected static final String HELP_COMMAND = "/datasync help";
59 |
60 | public static String[] SYNC_PATH = new String[]{"sync"};
61 |
62 | private boolean alreadyLoaded;
63 | protected Map, Function> descriptions;
64 | protected Map, Predicate> permissions;
65 | protected Map, Function> usages;
66 |
67 | @Inject
68 | protected CommandService commandService;
69 |
70 | @Inject
71 | protected Environment environment;
72 |
73 | protected Registry registry;
74 |
75 | protected CommonSyncCommandNode(Registry registry) {
76 | this.registry = registry;
77 | registry.whenLoaded(() -> {
78 | if (alreadyLoaded) return;
79 | loadCommands();
80 | alreadyLoaded = true;
81 | }).register();
82 | alreadyLoaded = false;
83 | descriptions = new HashMap<>();
84 | permissions = new HashMap<>();
85 | usages = new HashMap<>();
86 | descriptions.put(LOCK_ALIAS, c -> LOCK_DESCRIPTION);
87 | descriptions.put(RELOAD_ALIAS, c -> RELOAD_DESCRIPTION);
88 | descriptions.put(TEST_ALIAS, c -> TEST_DESCRIPTION);
89 | descriptions.put(UPLOAD_ALIAS, c -> UPLOAD_DESCRIPTION);
90 | descriptions.put(HELP_ALIAS, c -> HELP_DESCRIPTION);
91 | descriptions.put(VERSION_ALIAS, c -> VERSION_DESCRIPTION);
92 | usages.put(RELOAD_ALIAS, c -> RELOAD_USAGE);
93 | }
94 |
95 | protected abstract void loadCommands();
96 |
97 | private static final String ERROR_MESSAGE = "Sync command has not been loaded yet";
98 |
99 | @Override
100 | public Map, Function> getDescriptions() {
101 | return Objects.requireNonNull(descriptions, ERROR_MESSAGE);
102 | }
103 |
104 | @Override
105 | public Map, Predicate> getPermissions() {
106 | return Objects.requireNonNull(permissions, ERROR_MESSAGE);
107 | }
108 |
109 | @Override
110 | public Map, Function> getUsages() {
111 | return Objects.requireNonNull(usages, ERROR_MESSAGE);
112 | }
113 |
114 | @Override
115 | public String getName() {
116 | return DataSyncPluginInfo.id;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/command/optimize/CommonOptimizeCommandNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.command.optimize;
20 |
21 | import com.google.inject.Inject;
22 | import org.anvilpowered.anvil.api.command.CommandNode;
23 | import org.anvilpowered.anvil.api.command.CommandService;
24 | import org.anvilpowered.anvil.api.registry.Registry;
25 | import org.anvilpowered.datasync.common.command.CommonSyncCommandNode;
26 | import org.anvilpowered.datasync.common.plugin.DataSyncPluginInfo;
27 |
28 | import java.util.Arrays;
29 | import java.util.Collections;
30 | import java.util.HashMap;
31 | import java.util.List;
32 | import java.util.Map;
33 | import java.util.Objects;
34 | import java.util.function.Function;
35 | import java.util.function.Predicate;
36 |
37 | public abstract class CommonOptimizeCommandNode
38 | implements CommandNode {
39 |
40 | protected static final List START_ALIAS = Arrays.asList("start", "s");
41 | protected static final List INFO_ALIAS = Arrays.asList("info", "i");
42 | protected static final List STOP_ALIAS = Collections.singletonList("stop");
43 | protected static final List HELP_ALIAS = Collections.singletonList("help");
44 |
45 | protected static final String START_DESCRIPTION
46 | = "Starts manual optimization, deletes old snapshots.";
47 | protected static final String INFO_DESCRIPTION
48 | = "Gets info on current manual optimization.";
49 | protected static final String STOP_DESCRIPTION
50 | = "Stops current manual optimization.";
51 | protected static final String HELP_DESCRIPTION
52 | = "Shows this help page.";
53 | protected static final String ROOT_DESCRIPTION
54 | = "Optimize base command. (To delete old snapshots)";
55 |
56 | protected static final String START_USAGE = "all|user []";
57 |
58 | protected static final String HELP_COMMAND = "/sync optimize help";
59 |
60 | private boolean alreadyLoaded;
61 | protected Map, Function> descriptions;
62 | protected Map, Predicate> permissions;
63 | protected Map, Function> usages;
64 |
65 | @Inject
66 | protected CommandService commandService;
67 |
68 | protected Registry registry;
69 |
70 | protected CommonOptimizeCommandNode(Registry registry) {
71 | this.registry = registry;
72 | registry.whenLoaded(() -> {
73 | if (alreadyLoaded) return;
74 | loadCommands();
75 | alreadyLoaded = true;
76 | }).register();
77 | alreadyLoaded = false;
78 | descriptions = new HashMap<>();
79 | permissions = new HashMap<>();
80 | usages = new HashMap<>();
81 | descriptions.put(START_ALIAS, c -> START_DESCRIPTION);
82 | descriptions.put(INFO_ALIAS, c -> INFO_DESCRIPTION);
83 | descriptions.put(STOP_ALIAS, c -> STOP_DESCRIPTION);
84 | descriptions.put(HELP_ALIAS, c -> HELP_DESCRIPTION);
85 | usages.put(START_ALIAS, c -> START_USAGE);
86 | }
87 |
88 | protected abstract void loadCommands();
89 |
90 | private static final String ERROR_MESSAGE = "Sync command has not been loaded yet";
91 |
92 | @Override
93 | public Map, Function> getDescriptions() {
94 | return Objects.requireNonNull(descriptions, ERROR_MESSAGE);
95 | }
96 |
97 | @Override
98 | public Map, Predicate> getPermissions() {
99 | return Objects.requireNonNull(permissions, ERROR_MESSAGE);
100 | }
101 |
102 | @Override
103 | public Map, Function> getUsages() {
104 | return Objects.requireNonNull(usages, ERROR_MESSAGE);
105 | }
106 |
107 | @Override
108 | public String getName() {
109 | return DataSyncPluginInfo.id;
110 | }
111 |
112 | @Override
113 | public String[] getPath() {
114 | return CommonSyncCommandNode.SYNC_PATH;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/key/CommonDataKeyService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.key;
20 |
21 | import org.anvilpowered.datasync.api.key.DataKeyService;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 | import java.util.Optional;
26 |
27 | public abstract class CommonDataKeyService implements DataKeyService {
28 |
29 | private Map nameMap;
30 |
31 | public CommonDataKeyService() {
32 | nameMap = new HashMap<>();
33 | }
34 |
35 | @Override
36 | public void addMapping(K key, String name) {
37 | if (key != null && name != null) nameMap.put(key, name);
38 | }
39 |
40 | @Override
41 | public void removeMapping(K key) {
42 | nameMap.remove(key);
43 | }
44 |
45 | @Override
46 | public Optional getName(K key) {
47 | return Optional.ofNullable(nameMap.get(key));
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/misc/CommonSyncUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.misc;
20 |
21 | import org.anvilpowered.datasync.api.misc.SyncUtils;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 | import java.util.Optional;
26 |
27 | public class CommonSyncUtils implements SyncUtils {
28 |
29 | @Override
30 | public Optional> decodeOptimizationStrategy(List> list) {
31 | List numsList = new ArrayList<>();
32 |
33 | // check format
34 | if (list.stream().anyMatch(s -> {
35 | if (!(s instanceof String)) return true;
36 | String[] snums = ((String) s).split("[:]");
37 | if (snums.length != 2) return true;
38 | int[] nums = new int[2];
39 | try {
40 | nums[0] = Integer.parseInt(snums[0]);
41 | nums[1] = Integer.parseInt(snums[1]);
42 | } catch (NumberFormatException e) {
43 | e.printStackTrace();
44 | return true;
45 | }
46 | if (nums[0] < 0 || nums[1] < 0) return true;
47 | numsList.add(nums);
48 | return false;
49 | }
50 | )) {
51 | return Optional.empty();
52 | }
53 |
54 | for (int i = 0; i < numsList.size() - 1; i++) {
55 | if (numsList.get(i + 1)[0] != numsList.get(i)[0] * numsList.get(i)[1]) {
56 | return Optional.empty();
57 | }
58 | }
59 | return Optional.of(numsList);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/model/member/MongoMember.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.model.member;
20 |
21 | import com.google.common.base.Preconditions;
22 | import dev.morphia.annotations.Entity;
23 | import org.anvilpowered.anvil.base.model.MongoDbo;
24 | import org.anvilpowered.datasync.api.model.member.Member;
25 | import org.bson.types.ObjectId;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 | import java.util.UUID;
30 |
31 | @Entity("members")
32 | public class MongoMember extends MongoDbo implements Member {
33 |
34 | private UUID userUUID;
35 | private boolean skipDeserialization;
36 | private List snapshotIds;
37 |
38 | @Override
39 | public UUID getUserUUID() {
40 | return userUUID;
41 | }
42 |
43 | @Override
44 | public void setUserUUID(UUID userUUID) {
45 | this.userUUID = userUUID;
46 | }
47 |
48 | @Override
49 | public List getSnapshotIds() {
50 | if (snapshotIds == null) {
51 | snapshotIds = new ArrayList<>();
52 | }
53 | return snapshotIds;
54 | }
55 |
56 | @Override
57 | public void setSnapshotIds(List snapshotIds) {
58 | this.snapshotIds = Preconditions.checkNotNull(snapshotIds, "snapshotIds");
59 | }
60 |
61 | @Override
62 | public boolean isSkipDeserialization() {
63 | return skipDeserialization;
64 | }
65 |
66 | @Override
67 | public void setSkipDeserialization(boolean skipDeserialization) {
68 | this.skipDeserialization = skipDeserialization;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/model/member/XodusMember.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.model.member;
20 |
21 | import com.google.common.base.Preconditions;
22 | import jetbrains.exodus.entitystore.Entity;
23 | import jetbrains.exodus.entitystore.EntityId;
24 | import jetbrains.exodus.util.ByteArraySizedInputStream;
25 | import org.anvilpowered.anvil.api.datastore.XodusEntity;
26 | import org.anvilpowered.anvil.api.model.Mappable;
27 | import org.anvilpowered.anvil.base.model.XodusDbo;
28 | import org.anvilpowered.datasync.api.model.member.Member;
29 |
30 | import java.io.IOException;
31 | import java.util.ArrayList;
32 | import java.util.List;
33 | import java.util.UUID;
34 |
35 | @XodusEntity
36 | public class XodusMember extends XodusDbo implements Member, Mappable {
37 |
38 | private String userUUID;
39 | private boolean skipDeserialization;
40 | private List snapshotIds;
41 |
42 | @Override
43 | public UUID getUserUUID() {
44 | return UUID.fromString(userUUID);
45 | }
46 |
47 | @Override
48 | public void setUserUUID(UUID userUUID) {
49 | this.userUUID = userUUID.toString();
50 | prePersist();
51 | }
52 |
53 | @Override
54 | public List getSnapshotIds() {
55 | if (snapshotIds == null) {
56 | snapshotIds = new ArrayList<>();
57 | }
58 | return snapshotIds;
59 | }
60 |
61 | @Override
62 | public void setSnapshotIds(List snapshotIds) {
63 | this.snapshotIds = Preconditions.checkNotNull(snapshotIds, "snapshotIds");
64 | prePersist();
65 | }
66 |
67 | @Override
68 | public boolean isSkipDeserialization() {
69 | return skipDeserialization;
70 | }
71 |
72 | @Override
73 | public void setSkipDeserialization(boolean skipDeserialization) {
74 | this.skipDeserialization = skipDeserialization;
75 | }
76 |
77 | @Override
78 | public Entity writeTo(Entity object) {
79 | super.writeTo(object);
80 | if (userUUID != null) {
81 | object.setProperty("userUUID", userUUID);
82 | }
83 | if (skipDeserialization) {
84 | object.setProperty("skipDeserialization", true);
85 | }
86 | try {
87 | object.setBlob("snapshotIds",
88 | new ByteArraySizedInputStream(Mappable.serializeUnsafe(getSnapshotIds())));
89 | } catch (IOException e) {
90 | e.printStackTrace();
91 | }
92 | return object;
93 | }
94 |
95 | @Override
96 | public void readFrom(Entity object) {
97 | super.readFrom(object);
98 | Comparable> userUUID = object.getProperty("userUUID");
99 | if (userUUID instanceof String) {
100 | this.userUUID = (String) userUUID;
101 | }
102 | Comparable> skipDeserialization = object.getProperty("skipDeserialization");
103 | if (skipDeserialization instanceof Boolean) {
104 | this.skipDeserialization = (Boolean) skipDeserialization;
105 | }
106 | Mappable.>deserialize(object.getBlob("snapshotIds"))
107 | .ifPresent(t -> snapshotIds = t);
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/model/snapshot/MongoSnapshot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.model.snapshot;
20 |
21 | import com.google.common.base.Preconditions;
22 | import dev.morphia.annotations.Entity;
23 | import org.anvilpowered.anvil.base.model.MongoDbo;
24 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
25 | import org.bson.types.ObjectId;
26 |
27 | import java.util.ArrayList;
28 | import java.util.HashMap;
29 | import java.util.List;
30 | import java.util.Map;
31 |
32 | @Entity("snapshots")
33 | public class MongoSnapshot extends MongoDbo implements Snapshot {
34 |
35 | private String name;
36 |
37 | private String server;
38 |
39 | private List modulesUsed;
40 |
41 | private List modulesFailed;
42 |
43 | private Map keys;
44 |
45 | private byte[] inventory;
46 |
47 | @Override
48 | public String getName() {
49 | return name;
50 | }
51 |
52 | @Override
53 | public void setName(String name) {
54 | this.name = name;
55 | }
56 |
57 | @Override
58 | public String getServer() {
59 | return server;
60 | }
61 |
62 | @Override
63 | public void setServer(String server) {
64 | this.server = server;
65 | }
66 |
67 | @Override
68 | public List getModulesUsed() {
69 | if (modulesUsed == null) {
70 | modulesUsed = new ArrayList<>();
71 | }
72 | return modulesUsed;
73 | }
74 |
75 | @Override
76 | public void setModulesUsed(List modulesUsed) {
77 | this.modulesUsed = Preconditions.checkNotNull(modulesUsed, "modulesUsed");
78 | }
79 |
80 | @Override
81 | public List getModulesFailed() {
82 | if (modulesFailed == null) {
83 | modulesFailed = new ArrayList<>();
84 | }
85 | return modulesFailed;
86 | }
87 |
88 | @Override
89 | public void setModulesFailed(List modulesFailed) {
90 | this.modulesFailed = Preconditions.checkNotNull(modulesFailed, "modulesFailed");
91 | }
92 |
93 | @Override
94 | public Map getKeys() {
95 | if (keys == null) {
96 | keys = new HashMap<>();
97 | }
98 | return keys;
99 | }
100 |
101 | @Override
102 | public void setKeys(Map keys) {
103 | this.keys = Preconditions.checkNotNull(keys, "keys");
104 | }
105 |
106 | @Override
107 | public byte[] getInventory() {
108 | return inventory;
109 | }
110 |
111 | @Override
112 | public void setInventory(byte[] inventory) {
113 | this.inventory = inventory;
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/datasync-common/src/main/java/org/anvilpowered/datasync/common/model/snapshot/XodusSnapshot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * DataSync - AnvilPowered
3 | * Copyright (C) 2020 Cableguy20
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Lesser General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Lesser General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Lesser General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package org.anvilpowered.datasync.common.model.snapshot;
20 |
21 | import com.google.common.base.Preconditions;
22 | import jetbrains.exodus.entitystore.Entity;
23 | import jetbrains.exodus.entitystore.EntityId;
24 | import jetbrains.exodus.util.ByteArraySizedInputStream;
25 | import jetbrains.exodus.util.LightByteArrayOutputStream;
26 | import org.anvilpowered.anvil.api.datastore.XodusEntity;
27 | import org.anvilpowered.anvil.api.model.Mappable;
28 | import org.anvilpowered.anvil.base.model.XodusDbo;
29 | import org.anvilpowered.datasync.api.model.snapshot.Snapshot;
30 |
31 | import java.io.IOException;
32 | import java.io.InputStream;
33 | import java.util.ArrayList;
34 | import java.util.HashMap;
35 | import java.util.List;
36 | import java.util.Map;
37 |
38 | @XodusEntity
39 | public class XodusSnapshot extends XodusDbo implements Snapshot, Mappable {
40 |
41 | private String name;
42 |
43 | private String server;
44 |
45 | private List modulesUsed;
46 |
47 | private List modulesFailed;
48 |
49 | private Map keys;
50 |
51 | private byte[] inventory;
52 |
53 | @Override
54 | public String getName() {
55 | return name;
56 | }
57 |
58 | @Override
59 | public void setName(String name) {
60 | this.name = name;
61 | }
62 |
63 | @Override
64 | public String getServer() {
65 | return server;
66 | }
67 |
68 | @Override
69 | public void setServer(String server) {
70 | this.server = server;
71 | }
72 |
73 | @Override
74 | public List getModulesUsed() {
75 | if (modulesUsed == null) {
76 | modulesUsed = new ArrayList<>();
77 | }
78 | return modulesUsed;
79 | }
80 |
81 | @Override
82 | public void setModulesUsed(List modulesUsed) {
83 | this.modulesUsed = Preconditions.checkNotNull(modulesUsed, "modulesUsed");
84 | }
85 |
86 | @Override
87 | public List getModulesFailed() {
88 | if (modulesFailed == null) {
89 | modulesFailed = new ArrayList<>();
90 | }
91 | return modulesFailed;
92 | }
93 |
94 | @Override
95 | public void setModulesFailed(List modulesFailed) {
96 | this.modulesFailed = Preconditions.checkNotNull(modulesFailed, "modulesFailed");
97 | }
98 |
99 | @Override
100 | public Map getKeys() {
101 | if (keys == null) {
102 | keys = new HashMap<>();
103 | }
104 | return keys;
105 | }
106 |
107 | @Override
108 | public void setKeys(Map keys) {
109 | this.keys = Preconditions.checkNotNull(keys, "keys");
110 | }
111 |
112 | @Override
113 | public byte[] getInventory() {
114 | return inventory;
115 | }
116 |
117 | @Override
118 | public void setInventory(byte[] inventory) {
119 | this.inventory = inventory;
120 | }
121 |
122 | @Override
123 | public Entity writeTo(Entity object) {
124 | super.writeTo(object);
125 | if (name != null) {
126 | object.setProperty("name", name);
127 | }
128 | if (server != null) {
129 | object.setProperty("server", server);
130 | }
131 | try {
132 | object.setBlob("modulesUsed",
133 | new ByteArraySizedInputStream(Mappable.serializeUnsafe(getModulesUsed())));
134 | } catch (IOException e) {
135 | e.printStackTrace();
136 | }
137 | try {
138 | object.setBlob("modulesFailed",
139 | new ByteArraySizedInputStream(Mappable.serializeUnsafe(getModulesFailed())));
140 | } catch (IOException e) {
141 | e.printStackTrace();
142 | }
143 | try {
144 | object.setBlob("keys",
145 | new ByteArraySizedInputStream(Mappable.serializeUnsafe(getKeys())));
146 | } catch (IOException e) {
147 | e.printStackTrace();
148 | }
149 | object.setBlob("inventory",
150 | new ByteArraySizedInputStream(inventory));
151 | return object;
152 | }
153 |
154 | @Override
155 | public void readFrom(Entity object) {
156 | super.readFrom(object);
157 | Comparable> name = object.getProperty("name");
158 | if (name instanceof String) {
159 | this.name = (String) name;
160 | }
161 | Comparable> server = object.getProperty("server");
162 | if (name instanceof String) {
163 | this.server = (String) server;
164 | }
165 | Mappable.>deserialize(object.getBlob("modulesUsed"))
166 | .ifPresent(t -> modulesUsed = t);
167 | Mappable.>deserialize(object.getBlob("modulesFailed"))
168 | .ifPresent(t -> modulesFailed = t);
169 | Mappable.