Class PlayerHistoryStorage
java.lang.Object
me.confuser.banmanager.common.ormlite.dao.BaseDaoImpl<PlayerHistoryData,Integer>
me.confuser.banmanager.common.storage.PlayerHistoryStorage
- All Implemented Interfaces:
Iterable<PlayerHistoryData>,me.confuser.banmanager.common.ormlite.dao.CloseableIterable<PlayerHistoryData>,me.confuser.banmanager.common.ormlite.dao.Dao<PlayerHistoryData,Integer>
public class PlayerHistoryStorage
extends me.confuser.banmanager.common.ormlite.dao.BaseDaoImpl<PlayerHistoryData,Integer>
-
Nested Class Summary
Nested classes/interfaces inherited from interface me.confuser.banmanager.common.ormlite.dao.Dao
me.confuser.banmanager.common.ormlite.dao.Dao.CreateOrUpdateStatus, me.confuser.banmanager.common.ormlite.dao.Dao.DaoObserver -
Field Summary
Fields inherited from class me.confuser.banmanager.common.ormlite.dao.BaseDaoImpl
connectionSource, databaseType, dataClass, lastIterator, objectFactory, statementExecutor, tableConfig, tableInfo -
Constructor Summary
ConstructorsConstructorDescriptionPlayerHistoryStorage(BanManagerPlugin plugin) PlayerHistoryStorage(me.confuser.banmanager.common.ormlite.support.ConnectionSource connection, me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig<?> table) Constructor for conversion/migration purposes only. -
Method Summary
Modifier and TypeMethodDescriptionbooleanendSession(UUID uuid) End a session for a player.booleanendSessionById(int sessionId) End a session by its database ID.getNameAt(PlayerData player, long timestamp) Get the name a player was using at a specific timestamp.getNamesSummary(PlayerData player) Get a summary of distinct names with aggregated first/last seen times.me.confuser.banmanager.common.ormlite.dao.CloseableIterator<PlayerHistoryData> getSince(PlayerData player, long since, int page) booleanhasActiveSession(UUID uuid) Check if a player has an active session.voidPurge old session history records.removeSession(UUID uuid) Remove a session from memory without updating the database.voidsave()End all active sessions.voidstartSession(PlayerData player, boolean logIp) Start a new session for a player.Methods inherited from class me.confuser.banmanager.common.ormlite.dao.BaseDaoImpl
assignEmptyForeignCollection, callBatchTasks, checkForInitialized, clearAllInternalObjectCaches, clearObjectCache, closeableIterator, closeLastIterator, commit, countOf, countOf, create, create, createIfNotExists, createOrUpdate, delete, delete, delete, deleteBuilder, deleteById, deleteIds, endThreadConnection, executeRaw, executeRawNoArgs, extractId, findForeignFieldType, getConnectionSource, getDataClass, getEmptyForeignCollection, getObjectCache, getObjectFactory, getRawRowMapper, getSelectStarRowMapper, getTableConfig, getTableInfo, getTableName, getWrappedIterable, getWrappedIterable, idExists, initialize, isAutoCommit, isTableExists, isUpdatable, iterator, iterator, iterator, iterator, mapSelectStarRow, notifyChanges, objectsEqual, objectToString, query, queryBuilder, queryForAll, queryForEq, queryForFieldValues, queryForFieldValuesArgs, queryForFirst, queryForId, queryForMatching, queryForMatchingArgs, queryForSameId, queryRaw, queryRaw, queryRaw, queryRaw, queryRaw, queryRawValue, refresh, registerObserver, rollBack, setAutoCommit, setConnectionSource, setObjectCache, setObjectCache, setObjectFactory, setTableConfig, startThreadConnection, unregisterObserver, update, update, updateBuilder, updateId, updateRawMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PlayerHistoryStorage
- Throws:
SQLException
-
PlayerHistoryStorage
public PlayerHistoryStorage(me.confuser.banmanager.common.ormlite.support.ConnectionSource connection, me.confuser.banmanager.common.ormlite.table.DatabaseTableConfig<?> table) throws SQLException Constructor for conversion/migration purposes only. Does not support startSession/endSession methods.- Throws:
SQLException
-
-
Method Details
-
startSession
Start a new session for a player. Inserts a row using ORM, then updates timestamps to database time. The session ID is stored in memory for later update on leave.- Parameters:
player- The player datalogIp- Whether to record the IP address- Throws:
IllegalStateException- if dbConfig is not set (conversion mode)SQLException
-
endSession
End a session for a player. Updates the leave time to the current database time. Note: For async usage, prefer removeSession() + endSessionById() to avoid race conditions.- Parameters:
uuid- The player's UUID- Returns:
- true if the session was found and updated, false otherwise
- Throws:
IllegalStateException- if dbConfig is not set (conversion mode)SQLException
-
endSessionById
End a session by its database ID. Updates the leave time to the current database time. Use this when you've already retrieved the session ID (e.g., for async processing).- Parameters:
sessionId- The session database ID- Returns:
- true if the update was successful
- Throws:
IllegalStateException- if dbConfig is not set (conversion mode)SQLException
-
removeSession
Remove a session from memory without updating the database. Used when you need to handle the session manually.- Parameters:
uuid- The player's UUID- Returns:
- The session ID if found, null otherwise
-
hasActiveSession
Check if a player has an active session. -
getSince
public me.confuser.banmanager.common.ormlite.dao.CloseableIterator<PlayerHistoryData> getSince(PlayerData player, long since, int page) throws SQLException - Throws:
SQLException
-
getNamesSummary
Get a summary of distinct names with aggregated first/last seen times. firstSeen = MIN(join) across all sessions for that name lastSeen = MAX(leave) across all sessions for that name- Parameters:
player- The player- Returns:
- List of PlayerNameSummary ordered by lastSeen DESC
- Throws:
SQLException- if database error occurs
-
getNameAt
Get the name a player was using at a specific timestamp. Finds the session where join invalid input: '<'= ts AND leave >= ts.- Parameters:
player- The playertimestamp- The timestamp to check- Returns:
- The name at that time, or null if not found
- Throws:
SQLException- if database error occurs
-
save
public void save()End all active sessions. Called on shutdown. Updates leave time to database time for all remaining sessions. -
purge
Purge old session history records. Only purges records where: - ip IS NOT NULL (has IP) AND ip is not currently banned - OR ip IS NULL (name-only records, always eligible for purge by age) And leave timestamp is older than the configured days.- Throws:
SQLException
-