Class SeRent

java.lang.Object
me.tayebyassine.homestead.models.serialize.SeRent

public final class SeRent extends Object
Serializable representation of rental data for a region or sub-area.

Stores the renter, duration, timestamps, security deposit, price, and optional notice-to-vacate. Can be serialized to and deserialized from a comma-separated string for persistence.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a default rent with values from the regions configuration.
    SeRent(UUID renterId, long duration, long startedAt, long untilAt, double securityDeposit, double price)
    Create a rent with the given parameters.
    SeRent(org.bukkit.OfflinePlayer renter, long duration, long startedAt, long untilAt, double securityDeposit, double price)
    Create a rent with the given parameters from an offline player.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear renter-specific fields while preserving owner configuration (price, duration, deposit).
    static SeRent
    deserialize(@NotNull String serialized)
    Deserialize a rent from its comma-separated string form.
    boolean
     
    long
    Get the rental duration in milliseconds.
    Get the notice-to-vacate, if any.
    double
    Get the rental price.
    @Nullable org.bukkit.OfflinePlayer
    Get the renter as an offline player.
    Get the renter's UUID.
    Get the renter's display name safely.
    double
    Get the security deposit amount.
    long
    Get the timestamp when the rental started.
    long
    Get the timestamp when the rental ends.
    int
     
    boolean
    Whether a notice-to-vacate has been issued.
    boolean
    Whether this rent currently has a renter.
    boolean
    Whether the rental has expired.
    boolean
    Whether this is a permanent (non-expiring) rental.
    boolean
    isRenterer(UUID renterId)
    Check whether the given UUID is the current renter.
    boolean
    isRenterer(org.bukkit.OfflinePlayer player)
    Check whether the given player is the current renter.
    Serialize the rent to a comma-separated string.
    void
    setDuration(long duration)
    Set the rental duration in milliseconds.
    void
    setNoticeToVacate(@Nullable SeNoticeToVacate noticeToVacate)
    Set the notice-to-vacate.
    void
    setPrice(double price)
    Set the rental price.
    void
    setRenterId(UUID renterId)
    Set the renter's UUID.
    void
    setSecurityDeposit(double securityDeposit)
    Set the security deposit amount.
    void
    setStartedAt(long startedAt)
    Set the timestamp when the rental started.
    void
    setUntilAt(long untilAt)
    Set the timestamp when the rental ends.
     

    Methods inherited from class Object

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

    • SeRent

      public SeRent()
      Create a default rent with values from the regions configuration.
    • SeRent

      public SeRent(UUID renterId, long duration, long startedAt, long untilAt, double securityDeposit, double price)
      Create a rent with the given parameters.
      Parameters:
      renterId - the renter's UUID, or null for no renter
      duration - the rental duration in milliseconds
      startedAt - the timestamp when the rental started
      untilAt - the timestamp when the rental ends, or -1 for permanent
      securityDeposit - the security deposit amount
      price - the rental price
    • SeRent

      public SeRent(org.bukkit.OfflinePlayer renter, long duration, long startedAt, long untilAt, double securityDeposit, double price)
      Create a rent with the given parameters from an offline player.
      Parameters:
      renter - the renter
      duration - the rental duration in milliseconds
      startedAt - the timestamp when the rental started
      untilAt - the timestamp when the rental ends
      securityDeposit - the security deposit amount
      price - the rental price
  • Method Details

    • deserialize

      public static SeRent deserialize(@NotNull @NotNull String serialized)
      Deserialize a rent from its comma-separated string form.
      Parameters:
      serialized - the encoded rent string
      Returns:
      the deserialized rent, or a default rent on parse failure
    • getRenterId

      public UUID getRenterId()
      Get the renter's UUID.
      Returns:
      the renter UUID, or null if unoccupied
    • setRenterId

      public void setRenterId(UUID renterId)
      Set the renter's UUID.
      Parameters:
      renterId - the new renter UUID
    • clearRenter

      public void clearRenter()
      Clear renter-specific fields while preserving owner configuration (price, duration, deposit). Called when rent expires or is cancelled.
    • isRenterer

      public boolean isRenterer(org.bukkit.OfflinePlayer player)
      Check whether the given player is the current renter.
      Parameters:
      player - the player to check
      Returns:
      true if the player is the renter
    • isRenterer

      public boolean isRenterer(UUID renterId)
      Check whether the given UUID is the current renter.
      Parameters:
      renterId - the UUID to check
      Returns:
      true if the UUID matches the renter
    • getRenter

      @Nullable public @Nullable org.bukkit.OfflinePlayer getRenter()
      Get the renter as an offline player.
      Returns:
      the renter, or null if no renter or not found
    • getRenterName

      public String getRenterName()
      Get the renter's display name safely.
      Returns:
      the renter's name, or "?" if not found
    • hasRenter

      public boolean hasRenter()
      Whether this rent currently has a renter.
      Returns:
      true if a renter is assigned
    • getDuration

      public long getDuration()
      Get the rental duration in milliseconds.
      Returns:
      the duration, or -1 for permanent
    • setDuration

      public void setDuration(long duration)
      Set the rental duration in milliseconds.
      Parameters:
      duration - the new duration
    • isPermanent

      public boolean isPermanent()
      Whether this is a permanent (non-expiring) rental.
      Returns:
      true if the duration is -1
    • getStartedAt

      public long getStartedAt()
      Get the timestamp when the rental started.
      Returns:
      the start timestamp in milliseconds
    • setStartedAt

      public void setStartedAt(long startedAt)
      Set the timestamp when the rental started.
      Parameters:
      startedAt - the start timestamp in milliseconds
    • getUntilAt

      public long getUntilAt()
      Get the timestamp when the rental ends.
      Returns:
      the end timestamp, or -1 for permanent
    • setUntilAt

      public void setUntilAt(long untilAt)
      Set the timestamp when the rental ends.
      Parameters:
      untilAt - the end timestamp, or -1 for permanent
    • isExpired

      public boolean isExpired()
      Whether the rental has expired.
      Returns:
      true if the current time is past the end timestamp
    • getNoticeToVacate

      @Nullable public @Nullable SeNoticeToVacate getNoticeToVacate()
      Get the notice-to-vacate, if any.
      Returns:
      the notice, or null
    • setNoticeToVacate

      public void setNoticeToVacate(@Nullable @Nullable SeNoticeToVacate noticeToVacate)
      Set the notice-to-vacate.
      Parameters:
      noticeToVacate - the notice, or null to clear
    • hasNoticeToVacate

      public boolean hasNoticeToVacate()
      Whether a notice-to-vacate has been issued.
      Returns:
      true if a notice is active
    • getSecurityDeposit

      public double getSecurityDeposit()
      Get the security deposit amount.
      Returns:
      the deposit amount
    • setSecurityDeposit

      public void setSecurityDeposit(double securityDeposit)
      Set the security deposit amount.
      Parameters:
      securityDeposit - the new deposit amount
    • getPrice

      public double getPrice()
      Get the rental price.
      Returns:
      the price
    • setPrice

      public void setPrice(double price)
      Set the rental price.
      Parameters:
      price - the new price
    • serialize

      public String serialize()
      Serialize the rent to a comma-separated string.
      Returns:
      the encoded string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object