Add ability to define cooldowns for actions (#437)

This commit is contained in:
William authored and GitHub committed 2023-06-16 17:39:54 +01:00
1 parent fb052340c0
commit fc8d3b0098
52 files changed
+1140 -619

No files matched your search

@@ -22,6 +22,7 @@ package net.william278.huskhomes.hook;
import net.william278.huskhomes.HuskHomes;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.TransactionResolver;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
@@ -31,8 +32,6 @@ import java.util.Locale;
*/
public abstract class EconomyHook extends Hook {
public static final String BYPASS_PERMISSION = "huskhomes.bypass_economy_checks";
protected EconomyHook(@NotNull HuskHomes plugin, @NotNull String hookName) {
super(plugin, hookName);
}
@@ -69,7 +68,7 @@ public abstract class EconomyHook extends Hook {
* @param plugin the plugin instance
* @param action the action that was performed
*/
public final void notifyDeducted(@NotNull OnlineUser user, @NotNull HuskHomes plugin, @NotNull Action action) {
public final void notifyDeducted(@NotNull OnlineUser user, @NotNull HuskHomes plugin, @NotNull TransactionResolver.Action action) {
plugin.getSettings().getEconomyCost(action)
.flatMap(cost -> plugin.getLocales().getLocale(
"economy_transaction_complete",
@@ -82,31 +81,37 @@ public abstract class EconomyHook extends Hook {
}
/**
* Identifies actions that have a price associated with performing them
* Send the player a message notifying them that they have been charged
* for performing an action
*
* @param user the user to notify
* @param plugin the plugin instance
* @param action the action that was performed
* @deprecated See {@link #notifyDeducted(OnlineUser, HuskHomes, TransactionResolver.Action)} instead,
* using the new {@link TransactionResolver.Action} enum
*/
@Deprecated(since = "4.4", forRemoval = true)
public final void notifyDeducted(@NotNull OnlineUser user, @NotNull HuskHomes plugin, @NotNull Action action) {
this.notifyDeducted(user, plugin, action.getTransactionAction());
}
/**
* Economy actions for which a player can be charged
*
* @deprecated Use the new {@link TransactionResolver.Action} enum instead
*/
@Deprecated(since = "4.4", forRemoval = true)
public enum Action {
/*
* Home and public home slots
*/
ADDITIONAL_HOME_SLOT(100.00),
MAKE_HOME_PUBLIC(50.00),
BACK_COMMAND(0.00),
/*
* Teleportation actions
*/
RANDOM_TELEPORT(25.00),
HOME_TELEPORT(0.00),
PUBLIC_HOME_TELEPORT(0.00),
WARP_TELEPORT(0.00),
SPAWN_TELEPORT(0.00),
/*
* Teleport request actions
*/
SEND_TELEPORT_REQUEST(0.00),
ACCEPT_TELEPORT_REQUEST(0.00);
ADDITIONAL_HOME_SLOT(100d),
MAKE_HOME_PUBLIC(50d),
BACK_COMMAND,
RANDOM_TELEPORT(25d),
HOME_TELEPORT,
PUBLIC_HOME_TELEPORT,
WARP_TELEPORT,
SPAWN_TELEPORT,
SEND_TELEPORT_REQUEST,
ACCEPT_TELEPORT_REQUEST;
private final double defaultCost;
@@ -114,9 +119,31 @@ public abstract class EconomyHook extends Hook {
this.defaultCost = defaultCost;
}
Action() {
this(0d);
}
/**
* Create an action with a default cost
*
* @return the default cost
* @deprecated Use the new {@link TransactionResolver.Action#getDefaultCost()} instead
*/
@Deprecated(since = "4.4", forRemoval = true)
public double getDefaultCost() {
return defaultCost;
}
/**
* Translate this legacy Action to the new {@link TransactionResolver.Action}
*
* @return the equivalent {@link TransactionResolver.Action}
*/
@NotNull
public TransactionResolver.Action getTransactionAction() {
return TransactionResolver.Action.valueOf(this.name());
}
}
}