diff --git a/README.md b/README.md index f7749b5..d866846 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ To run the module as a plugin (which is the recommended way), run the `-plugin` - [configuration](configuration/README.md) - [mongodb](mongodb/README.md) - [cache](cache/README.md) +- [player](player/README.md) - In progress - security - Not started yet ## sponsors diff --git a/annotation/src/main/java/net/legacy/library/annotation/service/AnnotationProcessingService.java b/annotation/src/main/java/net/legacy/library/annotation/service/AnnotationProcessingService.java index d4f38f7..8d91738 100644 --- a/annotation/src/main/java/net/legacy/library/annotation/service/AnnotationProcessingService.java +++ b/annotation/src/main/java/net/legacy/library/annotation/service/AnnotationProcessingService.java @@ -3,6 +3,7 @@ import com.google.common.collect.Sets; import io.fairyproject.container.Containers; import io.fairyproject.container.InjectableComponent; +import io.fairyproject.container.scope.InjectableScope; import io.fairyproject.log.Log; import net.legacy.library.annotation.utils.AnnotationScanner; import org.reflections.util.ClasspathHelper; @@ -31,7 +32,7 @@ * @see AnnotationProcessor * @since 2024-12-19 17:00 */ -@InjectableComponent +@InjectableComponent(scope = InjectableScope.PROTOTYPE) public class AnnotationProcessingService implements AnnotationProcessingServiceInterface { /** * {@inheritDoc} diff --git a/player/README.md b/player/README.md new file mode 100644 index 0000000..4423815 --- /dev/null +++ b/player/README.md @@ -0,0 +1,20 @@ +### player + +This module is mainly used for processing player data in a distributed environment. +It includes `L1 (caffeine)` and `L2 (Redis)` cache and ensures data consistency. + +This module will facilitate player data management, rapid development, and no longer need to worry about data consistency issues. + +### process design + +- When the player enters, load the Redis data into Java memory. +- When the player data needs to be updated: + - Use the Redis Streams mechanism to notify other services. + - Each service checks whether the player is online. + - If online, directly update the memory data of the service; otherwise update Redis. +- When the player exits, save the memory data to Redis. +- The scheduled task persists the Redis data to the MongoDB. + +### distributed implementation of scheduled tasks: + +Through the election mechanism, a master node is elected in the distributed system to be responsible for executing scheduled tasks. Other nodes serve as backup nodes and only take over tasks when the master node fails. \ No newline at end of file diff --git a/player/build.gradle.kts b/player/build.gradle.kts new file mode 100644 index 0000000..3fa243d --- /dev/null +++ b/player/build.gradle.kts @@ -0,0 +1,35 @@ +fun properties(key: String) = project.findProperty(key).toString() +fun rootProperties(key: String) = rootProject.findProperty(key).toString() + +group = rootProperties("group") +version = rootProperties("version") + +// Run server +runServer { + version.set(rootProperties("spigot.version")) + javaVersion.set(JavaVersion.VERSION_21) +} + +// Fairy configuration +fairy { + name.set(properties("name")) + mainPackage.set(properties("package")) + fairyPackage.set("io.fairyproject") + + bukkitProperties().depends.add("fairy-lib-plugin") + + bukkitProperties().foliaSupported = true + bukkitProperties().bukkitApi = rootProperties("spigot.version") +} + +// Dependencies +dependencies { + // Annotation module + compileOnly(project(":annotation")) + + // Cache module + compileOnly(project(":cache")) + + // Mongodb module + compileOnly(project(":mongodb")) +} \ No newline at end of file diff --git a/player/gradle.properties b/player/gradle.properties new file mode 100644 index 0000000..d45e5ba --- /dev/null +++ b/player/gradle.properties @@ -0,0 +1,3 @@ +# player +package=net.legacy.library.player +name=player \ No newline at end of file diff --git a/player/src/main/java/net/legacy/library/player/PlayerLauncher.java b/player/src/main/java/net/legacy/library/player/PlayerLauncher.java new file mode 100644 index 0000000..3a3f75b --- /dev/null +++ b/player/src/main/java/net/legacy/library/player/PlayerLauncher.java @@ -0,0 +1,25 @@ +package net.legacy.library.player; + +import io.fairyproject.FairyLaunch; +import io.fairyproject.container.InjectableComponent; +import io.fairyproject.plugin.Plugin; + +/** + * The type Player launcher. + * + * @author qwq-dev + * @since 2025-1-3 14:12 + */ +@FairyLaunch +@InjectableComponent +public class PlayerLauncher extends Plugin { + @Override + public void onPluginEnable() { + // TODO: try get leader from redis + } + + @Override + public void onPluginDisable() { + // TODO: if leader, then save redis data to mongodb + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index ecba20a..a18090f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -12,3 +12,4 @@ include("annotation") include("commons") include("mongodb") include("cache") +include("player")