mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 22:16:08 +00:00
Fix max home locale placeholder, account for free homes, fix #338
This commit is contained in:
5 files changed
+38
-31
No files matched your search
@@ -45,18 +45,9 @@ public class PlaceholderAPIHook extends Hook {
|
||||
case "homes_count" -> String.valueOf(plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.getOrDefault(player.getUsername(), List.of()).size());
|
||||
case "max_homes" -> String.valueOf(player.getMaxHomes(
|
||||
plugin.getSettings().getMaxHomes(),
|
||||
plugin.getSettings().doStackPermissionLimits()
|
||||
));
|
||||
case "max_public_homes" -> String.valueOf(player.getMaxPublicHomes(
|
||||
plugin.getSettings().getMaxPublicHomes(),
|
||||
plugin.getSettings().doStackPermissionLimits()
|
||||
));
|
||||
case "free_home_slots" -> String.valueOf(player.getFreeHomes(
|
||||
plugin.getSettings().getFreeHomeSlots(),
|
||||
plugin.getSettings().doStackPermissionLimits()
|
||||
));
|
||||
case "max_homes" -> String.valueOf(plugin.getManager().homes().getMaxHomes(player));
|
||||
case "max_public_homes" -> String.valueOf(plugin.getManager().homes().getMaxPublicHomes(player));
|
||||
case "free_home_slots" -> String.valueOf(plugin.getManager().homes().getFreeHomes(player));
|
||||
case "home_slots" -> String.valueOf(plugin.getSavedUser(player)
|
||||
.map(SavedUser::getHomeSlots)
|
||||
.orElse(0));
|
||||
|
||||
@@ -578,7 +578,7 @@ public abstract class BaseHuskHomesAPI {
|
||||
* @since 3.0
|
||||
*/
|
||||
public final int getMaxHomeSlots(@NotNull OnlineUser user) {
|
||||
return user.getMaxHomes(plugin.getSettings().getMaxHomes(), plugin.getSettings().doStackPermissionLimits());
|
||||
return plugin.getManager().homes().getMaxHomes(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -591,7 +591,7 @@ public abstract class BaseHuskHomesAPI {
|
||||
* @since 3.0
|
||||
*/
|
||||
public final int getFreeHomeSlots(@NotNull OnlineUser user) {
|
||||
return user.getFreeHomes(plugin.getSettings().getFreeHomeSlots(), plugin.getSettings().doStackPermissionLimits());
|
||||
return plugin.getManager().homes().getFreeHomes(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,7 +602,7 @@ public abstract class BaseHuskHomesAPI {
|
||||
* @since 3.0
|
||||
*/
|
||||
public final int getMaxPublicHomeSlots(@NotNull OnlineUser user) {
|
||||
return user.getMaxPublicHomes(plugin.getSettings().getMaxPublicHomes(), plugin.getSettings().doStackPermissionLimits());
|
||||
return plugin.getManager().homes().getMaxPublicHomes(user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -170,10 +170,7 @@ public class EditHomeCommand extends SavedPositionCommand<Home> {
|
||||
try {
|
||||
plugin.getManager().homes().setHomePrivacy(event.getHome(), home.isPublic());
|
||||
} catch (ValidationException e) {
|
||||
int maxHomes = executor instanceof OnlineUser user ?
|
||||
user.getMaxPublicHomes(plugin.getSettings().getMaxPublicHomes(),
|
||||
plugin.getSettings().doStackPermissionLimits()) :
|
||||
plugin.getSettings().getMaxPublicHomes();
|
||||
int maxHomes = plugin.getManager().homes().getMaxPublicHomes(executor instanceof OnlineUser user ? user : null);
|
||||
e.dispatchHomeError(executor, false, plugin, Integer.toString(maxHomes));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.util.ValidationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -145,18 +146,14 @@ public class HomesManager {
|
||||
|
||||
// Validate against user max homes
|
||||
final int homeCount = plugin.getDatabase().getHomes(owner).size();
|
||||
int maxHomes = plugin.getSettings().getMaxHomes();
|
||||
if (owner instanceof OnlineUser online) {
|
||||
maxHomes = online.getMaxHomes(maxHomes, plugin.getSettings().doStackPermissionLimits());
|
||||
}
|
||||
if (homeCount >= maxHomes) {
|
||||
if (homeCount >= getMaxHomes(owner)) {
|
||||
throw new ValidationException(ValidationException.Type.REACHED_MAX_HOMES);
|
||||
}
|
||||
|
||||
// Validate against user home slots
|
||||
final SavedUser savedOwner = plugin.getSavedUser(owner)
|
||||
.orElseThrow(() -> new IllegalStateException("User data not found for " + owner.getUuid()));
|
||||
if (plugin.getSettings().doEconomy() && homeCount >= savedOwner.getHomeSlots()) {
|
||||
if (plugin.getSettings().doEconomy() && homeCount >= getFreeHomes(owner) && homeCount >= savedOwner.getHomeSlots()) {
|
||||
if (!buyAdditionalSlots || plugin.getEconomyHook().isEmpty() || !(owner instanceof OnlineUser online)) {
|
||||
throw new ValidationException(ValidationException.Type.NOT_ENOUGH_HOME_SLOTS);
|
||||
}
|
||||
@@ -272,13 +269,11 @@ public class HomesManager {
|
||||
}
|
||||
|
||||
public void setHomePrivacy(@NotNull Home home, boolean isPublic) {
|
||||
if (isPublic && home.getOwner() instanceof OnlineUser online) {
|
||||
if (isPublic) {
|
||||
final int publicHomes = plugin.getDatabase().getHomes(home.getOwner()).stream()
|
||||
.filter(Home::isPublic)
|
||||
.toList().size();
|
||||
final int publicSlots = online.getMaxPublicHomes(plugin.getSettings().getMaxPublicHomes(),
|
||||
plugin.getSettings().doStackPermissionLimits());
|
||||
if (publicHomes >= publicSlots) {
|
||||
if (publicHomes >= getMaxPublicHomes(home.getOwner())) {
|
||||
throw new ValidationException(ValidationException.Type.REACHED_MAX_PUBLIC_HOMES);
|
||||
}
|
||||
}
|
||||
@@ -303,4 +298,25 @@ public class HomesManager {
|
||||
this.cacheHome(home, true);
|
||||
}
|
||||
|
||||
public int getMaxHomes(@Nullable User user) {
|
||||
return user instanceof OnlineUser online ? online.getMaxHomes(
|
||||
plugin.getSettings().getMaxHomes(),
|
||||
plugin.getSettings().doStackPermissionLimits()
|
||||
) : plugin.getSettings().getMaxHomes();
|
||||
}
|
||||
|
||||
public int getMaxPublicHomes(@Nullable User user) {
|
||||
return user instanceof OnlineUser online ? online.getMaxPublicHomes(
|
||||
plugin.getSettings().getMaxPublicHomes(),
|
||||
plugin.getSettings().doStackPermissionLimits()
|
||||
) : plugin.getSettings().getMaxPublicHomes();
|
||||
}
|
||||
|
||||
public int getFreeHomes(@Nullable User user) {
|
||||
return user instanceof OnlineUser online ? online.getFreeHomes(
|
||||
plugin.getSettings().getFreeHomeSlots(),
|
||||
plugin.getSettings().doStackPermissionLimits()
|
||||
) : plugin.getSettings().getFreeHomeSlots();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.william278.huskhomes.util;
|
||||
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ValidationException extends IllegalArgumentException {
|
||||
@@ -25,10 +26,12 @@ public class ValidationException extends IllegalArgumentException {
|
||||
.getLocale("error_home_name_characters", args)
|
||||
.ifPresent(viewer::sendMessage);
|
||||
case NOT_ENOUGH_HOME_SLOTS, REACHED_MAX_HOMES -> plugin.getLocales()
|
||||
.getLocale("error_set_home_maximum_homes", args)
|
||||
.getLocale("error_set_home_maximum_homes", Integer.toString(plugin.getManager().homes()
|
||||
.getMaxHomes(viewer instanceof OnlineUser user ? user : null)))
|
||||
.ifPresent(viewer::sendMessage);
|
||||
case REACHED_MAX_PUBLIC_HOMES -> plugin.getLocales()
|
||||
.getLocale("error_edit_home_maximum_public_homes", args)
|
||||
.getLocale("error_edit_home_maximum_public_homes", Integer.toString(plugin.getManager().homes()
|
||||
.getMaxPublicHomes(viewer instanceof OnlineUser user ? user : null)))
|
||||
.ifPresent(viewer::sendMessage);
|
||||
case DESCRIPTION_INVALID -> plugin.getLocales()
|
||||
.getLocale("error_home_description_characters", args)
|
||||
|
||||
Reference in new issue
Block a user