Switched EconomyIntegration to be based around BigDecimal
This commit is contained in:
@@ -8,7 +8,19 @@ import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Wrapper class for economy integrations.
|
||||
* <p>
|
||||
* If you're adding your economy to be supported in eco,
|
||||
* it's recommended to override the {@link BigDecimal} methods
|
||||
* as opposed to the {@code double} methods.
|
||||
*
|
||||
* <strong>You must override at least one of all methods</strong>,
|
||||
* i.e. one {@code hasAmount}, one {@code giveMoney}, etc.,
|
||||
* otherwise your integration will cause {@link StackOverflowError}.
|
||||
* <p>
|
||||
* All methods are marked as default to preserve compatibility with
|
||||
* integrations made before 6.43.0.
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
public interface EconomyIntegration extends Integration {
|
||||
/**
|
||||
* Get if a player has a certain amount.
|
||||
@@ -16,9 +28,39 @@ public interface EconomyIntegration extends Integration {
|
||||
* @param player The player.
|
||||
* @param amount The amount.
|
||||
* @return If the player has the amount.
|
||||
* @deprecated Use {@link BigDecimal} methods instead.
|
||||
*/
|
||||
boolean hasAmount(@NotNull OfflinePlayer player,
|
||||
double amount);
|
||||
@Deprecated(since = "6.43.0")
|
||||
default boolean hasAmount(@NotNull OfflinePlayer player,
|
||||
double amount) {
|
||||
return hasAmount(player, BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if a player has a certain amount.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param amount The amount
|
||||
* @return If the player has the amount.
|
||||
*/
|
||||
default boolean hasAmount(@NotNull OfflinePlayer player,
|
||||
@NotNull BigDecimal amount) {
|
||||
return hasAmount(player, amount.doubleValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Give money to a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param amount The amount to give.
|
||||
* @return If the transaction was a success.
|
||||
* @deprecated Use {@link BigDecimal} methods instead.
|
||||
*/
|
||||
@Deprecated(since = "6.43.0")
|
||||
default boolean giveMoney(@NotNull OfflinePlayer player,
|
||||
double amount) {
|
||||
return giveMoney(player, BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give money to a player.
|
||||
@@ -27,8 +69,24 @@ public interface EconomyIntegration extends Integration {
|
||||
* @param amount The amount to give.
|
||||
* @return If the transaction was a success.
|
||||
*/
|
||||
boolean giveMoney(@NotNull OfflinePlayer player,
|
||||
double amount);
|
||||
default boolean giveMoney(@NotNull OfflinePlayer player,
|
||||
@NotNull BigDecimal amount) {
|
||||
return giveMoney(player, amount.doubleValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove money from a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param amount The amount to remove.
|
||||
* @return If the transaction was a success.
|
||||
* @deprecated Use {@link BigDecimal} methods instead.
|
||||
*/
|
||||
@Deprecated(since = "6.43.0")
|
||||
default boolean removeMoney(@NotNull OfflinePlayer player,
|
||||
double amount) {
|
||||
return removeMoney(player, BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove money from a player.
|
||||
@@ -37,16 +95,23 @@ public interface EconomyIntegration extends Integration {
|
||||
* @param amount The amount to remove.
|
||||
* @return If the transaction was a success.
|
||||
*/
|
||||
boolean removeMoney(@NotNull OfflinePlayer player,
|
||||
double amount);
|
||||
default boolean removeMoney(@NotNull OfflinePlayer player,
|
||||
@NotNull BigDecimal amount) {
|
||||
return removeMoney(player, amount.doubleValue());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the balance of a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return The balance.
|
||||
* @deprecated Use {@link BigDecimal} methods instead.
|
||||
*/
|
||||
double getBalance(@NotNull OfflinePlayer player);
|
||||
@Deprecated(since = "6.43.0")
|
||||
default double getBalance(@NotNull OfflinePlayer player) {
|
||||
return getExactBalance(player).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the balance of a player.
|
||||
|
||||
@@ -44,6 +44,18 @@ public final class EconomyManager {
|
||||
*/
|
||||
public static boolean hasAmount(@NotNull final OfflinePlayer player,
|
||||
final double amount) {
|
||||
return hasAmount(player, BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if a player has a certain amount.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param amount The amount.
|
||||
* @return If the player has the amount.
|
||||
*/
|
||||
public static boolean hasAmount(@NotNull final OfflinePlayer player,
|
||||
final BigDecimal amount) {
|
||||
for (EconomyIntegration integration : REGISTERED) {
|
||||
return integration.hasAmount(player, amount);
|
||||
}
|
||||
@@ -60,6 +72,18 @@ public final class EconomyManager {
|
||||
*/
|
||||
public static boolean giveMoney(@NotNull final OfflinePlayer player,
|
||||
final double amount) {
|
||||
return giveMoney(player, BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give money to a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param amount The amount to give.
|
||||
* @return If the transaction was a success.
|
||||
*/
|
||||
public static boolean giveMoney(@NotNull final OfflinePlayer player,
|
||||
@NotNull final BigDecimal amount) {
|
||||
for (EconomyIntegration integration : REGISTERED) {
|
||||
return integration.giveMoney(player, amount);
|
||||
}
|
||||
@@ -76,6 +100,18 @@ public final class EconomyManager {
|
||||
*/
|
||||
public static boolean removeMoney(@NotNull final OfflinePlayer player,
|
||||
final double amount) {
|
||||
return removeMoney(player, BigDecimal.valueOf(amount));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove money from a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param amount The amount to remove.
|
||||
* @return If the transaction was a success.
|
||||
*/
|
||||
public static boolean removeMoney(@NotNull final OfflinePlayer player,
|
||||
@NotNull final BigDecimal amount) {
|
||||
for (EconomyIntegration integration : REGISTERED) {
|
||||
return integration.removeMoney(player, amount);
|
||||
}
|
||||
@@ -90,11 +126,7 @@ public final class EconomyManager {
|
||||
* @return The balance.
|
||||
*/
|
||||
public static double getBalance(@NotNull final OfflinePlayer player) {
|
||||
for (EconomyIntegration integration : REGISTERED) {
|
||||
return integration.getBalance(player);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return getExactBalance(player).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user