Class Utils

java.lang.Object
me.EtienneDx.RealEstate.Utils

public class Utils extends Object
A utility class containing helper methods for the RealEstate plugin.

This class provides methods for processing economy transactions, formatting time durations, transferring claim blocks between players, and truncating strings for sign display.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new Utils object.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Truncates a given string to a maximum length of 16 characters.
    static String
    getTime(int days, Duration hours, boolean details)
    Formats a time duration as a human-readable string.
    static boolean
    makePayment(UUID receiver, UUID giver, double amount, boolean msgReceiver, boolean msgGiver)
    Processes a payment transaction between two players.
    static void
    transferClaim(IClaim claim, UUID buyer, UUID seller)
    Transfers a claim from one owner to another.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Utils

      public Utils()
      Instantiates a new Utils object.
  • Method Details

    • makePayment

      public static boolean makePayment(UUID receiver, UUID giver, double amount, boolean msgReceiver, boolean msgGiver)
      Processes a payment transaction between two players.

      The method attempts to withdraw a specified amount from the giver and deposit it to the receiver. If the giver does not have sufficient funds or if any transaction fails, an error message is sent (if enabled) and the transaction is aborted.

      Parameters:
      receiver - the UUID of the player who will receive money (can be null for the server)
      giver - the UUID of the player from whom money is to be withdrawn
      amount - the amount of money to transfer
      msgReceiver - if true and the receiver is online, a message will be sent
      msgGiver - if true and the giver is online, a message will be sent
      Returns:
      true if the payment was successful; false otherwise.
    • getTime

      public static String getTime(int days, Duration hours, boolean details)
      Formats a time duration as a human-readable string.

      The method converts the given number of days and a Duration representing hours/minutes into a string such as "1 week 3 days 5 hours 30 mins".

      Parameters:
      days - the number of days
      hours - a Duration representing additional hours and minutes; may be null
      details - if true, include hours and minutes even when days are present
      Returns:
      a formatted string representing the total time.
    • transferClaim

      public static void transferClaim(IClaim claim, UUID buyer, UUID seller)
      Transfers a claim from one owner to another.

      This method handles the transfer of claim blocks between the seller and buyer if claim blocks are being transferred, and then updates the claim's ownership using the claim API.

      Parameters:
      claim - the claim to be transferred
      buyer - the UUID of the new owner
      seller - the UUID of the current owner (may be null for admin claims)
    • getSignString

      public static String getSignString(String str)
      Truncates a given string to a maximum length of 16 characters.

      This is used for ensuring that sign text does not exceed Minecraft's character limit.

      Parameters:
      str - the input string
      Returns:
      the truncated string if its length exceeds 16 characters; otherwise, the original string.