Skip to content

Commit

Permalink
feat: Initial for Player module, it is a work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
QwQ-dev committed Jan 3, 2025
1 parent 5a7e439 commit 20b4dd6
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -31,7 +32,7 @@
* @see AnnotationProcessor
* @since 2024-12-19 17:00
*/
@InjectableComponent
@InjectableComponent(scope = InjectableScope.PROTOTYPE)
public class AnnotationProcessingService implements AnnotationProcessingServiceInterface {
/**
* {@inheritDoc}
Expand Down
20 changes: 20 additions & 0 deletions player/README.md
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 35 additions & 0 deletions player/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
}
3 changes: 3 additions & 0 deletions player/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# player
package=net.legacy.library.player
name=player
25 changes: 25 additions & 0 deletions player/src/main/java/net/legacy/library/player/PlayerLauncher.java
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ include("annotation")
include("commons")
include("mongodb")
include("cache")
include("player")

0 comments on commit 20b4dd6

Please sign in to comment.