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

    Constructors
    Constructor
    Description
     
    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 Type
    Method
    Description
    boolean
    End a session for a player.
    boolean
    endSessionById(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.
    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)
     
    boolean
    Check if a player has an active session.
    void
    purge(CleanUp cleanup)
    Purge old session history records.
    Remove a session from memory without updating the database.
    void
    End all active sessions.
    void
    startSession(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, updateRaw

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • PlayerHistoryStorage

      public PlayerHistoryStorage(BanManagerPlugin plugin) throws SQLException
      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

      public void startSession(PlayerData player, boolean logIp) throws SQLException
      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 data
      logIp - Whether to record the IP address
      Throws:
      IllegalStateException - if dbConfig is not set (conversion mode)
      SQLException
    • endSession

      public boolean endSession(UUID uuid) throws SQLException
      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

      public boolean endSessionById(int sessionId) throws SQLException
      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

      public Integer removeSession(UUID uuid)
      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

      public boolean hasActiveSession(UUID uuid)
      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

      public List<PlayerNameSummary> getNamesSummary(PlayerData player) throws SQLException
      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

      public String getNameAt(PlayerData player, long timestamp) throws SQLException
      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 player
      timestamp - 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

      public void purge(CleanUp cleanup) throws SQLException
      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