Record Class IPBanEntry

java.lang.Object
java.lang.Record
me.github.simonplays15.betterbansystem.core.ban.IPBanEntry
All Implemented Interfaces:
IIPBanEntry

public record IPBanEntry(String ip, String source, Date created, Object expires, String reason) extends Record implements IIPBanEntry
Represents an entry for an IP ban.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The IIPBanEntryAdapter class is a Gson TypeAdapter for serializing and deserializing IIPBanEntry objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
    IPBanEntry (String ip, String source, Date created, Object expires, String reason)
    Creates a new IPBanEntry object and checks if the associated file exists.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the created record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the expires record component.
    static IIPBanEntry
    findEntry (String ipAddress)
    Finds an IP ban entry given the IP address.
    static @NotNull List<IIPBanEntry>
    Retrieves all IP ban entries.
    final int
    Returns a hash code value for this object.
    ip()
    Returns the value of the ip record component.
    Returns the value of the reason record component.
    static void
    removeEntry (@NotNull IIPBanEntry entry)
    Removes an entry from the IP ban list.
    static void
    removeFromJson (String ipAddress)
    Removes an entry from a JSON file based on the provided IP address.
    static void
    Saves the given IP ban entry to a JSON file or a database.
    Returns the value of the source record component.
    @NotNull String
    Returns a string representation of the IPBanEntry object.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • IPBanEntry

      public IPBanEntry (String ip, String source, Date created, Object expires, String reason)
      Creates a new IPBanEntry object and checks if the associated file exists. If the file does not exist, it will attempt to create a new file and output a log message if successful.
      Parameters:
      file - The associated file for this IPBanEntry.
  • Method Details

    • saveToJson

      public static void saveToJson (IIPBanEntry entry)
      Saves the given IP ban entry to a JSON file or a database.
      Parameters:
      entry - The IP ban entry to save.
    • removeEntry

      public static void removeEntry (@NotNull @NotNull IIPBanEntry entry)
      Removes an entry from the IP ban list.
      Parameters:
      entry - The IP ban entry to be removed.
    • removeFromJson

      public static void removeFromJson (String ipAddress)
      Removes an entry from a JSON file based on the provided IP address.
      Parameters:
      ipAddress - The IP address of the entry to be removed.
    • getAllEntries

      @NotNull public static @NotNull List<IIPBanEntry> getAllEntries()
      Retrieves all IP ban entries.
      Returns:
      A list of IPBanEntry objects representing the ban entries.
    • findEntry

      public static IIPBanEntry findEntry (String ipAddress)
      Finds an IP ban entry given the IP address.
      Parameters:
      ipAddress - The IP address to search for.
      Returns:
      The IP ban entry matching the given IP address, or null if no match is found.
    • toString

      @Contract(pure=true) @NotNull public @NotNull String toString()
      Returns a string representation of the IPBanEntry object.
      Specified by:
      toString in class Record
      Returns:
      A string representation of the IPBanEntry object.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals (Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • ip

      public String ip()
      Returns the value of the ip record component.
      Specified by:
      ip in interface IIPBanEntry
      Returns:
      the value of the ip record component
    • source

      public String source()
      Returns the value of the source record component.
      Specified by:
      source in interface IIPBanEntry
      Returns:
      the value of the source record component
    • created

      public Date created()
      Returns the value of the created record component.
      Specified by:
      created in interface IIPBanEntry
      Returns:
      the value of the created record component
    • expires

      public Object expires()
      Returns the value of the expires record component.
      Specified by:
      expires in interface IIPBanEntry
      Returns:
      the value of the expires record component
    • reason

      public String reason()
      Returns the value of the reason record component.
      Specified by:
      reason in interface IIPBanEntry
      Returns:
      the value of the reason record component