Add persistent player stats and DB support
Introduce MySQL persistence and an in-memory stats system with async saving. - Add HikariCP & MySQL connector dependencies and relocate libs in build.gradle.kts. - Add DatabaseManager (HikariCP) to manage connection pool and lifecycle. - Add PlayerStats data model and PlayerStatsRepository for table creation, reads, upserts and batch upserts (with prepared statements). - Add StatsManager: coroutine-based cache, dirty-flags, async batch saves, auto-save (every 5 minutes), load/save APIs and shutdown save. - Add StatsListener: load on AsyncPlayerPreLoginEvent and save on PlayerQuitEvent. - Wire DB and stats into main plugin: connect on enable (disable plugin on fail), initialize StatsManager, save/disconnect on disable, register leaderboard command and stats listener. - Update GameManager to record kills/wins/deaths and adjust scrimScore on events. - Add LeaderboardCommand and language entries for leaderboard output; expose command in plugin.yml. - Add database configuration section to config.yml. - Minor refactor: KitCommand plugin accessor changed to a getter. These changes provide a robust, pooled DB connection and efficient stats persistence (batched/upserted) to reduce DB load and ensure data safety during shutdown.
This commit is contained in:
@@ -226,6 +226,15 @@ class GameManager(
|
||||
alivePlayers.remove( player.uniqueId )
|
||||
player.gameMode = GameMode.SPECTATOR
|
||||
|
||||
plugin.statsManager.addDeath( player.uniqueId )
|
||||
plugin.statsManager.adjustScrimScore( player.uniqueId, -25 ) // Elo-Verlust
|
||||
|
||||
if ( killer != null )
|
||||
{
|
||||
plugin.statsManager.addKill( killer.uniqueId )
|
||||
plugin.statsManager.adjustScrimScore( killer.uniqueId, +15 ) // Elo-Gewinn
|
||||
}
|
||||
|
||||
player.inventory.contents.filterNotNull().forEach {
|
||||
player.world.dropItemNaturally( player.location, it )
|
||||
}
|
||||
@@ -257,6 +266,17 @@ class GameManager(
|
||||
) {
|
||||
setGameState( GameState.ENDING )
|
||||
timer = 15
|
||||
|
||||
val winnerUUID = alivePlayers.firstOrNull()
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach { p ->
|
||||
if ( p.uniqueId == winnerUUID )
|
||||
{
|
||||
plugin.statsManager.addWin( p.uniqueId )
|
||||
plugin.statsManager.adjustScrimScore( p.uniqueId, +50 ) // Elo-Bonus für Win
|
||||
}
|
||||
}
|
||||
|
||||
plugin.kitManager.clearAll()
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach { p ->
|
||||
|
||||
Reference in New Issue
Block a user