mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 22:16:22 +00:00
homes: Fix calculation of new home count when overwriting, close #293
This commit is contained in:
1 file changed
+5
-5
@@ -162,24 +162,24 @@ public class HomesManager {
|
|||||||
throw new ValidationException(ValidationException.Type.NAME_INVALID);
|
throw new ValidationException(ValidationException.Type.NAME_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate against user max homes
|
// Determine what the new home count would be & validate against user max homes
|
||||||
final int homeCount = plugin.getDatabase().getHomes(owner).size();
|
int homes = plugin.getDatabase().getHomes(owner).size() + (existingHome.isPresent() ? 0 : 1);
|
||||||
if (homeCount >= getMaxHomes(owner)) {
|
if (homes > getMaxHomes(owner)) {
|
||||||
throw new ValidationException(ValidationException.Type.REACHED_MAX_HOMES);
|
throw new ValidationException(ValidationException.Type.REACHED_MAX_HOMES);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate against user home slots
|
// Validate against user home slots
|
||||||
final SavedUser savedOwner = plugin.getSavedUser(owner)
|
final SavedUser savedOwner = plugin.getSavedUser(owner)
|
||||||
.orElseThrow(() -> new IllegalStateException("User data not found for " + owner.getUuid()));
|
.orElseThrow(() -> new IllegalStateException("User data not found for " + owner.getUuid()));
|
||||||
if (plugin.getSettings().doEconomy() && homeCount >= getFreeHomes(owner) && homeCount >= savedOwner.getHomeSlots()) {
|
if (plugin.getSettings().doEconomy() && homes > getFreeHomes(owner) && homes > savedOwner.getHomeSlots()) {
|
||||||
if (!buyAdditionalSlots || plugin.getEconomyHook().isEmpty() || !(owner instanceof OnlineUser online)) {
|
if (!buyAdditionalSlots || plugin.getEconomyHook().isEmpty() || !(owner instanceof OnlineUser online)) {
|
||||||
throw new ValidationException(ValidationException.Type.NOT_ENOUGH_HOME_SLOTS);
|
throw new ValidationException(ValidationException.Type.NOT_ENOUGH_HOME_SLOTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Perform transaction and increase user slot size
|
||||||
if (!plugin.canPerformTransaction(online, EconomyHook.Action.ADDITIONAL_HOME_SLOT)) {
|
if (!plugin.canPerformTransaction(online, EconomyHook.Action.ADDITIONAL_HOME_SLOT)) {
|
||||||
throw new ValidationException(ValidationException.Type.NOT_ENOUGH_MONEY);
|
throw new ValidationException(ValidationException.Type.NOT_ENOUGH_MONEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.performTransaction(online, EconomyHook.Action.ADDITIONAL_HOME_SLOT);
|
plugin.performTransaction(online, EconomyHook.Action.ADDITIONAL_HOME_SLOT);
|
||||||
plugin.editUserData(online, (SavedUser saved) -> saved.setHomeSlots(saved.getHomeSlots() + 1));
|
plugin.editUserData(online, (SavedUser saved) -> saved.setHomeSlots(saved.getHomeSlots() + 1));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user