diff --git a/docs/source/customizing/placeholders.rst b/docs/source/customizing/placeholders.rst index 9adbd9cc7..c02bf3490 100644 --- a/docs/source/customizing/placeholders.rst +++ b/docs/source/customizing/placeholders.rst @@ -41,11 +41,21 @@ Team PlaceHolder Description %blockball_team_players% Current amount of players in the team ================================== ====================================================================== -================================== ====================================================================== +.. note:: Stats tracking is only available in MiniGame mode games. It does not work in HubGame mode games. + +===================================== =================================================================================== Player Placeholder Description -================================== ====================================================================== +===================================== =================================================================================== %blockball_player_isInGame% true if the player is in a game, false if not %blockball_player_isInTeamRed% true if the player is in a game and in team red, false if not %blockball_player_isInTeamBlue% true if the player is in a game and in team blue, false if not -================================== ====================================================================== - +%blockball_player_goals% Amount of goals a player has scored +%blockball_player_games% Amount of games a player has started playing +%blockball_player_gamesFull% Amount of games a player has fully played +%blockball_player_wins% Amount of wins a player has got by playing +%blockball_player_losses% Amount of losses a player has got by playing +%blockball_player_winrate% Ratio between amount of games a player has started playing and wins +%blockball_player_winrateFull% Ratio between amount of games a player has fully played and wins +%blockball_player_goalsPerGame% Ratio between amount of games a player has started playing and scored goals +%blockball_player_goalsPerGameFull% Ratio between amount of games a player has fully played and scored goals +===================================== =================================================================================== diff --git a/src/main/java/com/github/shynixn/blockball/entity/StatsMeta.kt b/src/main/java/com/github/shynixn/blockball/entity/StatsMeta.kt index e4d28e7e4..462a942b3 100644 --- a/src/main/java/com/github/shynixn/blockball/entity/StatsMeta.kt +++ b/src/main/java/com/github/shynixn/blockball/entity/StatsMeta.kt @@ -7,10 +7,15 @@ class StatsMeta { var scoredGoals: Int = 0 /** - * Amount of played games. + * Amount of completed played games. */ var playedGames: Int = 0 + /** + * Amount of games a player has started. + */ + var joinedGames: Int = 0 + /** * Amount of wins. */ diff --git a/src/main/java/com/github/shynixn/blockball/enumeration/PlaceHolder.kt b/src/main/java/com/github/shynixn/blockball/enumeration/PlaceHolder.kt index 699ff557f..a6bae7032 100644 --- a/src/main/java/com/github/shynixn/blockball/enumeration/PlaceHolder.kt +++ b/src/main/java/com/github/shynixn/blockball/enumeration/PlaceHolder.kt @@ -61,13 +61,19 @@ enum class PlaceHolder( PLAYER_STATS_SCOREDGOALS("%blockball_player_goals%"), - PLAYER_STATS_PLAYEDGAMES("%blockball_player_games%"), + PLAYER_STATS_STARTEDGAMES("%blockball_player_games%"), + + PLAYER_STATS_COMPLETEDGAMES("%blockball_player_gamesFull%"), PLAYER_STATS_WINS("%blockball_player_wins%"), PLAYER_STATS_LOSSES("%blockball_player_losses%"), - PLAYER_STATS_WINRATE("%blockball_player_winrate%"), + PLAYER_STATS_STARTEDWINRATE("%blockball_player_winrate%"), + + PLAYER_STATS_COMPLETEDWINRATE("%blockball_player_winrateFull%"), + + PLAYER_STATS_STARTEDGOALSPER("%blockball_player_goalsPerGame%"), - PLAYER_STATS_GOALSPERGAME("%blockball_player_goalsPerGameRate%") + PLAYER_STATS_COMPLETEDGOALSPER("%blockball_player_goalsPerGameFull%") } diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/GameActionServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/GameActionServiceImpl.kt index d2c5217c2..02c8e6d71 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/GameActionServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/GameActionServiceImpl.kt @@ -9,7 +9,9 @@ import com.github.shynixn.blockball.enumeration.* import com.github.shynixn.blockball.event.GameJoinEvent import com.github.shynixn.blockball.event.GameLeaveEvent import com.github.shynixn.blockball.impl.PacketHologram +import com.github.shynixn.mccoroutine.bukkit.launch import com.github.shynixn.mcutils.common.Version +import com.github.shynixn.mcutils.database.api.PlayerDataRepository import com.github.shynixn.mcutils.packet.api.PacketService import com.google.inject.Inject import org.bukkit.Bukkit @@ -32,6 +34,7 @@ class GameActionServiceImpl @Inject constructor( private val proxyService: ProxyService, private val packetService: PacketService, private val plugin: Plugin, + private val playerDataRepository: PlayerDataRepository ) : GameActionService { /** * Compatibility reference. @@ -60,14 +63,24 @@ class GameActionServiceImpl @Inject constructor( return false } - if (game is HubGame) { - return gameHubGameActionService.joinGame(game, player, team) + val result = if (game is HubGame) { + gameHubGameActionService.joinGame(game, player, team) + } else if (game is MiniGame) { + minigameActionService.joinGame(game, player, team) + } else { + throw RuntimeException("Game not supported!") } - if (game is MiniGame) { - return minigameActionService.joinGame(game, player, team) + + if (result) { + plugin.launch { + val playerData = playerDataRepository.getByPlayer(player) + if (playerData != null) { + playerData.statsMeta.joinedGames++ + } + } } - throw RuntimeException("Game not supported!") + return result } /** diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/GameSoccerServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/GameSoccerServiceImpl.kt index 34f6782bf..d62cae6d1 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/GameSoccerServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/GameSoccerServiceImpl.kt @@ -1,11 +1,7 @@ package com.github.shynixn.blockball.impl.service -import com.github.shynixn.blockball.BlockBallDependencyInjectionBinder import com.github.shynixn.blockball.contract.* -import com.github.shynixn.blockball.entity.CommandMeta -import com.github.shynixn.blockball.entity.Game -import com.github.shynixn.blockball.entity.PlayerInformation -import com.github.shynixn.blockball.entity.TeamMeta +import com.github.shynixn.blockball.entity.* import com.github.shynixn.blockball.enumeration.* import com.github.shynixn.blockball.event.GameEndEvent import com.github.shynixn.blockball.event.GameGoalEvent @@ -221,13 +217,11 @@ class GameSoccerServiceImpl @Inject constructor( ) } - if (BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { - plugin.launch { - val playerData = playerDataRepository.getByPlayer(interactionEntity) + plugin.launch { + val playerData = playerDataRepository.getByPlayer(interactionEntity) - if (playerData != null) { - playerData.statsMeta.scoredGoals++ - } + if (playerData != null) { + playerData.statsMeta.scoredGoals++ } } } @@ -313,18 +307,16 @@ class GameSoccerServiceImpl @Inject constructor( val participatingPlayers = game.inTeamPlayers.map { e -> e as Player }.toTypedArray() val winningPlayerCache = winningPlayers?.toMutableList() - if (BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { - plugin.launch { - for (player in participatingPlayers) { - val playerData = playerDataRepository.getByPlayer(player) + plugin.launch { + for (player in participatingPlayers) { + val playerData = playerDataRepository.getByPlayer(player) - if (playerData != null) { - playerData.statsMeta.playedGames++ - playerData.playerName = player.name + if (playerData != null) { + playerData.statsMeta.playedGames++ + playerData.playerName = player.name - if (winningPlayerCache != null && winningPlayerCache.contains(player)) { - playerData.statsMeta.winsAmount++ - } + if (winningPlayerCache != null && winningPlayerCache.contains(player)) { + playerData.statsMeta.winsAmount++ } } } diff --git a/src/main/java/com/github/shynixn/blockball/impl/service/PlaceHolderServiceImpl.kt b/src/main/java/com/github/shynixn/blockball/impl/service/PlaceHolderServiceImpl.kt index 5ef46a95d..880bd25d2 100644 --- a/src/main/java/com/github/shynixn/blockball/impl/service/PlaceHolderServiceImpl.kt +++ b/src/main/java/com/github/shynixn/blockball/impl/service/PlaceHolderServiceImpl.kt @@ -119,7 +119,15 @@ class PlaceHolderServiceImpl @Inject constructor( playerData?.statsMeta?.scoredGoals?.toString() ?: "" } } - playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_PLAYEDGAMES] = { player -> + playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_STARTEDGAMES] = { player -> + if (!BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { + "PatreonOnly" + } else { + val playerData = playerDataRepository.getCachedByPlayer(player) + playerData?.statsMeta?.joinedGames?.toString() ?: "" + } + } + playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_COMPLETEDGAMES] = { player -> if (!BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { "PatreonOnly" } else { @@ -147,7 +155,25 @@ class PlaceHolderServiceImpl @Inject constructor( } } } - playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_WINRATE] = { player -> + playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_STARTEDWINRATE] = { player -> + if (!BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { + "PatreonOnly" + } else { + val playerData = playerDataRepository.getCachedByPlayer(player) + if (playerData != null) { + if (playerData.statsMeta.joinedGames == 0) { + "0.00" + } else { + val result = + playerData.statsMeta.winsAmount.toDouble() / playerData.statsMeta.joinedGames.toDouble() + String.format("%.2f", result) + } + } else { + "" + } + } + } + playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_COMPLETEDWINRATE] = { player -> if (!BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { "PatreonOnly" } else { @@ -165,7 +191,25 @@ class PlaceHolderServiceImpl @Inject constructor( } } } - playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_GOALSPERGAME] = { player -> + playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_STARTEDGOALSPER] = { player -> + if (!BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { + "PatreonOnly" + } else { + val playerData = playerDataRepository.getCachedByPlayer(player) + if (playerData != null) { + if (playerData.statsMeta.joinedGames == 0) { + "0.00" + } else { + val result = + playerData.statsMeta.scoredGoals.toDouble() / playerData.statsMeta.joinedGames.toDouble() + String.format("%.2f", result) + } + } else { + "" + } + } + } + playerPlaceHolderFunctions[PlaceHolder.PLAYER_STATS_COMPLETEDGOALSPER] = { player -> if (!BlockBallDependencyInjectionBinder.areLegacyVersionsIncluded) { "PatreonOnly" } else {