mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Fix placeholder on home slots economy warning, close #278
This commit is contained in:
1 parent
b3db9de64f
commit
7c01b434e6
2 files changed
+34
-12
No files matched your search
@@ -226,17 +226,36 @@ public interface HuskHomes {
|
|||||||
@NotNull
|
@NotNull
|
||||||
Set<PluginHook> getPluginHooks();
|
Set<PluginHook> getPluginHooks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the {@link PluginHook} of the given class instance from the set of active {@link PluginHook}s
|
||||||
|
*
|
||||||
|
* @param hookClass the class of the {@link PluginHook} to get
|
||||||
|
* @param <H> the type of the {@link PluginHook}
|
||||||
|
* @return the {@link PluginHook} instance, or an empty {@link Optional} if not found
|
||||||
|
*/
|
||||||
|
default <H extends PluginHook> Optional<H> getHook(@NotNull Class<H> hookClass) {
|
||||||
|
return getPluginHooks().stream()
|
||||||
|
.filter(hook -> hook.getClass().isInstance(hookClass))
|
||||||
|
.findFirst()
|
||||||
|
.map(hookClass::cast);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link MapHook} being used to display public homes and warps on a web map, if there is one, and it is enabled
|
* Gets the {@link MapHook} being used to display public homes and warps on a web map, if there is one, and it is enabled
|
||||||
*
|
*
|
||||||
* @return the {@link MapHook} being used, if there is one, and it is enabled
|
* @return the {@link MapHook} optionally being used
|
||||||
*/
|
*/
|
||||||
default Optional<MapHook> getMapHook() {
|
default Optional<MapHook> getMapHook() {
|
||||||
return getSettings().doMapHook ? getPluginHooks()
|
return getSettings().doMapHook ? getHook(MapHook.class) : Optional.empty();
|
||||||
.stream()
|
}
|
||||||
.filter(pluginHook -> pluginHook instanceof MapHook)
|
|
||||||
.findFirst()
|
/**
|
||||||
.map(hook -> (MapHook) hook) : Optional.empty();
|
* Gets the {@link EconomyHook} being used to charge players for commands, if there is one, and it is enabled
|
||||||
|
*
|
||||||
|
* @return the {@link EconomyHook} optionally being used
|
||||||
|
*/
|
||||||
|
default Optional<EconomyHook> getEconomyHook() {
|
||||||
|
return getSettings().economy ? getHook(EconomyHook.class) : Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -250,8 +269,7 @@ public interface HuskHomes {
|
|||||||
default boolean validateEconomyCheck(@NotNull OnlineUser player, @NotNull Settings.EconomyAction action) {
|
default boolean validateEconomyCheck(@NotNull OnlineUser player, @NotNull Settings.EconomyAction action) {
|
||||||
final Optional<Double> cost = getSettings().getEconomyCost(action).map(Math::abs);
|
final Optional<Double> cost = getSettings().getEconomyCost(action).map(Math::abs);
|
||||||
if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) {
|
if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) {
|
||||||
final Optional<EconomyHook> hook = getPluginHooks().stream().filter(pluginHook ->
|
final Optional<EconomyHook> hook = getEconomyHook();
|
||||||
pluginHook instanceof EconomyHook).findFirst().map(pluginHook -> (EconomyHook) pluginHook);
|
|
||||||
if (hook.isPresent()) {
|
if (hook.isPresent()) {
|
||||||
if (cost.get() > hook.get().getPlayerBalance(player)) {
|
if (cost.get() > hook.get().getPlayerBalance(player)) {
|
||||||
getLocales().getLocale("error_insufficient_funds", hook.get().formatCurrency(cost.get()))
|
getLocales().getLocale("error_insufficient_funds", hook.get().formatCurrency(cost.get()))
|
||||||
@@ -274,8 +292,7 @@ public interface HuskHomes {
|
|||||||
final Optional<Double> cost = getSettings().getEconomyCost(action).map(Math::abs);
|
final Optional<Double> cost = getSettings().getEconomyCost(action).map(Math::abs);
|
||||||
|
|
||||||
if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) {
|
if (cost.isPresent() && !player.hasPermission(Permission.BYPASS_ECONOMY_CHECKS.node)) {
|
||||||
final Optional<EconomyHook> hook = getPluginHooks().stream().filter(pluginHook ->
|
final Optional<EconomyHook> hook = getEconomyHook();
|
||||||
pluginHook instanceof EconomyHook).findFirst().map(pluginHook -> (EconomyHook) pluginHook);
|
|
||||||
if (hook.isPresent()) {
|
if (hook.isPresent()) {
|
||||||
hook.get().changePlayerBalance(player, -cost.get());
|
hook.get().changePlayerBalance(player, -cost.get());
|
||||||
getLocales().getLocale(action.confirmationLocaleId, hook.get().formatCurrency(cost.get()))
|
getLocales().getLocale(action.confirmationLocaleId, hook.get().formatCurrency(cost.get()))
|
||||||
|
|||||||
@@ -71,18 +71,23 @@ public class SetHomeCommand extends CommandBase {
|
|||||||
final int freeHomes = onlineUser.getFreeHomes(plugin.getSettings().freeHomeSlots,
|
final int freeHomes = onlineUser.getFreeHomes(plugin.getSettings().freeHomeSlots,
|
||||||
plugin.getSettings().stackPermissionLimits);
|
plugin.getSettings().stackPermissionLimits);
|
||||||
if (fetchedData.isPresent()) {
|
if (fetchedData.isPresent()) {
|
||||||
|
final Settings.EconomyAction action = Settings.EconomyAction.ADDITIONAL_HOME_SLOT;
|
||||||
newSlotNeeded.set((currentHomes.size() + 1) > (freeHomes + fetchedData.get().homeSlots()));
|
newSlotNeeded.set((currentHomes.size() + 1) > (freeHomes + fetchedData.get().homeSlots()));
|
||||||
|
|
||||||
// If a new slot is needed, validate the user has enough funds to purchase one
|
// If a new slot is needed, validate the user has enough funds to purchase one
|
||||||
if (newSlotNeeded.get()) {
|
if (newSlotNeeded.get()) {
|
||||||
if (!plugin.validateEconomyCheck(onlineUser, Settings.EconomyAction.ADDITIONAL_HOME_SLOT)) {
|
if (!plugin.validateEconomyCheck(onlineUser, action)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
userDataToUpdate.set(new UserData(onlineUser, (currentHomes.size() + 1) - freeHomes,
|
userDataToUpdate.set(new UserData(onlineUser, (currentHomes.size() + 1) - freeHomes,
|
||||||
fetchedData.get().ignoringTeleports(), fetchedData.get().rtpCooldown()));
|
fetchedData.get().ignoringTeleports(), fetchedData.get().rtpCooldown()));
|
||||||
} else {
|
} else {
|
||||||
if (currentHomes.size() == freeHomes) {
|
if (currentHomes.size() == freeHomes) {
|
||||||
plugin.getLocales().getLocale("set_home_used_free_slots", Integer.toString(freeHomes))
|
plugin.getEconomyHook()
|
||||||
|
.flatMap(economyHook -> plugin.getSettings().getEconomyCost(action)
|
||||||
|
.map(economyHook::formatCurrency))
|
||||||
|
.flatMap(formatted -> plugin.getLocales().getLocale("set_home_used_free_slots",
|
||||||
|
Integer.toString(freeHomes), formatted))
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user