Add fabric builds for older MC versions & add checkstyle (#449)

* Remove instance getters, improve command logic, register APi

* Publish multiple fabric builds, enforce checkstyle

* Bump guava

* Bump to 4.4.2
This commit is contained in:
William authored and GitHub committed 2023-07-02 13:26:12 +01:00
1 parent 51baf196b3
commit c9f5262292
219 files changed
+8032 -1392

No files matched your search

@@ -30,15 +30,15 @@ import java.util.Optional;
import java.util.StringJoiner;
/**
* Class for validating and performing economy and cooldown transactions involving {@link Action}s
* Class for validating and performing economy and cooldown transactions involving {@link Action}s.
*/
public interface TransactionResolver {
/**
* Validates whether an {@link OnlineUser} can perform an {@link Action}, in terms of whether they have sufficient
* funds and are not on cooldown. This method will also send the user a message if they cannot perform the action.
* <p>
* This method will return {@code true} if the user has sufficient funds and is not on cooldown, otherwise
*
* <p>This method will return {@code true} if the user has sufficient funds and is not on cooldown, otherwise
* {@code false}.
*
* @param player the {@link OnlineUser player} to perform the check on
@@ -52,11 +52,13 @@ public interface TransactionResolver {
// Validates if the user has funds to perform an action
private boolean hasFunds(@NotNull OnlineUser player, @NotNull Action action) {
return getPlugin().getSettings().getEconomyCost(action).map(Math::abs)
.flatMap(c -> player.hasPermission(Action.BYPASS_ECONOMY_PERMISSION) ? Optional.empty() : Optional.of(c))
.flatMap(c -> player.hasPermission(Action.BYPASS_ECONOMY_PERMISSION)
? Optional.empty() : Optional.of(c))
.map(c -> getEconomyHook()
.map(hook -> {
if (hook.getPlayerBalance(player) < c) {
getPlugin().getLocales().getLocale("error_insufficient_funds", hook.formatCurrency(c))
getPlugin().getLocales().getLocale("error_insufficient_funds",
hook.formatCurrency(c))
.ifPresent(player::sendMessage);
return false;
}
@@ -110,7 +112,7 @@ public interface TransactionResolver {
}
/**
* Execute an economy transaction if needed, updating the player's balance
* Execute an economy transaction if needed, updating the player's balance.
*
* @param player the {@link OnlineUser player} to deduct the cost from if needed
* @param action the {@link Action action} to deduct the cost from if needed
@@ -118,7 +120,8 @@ public interface TransactionResolver {
default void performTransaction(@NotNull OnlineUser player, @NotNull Action action) {
getEconomyHook().ifPresent(hook -> getPlugin().getSettings()
.getEconomyCost(action).map(Math::abs)
.flatMap(c -> player.hasPermission(Action.BYPASS_ECONOMY_PERMISSION) ? Optional.empty() : Optional.of(c))
.flatMap(c -> player.hasPermission(Action.BYPASS_ECONOMY_PERMISSION)
? Optional.empty() : Optional.of(c))
.ifPresent(cost -> {
hook.changePlayerBalance(player, -cost);
hook.notifyDeducted(player, getPlugin(), action);
@@ -131,16 +134,9 @@ public interface TransactionResolver {
}
/**
* @deprecated use {@link #validateTransaction(OnlineUser, Action)} instead
*/
@SuppressWarnings("removal")
@Deprecated(since = "4.4", forRemoval = true)
default boolean canPerformTransaction(@NotNull OnlineUser player, @NotNull EconomyHook.Action action) {
return this.validateTransaction(player, action.getTransactionAction());
}
/**
* @deprecated use {@link #performTransaction(OnlineUser, Action)} instead
* Execute an economy transaction if needed, updating the player's balance.
*
* @deprecated use {@link #performTransaction(OnlineUser, Action)} instead.
*/
@SuppressWarnings("removal")
@Deprecated(since = "4.4", forRemoval = true)
@@ -149,7 +145,19 @@ public interface TransactionResolver {
}
/**
* Get the {@link EconomyHook} instance, if present
* Get whether the {@link OnlineUser} can perform the {@link EconomyHook.Action},
* in terms of whether they have sufficient funds and are not on cooldown.
*
* @deprecated use {@link #validateTransaction(OnlineUser, Action)} instead.
*/
@SuppressWarnings("removal")
@Deprecated(since = "4.4", forRemoval = true)
default boolean canPerformTransaction(@NotNull OnlineUser player, @NotNull EconomyHook.Action action) {
return this.validateTransaction(player, action.getTransactionAction());
}
/**
* Get the {@link EconomyHook} instance, if present.
*
* @return the {@link EconomyHook} instance
*/
@@ -162,7 +170,7 @@ public interface TransactionResolver {
HuskHomes getPlugin();
/**
* Represents actions that can be the subject of a transaction
* Represents actions that can be the subject of a transaction.
*/
enum Action {
@@ -204,7 +212,7 @@ public interface TransactionResolver {
}
/**
* Create an action with a default cost
* Create an action with a default cost.
*
* @return the default cost
*/
@@ -213,7 +221,7 @@ public interface TransactionResolver {
}
/**
* Get the default cooldown for this action (in seconds)
* Get the default cooldown for this action (in seconds).
*
* @return the default cooldown in seconds
*/