Class Utils
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getSignString
(String str) Truncates a given string to a maximum length of 16 characters.static String
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.
-
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 withdrawnamount
- the amount of money to transfermsgReceiver
- iftrue
and the receiver is online, a message will be sentmsgGiver
- iftrue
and the giver is online, a message will be sent- Returns:
true
if the payment was successful;false
otherwise.
-
getTime
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 dayshours
- a Duration representing additional hours and minutes; may benull
details
- iftrue
, include hours and minutes even when days are present- Returns:
- a formatted string representing the total time.
-
transferClaim
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 transferredbuyer
- the UUID of the new ownerseller
- the UUID of the current owner (may benull
for admin claims)
-
getSignString
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.
-