Skip to content

Commit

Permalink
#485 Improved stats tracking cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Apr 6, 2024
1 parent 60d8d02 commit 4bd27e0
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 37 deletions.
18 changes: 14 additions & 4 deletions docs/source/customizing/placeholders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
===================================== ===================================================================================
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +34,7 @@ class GameActionServiceImpl @Inject constructor(
private val proxyService: ProxyService,
private val packetService: PacketService,
private val plugin: Plugin,
private val playerDataRepository: PlayerDataRepository<PlayerInformation>
) : GameActionService {
/**
* Compatibility reference.
Expand Down Expand Up @@ -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
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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++
}
}
}
Expand Down Expand Up @@ -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++
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 4bd27e0

Please sign in to comment.