Class LogManager

java.lang.Object
me.tayebyassine.homestead.managers.LogManager

public final class LogManager extends Object
A utility class that manages RegionLog.
  • Method Details

    • addLog

      public static void addLog(Region region, String author, String message)
      Add a new log to a region.
      Parameters:
      region - the region
      author - the author of the message
      message - the message
    • addLog

      public static void addLog(long regionId, String author, String message)
      Add a new log to a region.
      Parameters:
      regionId - the region ID
      author - the author of the message
      message - the message
    • addLog

      public static void addLog(Region region, @Nullable @Nullable org.bukkit.OfflinePlayer player, LogManager.PredefinedLog log, Object... data)
      Add a new log to a region using a predefined log template.
      Parameters:
      region - the region
      player - the player associated with the log, or null for system logs
      log - the predefined log type
      data - the placeholder data to fill in the log message
    • addLog

      public static void addLog(long regionId, @Nullable @Nullable org.bukkit.OfflinePlayer player, LogManager.PredefinedLog log, Object... data)
      Add a new log to a region using a predefined log template.
      Parameters:
      regionId - the region ID
      player - the player associated with the log, or null for system logs
      log - the predefined log type
      data - the placeholder data to fill in the log message
    • getLog

      public static RegionLog getLog(long logId)
      Retrieves a specific log by its unique ID.
      Parameters:
      logId - the log ID
      Returns:
      the RegionLog, or null if not found
    • getLogs

      public static List<RegionLog> getLogs(Region region)
      Returns a list of logs from a region, sorted newest first.
      Parameters:
      region - the region
      Returns:
      list of logs from a region
    • getLogs

      public static List<RegionLog> getLogs(long regionId)
      Returns a list of logs from a region, sorted newest first.
      Parameters:
      regionId - the region ID
      Returns:
      list of logs from a region
    • getLogCount

      public static int getLogCount()
      Returns the total number of logs in the server.
      Returns:
      total log count
    • getLogCount

      public static int getLogCount(Region region)
      Returns the total number of logs in a region.
      Parameters:
      region - the region
      Returns:
      total log count
    • getLogCount

      public static int getLogCount(long regionId)
      Returns the total number of logs in a region.
      Parameters:
      regionId - the region ID
      Returns:
      total log count
    • getOldestLog

      public static RegionLog getOldestLog(Region region)
      Returns the oldest log in a region.
      Parameters:
      region - the region
      Returns:
      the oldest log, or null if none exist
    • getOldestLog

      public static RegionLog getOldestLog(long regionId)
      Returns the oldest log in a region.
      Parameters:
      regionId - the region ID
      Returns:
      the oldest log, or null if none exist
    • getLatestLog

      public static RegionLog getLatestLog(Region region)
      Returns the most recent log in a region.
      Parameters:
      region - the region
      Returns:
      the latest log, or null if none exist
    • getLatestLog

      public static RegionLog getLatestLog(long regionId)
      Returns the most recent log in a region.
      Parameters:
      regionId - the region ID
      Returns:
      the latest log, or null if none exist
    • getLogsByAuthor

      public static List<RegionLog> getLogsByAuthor(Region region, String author)
      Returns logs from a specific author in a region.
      Parameters:
      region - the region
      author - the author name
      Returns:
      list of logs by the author
    • getLogsByAuthor

      public static List<RegionLog> getLogsByAuthor(long regionId, String author)
      Returns logs from a specific author in a region.
      Parameters:
      regionId - the region ID
      author - the author name
      Returns:
      list of logs by the author
    • getLogsBefore

      public static List<RegionLog> getLogsBefore(Region region, long timestamp)
      Returns logs sent before a specific timestamp.
      Parameters:
      region - the region
      timestamp - the cutoff timestamp (exclusive)
      Returns:
      list of older logs
    • getLogsBefore

      public static List<RegionLog> getLogsBefore(long regionId, long timestamp)
      Returns logs sent before a specific timestamp.
      Parameters:
      regionId - the region ID
      timestamp - the cutoff timestamp (exclusive)
      Returns:
      list of older logs
    • getLogsAfter

      public static List<RegionLog> getLogsAfter(Region region, long timestamp)
      Returns logs sent after a specific timestamp.
      Parameters:
      region - the region
      timestamp - the cutoff timestamp (exclusive)
      Returns:
      list of newer logs
    • getLogsAfter

      public static List<RegionLog> getLogsAfter(long regionId, long timestamp)
      Returns logs sent after a specific timestamp.
      Parameters:
      regionId - the region ID
      timestamp - the cutoff timestamp (exclusive)
      Returns:
      list of newer logs
    • getUnreadLogs

      public static List<RegionLog> getUnreadLogs(Region region)
      Returns only unread logs from a region.
      Parameters:
      region - the region
      Returns:
      list of unread logs
    • getUnreadLogs

      public static List<RegionLog> getUnreadLogs(long regionId)
      Returns only unread logs from a region.
      Parameters:
      regionId - the region ID
      Returns:
      list of unread logs
    • getUnreadCount

      public static int getUnreadCount(Region region)
      Returns the number of unread logs in a region.
      Parameters:
      region - the region
      Returns:
      unread log count
    • getUnreadCount

      public static int getUnreadCount(long regionId)
      Returns the number of unread logs in a region.
      Parameters:
      regionId - the region ID
      Returns:
      unread log count
    • hasUnreadLogs

      public static boolean hasUnreadLogs(Region region)
      Checks if a region has any unread logs.
      Parameters:
      region - the region
      Returns:
      true if unread logs exist
    • hasUnreadLogs

      public static boolean hasUnreadLogs(long regionId)
      Checks if a region has any unread logs.
      Parameters:
      regionId - the region ID
      Returns:
      true if unread logs exist
    • markAsRead

      public static boolean markAsRead(long logId)
      Marks a specific log as read.
      Parameters:
      logId - the log ID
      Returns:
      true if the log was found and updated
    • markAsUnread

      public static boolean markAsUnread(long logId)
      Marks a specific log as unread.
      Parameters:
      logId - the log ID
      Returns:
      true if the log was found and updated
    • markAllAsRead

      public static void markAllAsRead(Region region)
      Mark all logs as read.
      Parameters:
      region - the region
    • markAllAsRead

      public static void markAllAsRead(long regionId)
      Mark all logs as read.
      Parameters:
      regionId - the region ID
    • markAllAsUnread

      public static void markAllAsUnread(Region region)
      Mark all logs as unread.
      Parameters:
      region - the region
    • markAllAsUnread

      public static void markAllAsUnread(long regionId)
      Mark all logs as unread.
      Parameters:
      regionId - the region ID
    • deleteLog

      public static void deleteLog(RegionLog log)
      Delete a log.
      Parameters:
      log - the log
    • deleteLog

      public static void deleteLog(long logId)
      Delete a log.
      Parameters:
      logId - the log ID
    • deleteLogsOfRegion

      public static void deleteLogsOfRegion(Region region)
      Delete all logs from a region.
      Parameters:
      region - the region
    • deleteLogsOfRegion

      public static void deleteLogsOfRegion(long regionId)
      Delete all logs from a region.
      Parameters:
      regionId - the region ID
    • deleteReadLogs

      public static int deleteReadLogs(Region region)
      Deletes all read logs from a region.
      Parameters:
      region - the region
      Returns:
      the number of logs deleted
    • deleteReadLogs

      public static int deleteReadLogs(long regionId)
      Deletes all read logs from a region.
      Parameters:
      regionId - the region ID
      Returns:
      the number of logs deleted
    • deleteLogsOlderThan

      public static int deleteLogsOlderThan(long timestamp)
      Deletes all logs older than the specified timestamp.
      Parameters:
      timestamp - the cutoff timestamp (exclusive)
      Returns:
      the number of logs deleted
    • deleteAllLogs

      public static int deleteAllLogs()
      Deletes every log in the cache. Use with caution.
      Returns:
      the number of logs deleted
    • cleanupInvalidLogs

      public static int cleanupInvalidLogs()
      Removes all logs with invalid references:
      - Regions that no longer exist
      Returns:
      number of corrupted logs removed