Record Class WarnEntry

java.lang.Object
java.lang.Record
me.github.simonplays15.betterbansystem.core.warn.WarnEntry
All Implemented Interfaces:
IWarnEntry

public record WarnEntry(UUID uuid, String name, List<Warn> warns) extends Record implements IWarnEntry
Represents a warning entry for a player.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The IWarnEntryAdapter class is a TypeAdapter for serializing and deserializing IWarnEntry objects to and from JSON.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final AtomicInteger
    The idGenerator variable is an AtomicInteger that is used for generating unique IDs for warnings.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WarnEntry (UUID uuid, String name, List<Warn> warns)
    Checks if the specified file exists, and if it doesn't, creates a new file.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addWarn (Warn warn)
    Adds a warning to the warn entry.
    final boolean
    Indicates whether some other object is "equal to" this one.
    static IWarnEntry
    findEntry (UUID targetUUID)
    Finds the warning entry with the specified UUID.
    static @NotNull List<IWarnEntry>
    Retrieves all the warning entries.
    final int
    Returns a hash code value for this object.
    name()
    Returns the value of the name record component.
    static void
    removeEntry (@NotNull IWarnEntry entry)
    Removes the specified warning entry from the system.
    static void
    removeFromJson (UUID target)
    Removes the specified UUID from the JSON file.
    boolean
    removeWarn (int id)
    Removes a warning with the specified ID from the warn entry.
    static void
    Saves a WarnEntry to a JSON file.
    final String
    Returns a string representation of this record class.
    uuid()
    Returns the value of the uuid record component.
    Returns the value of the warns record component.

    Methods inherited from class java.lang.Object

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

    • idGenerator

      public static final AtomicInteger idGenerator
      The idGenerator variable is an AtomicInteger that is used for generating unique IDs for warnings. It is declared as public, static, and final, which means that it is a constant variable and can be accessed without creating an instance of its containing class.

      idGenerator is an instance of the AtomicInteger class, which provides atomic operations for integers. This allows multiple threads to safely increment and retrieve the current value of the generator without conflicts or data races.

      The initial value of the generator is 1.

      Example usage:

      int id = idGenerator.getAndIncrement();

      This code snippet gets the current value of idGenerator and then increments it atomically. The returned value is stored in the "id" variable.

  • Constructor Details

    • WarnEntry

      public WarnEntry (UUID uuid, String name, List<Warn> warns)
      Checks if the specified file exists, and if it doesn't, creates a new file. If the file is created successfully, a log message will be logged indicating the creation of the file. Any IOException that occurs during the file creation process will be logged as an error.
  • Method Details

    • saveToJson

      public static void saveToJson (IWarnEntry entry)
      Saves a WarnEntry to a JSON file.
      Parameters:
      entry - The WarnEntry to be saved.
    • removeEntry

      public static void removeEntry (@NotNull @NotNull IWarnEntry entry)
      Removes the specified warning entry from the system.
      Parameters:
      entry - the warning entry to be removed
    • removeFromJson

      public static void removeFromJson (UUID target)
      Removes the specified UUID from the JSON file.
      Parameters:
      target - The UUID to remove from the JSON file.
    • getAllEntries

      @NotNull public static @NotNull List<IWarnEntry> getAllEntries()
      Retrieves all the warning entries.
      Returns:
      a list of IWarnEntry objects representing the warning entries
    • findEntry

      public static IWarnEntry findEntry (UUID targetUUID)
      Finds the warning entry with the specified UUID.
      Parameters:
      targetUUID - the UUID of the warning entry to find
      Returns:
      the warning entry with the specified UUID, or null if not found
    • addWarn

      public void addWarn (Warn warn)
      Adds a warning to the warn entry.
      Specified by:
      addWarn in interface IWarnEntry
      Parameters:
      warn - the warning to be added
    • removeWarn

      public boolean removeWarn (int id)
      Removes a warning with the specified ID from the warn entry.
      Specified by:
      removeWarn in interface IWarnEntry
      Parameters:
      id - the ID of the warning to remove
      Returns:
      true if the warning is successfully removed, false otherwise
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this 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.
    • uuid

      public UUID uuid()
      Returns the value of the uuid record component.
      Specified by:
      uuid in interface IWarnEntry
      Returns:
      the value of the uuid record component
    • name

      public String name()
      Returns the value of the name record component.
      Specified by:
      name in interface IWarnEntry
      Returns:
      the value of the name record component
    • warns

      public List<Warn> warns()
      Returns the value of the warns record component.
      Specified by:
      warns in interface IWarnEntry
      Returns:
      the value of the warns record component