Skip to content

Commit

Permalink
refactor: add bypass for home slot validation, fix #706
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Nov 5, 2024
1 parent 97769ce commit d89f798
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private int importHomes() {
this.normalizeName(homeName),
BukkitHuskHomes.Adapter.adapt(essentialsUser.getHome(homeName), plugin.getServerName()),
true,
false,
true,
true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,30 @@ public CompletableFuture<Home> createHome(@NotNull User owner, @NotNull String n
public CompletableFuture<Home> createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes) {
return plugin.supplyAsync(() -> plugin.getManager().homes().createHome(
owner, name, position, overwrite, buyAdditionalSlots, ignoreMaxHomes
owner, name, position, overwrite, buyAdditionalSlots, ignoreMaxHomes, false
));
}

/**
* Create a home for a given user with the specified name and position.
* The returned future may complete exceptionally with a {@link net.william278.huskhomes.util.ValidationException}
* if the home could not be created.
*
* @param owner The {@link User} to create the home for
* @param name The name of the home
* @param position The {@link Position} of the home
* @param overwrite Whether to overwrite an existing home with the same name
* @param buyAdditionalSlots Whether to buy additional home slots if the user has reached their maximum
* @param ignoreMaxHomes Whether to ignore the maximum number of homes a user can have
* @param ignoreHomeSlots Whether to ignore the number of home slots a user has
* @return a {@link CompletableFuture} that will complete with the created {@link Home}.
* @since 4.8
*/
public CompletableFuture<Home> createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes,
boolean ignoreHomeSlots) {
return plugin.supplyAsync(() -> plugin.getManager().homes().createHome(
owner, name, position, overwrite, buyAdditionalSlots, ignoreMaxHomes, ignoreHomeSlots
));
}

Expand Down Expand Up @@ -786,7 +809,7 @@ public final TeleportBuilder teleportBuilder() {
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, boolean timedTeleport,
@NotNull String... rtpArgs) {
if (plugin.getSettings().getRtp().isCrossServer() && (plugin.getSettings().getCrossServer().isEnabled() &&
plugin.getSettings().getCrossServer().getBrokerType() == Broker.Type.REDIS)) {
plugin.getSettings().getCrossServer().getBrokerType() == Broker.Type.REDIS)) {
List<String> allowedServers = plugin.getSettings().getRtp().getRandomTargetServers();
String randomServer = allowedServers.get(random.nextInt(allowedServers.size()));
if (randomServer.equals(plugin.getServerName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public void removeUserHomes(@NotNull User user) {

@NotNull
public Home createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes)
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes,
boolean ignoreHomeSlots)
throws ValidationException {
final Optional<Home> existingHome = plugin.getDatabase().getHome(owner, name);
if (existingHome.isPresent() && !overwrite) {
Expand All @@ -220,7 +221,7 @@ public Home createHome(@NotNull User owner, @NotNull String name, @NotNull Posit
final SavedUser savedOwner = plugin.getSavedUser(owner)
.or(() -> plugin.getDatabase().getUser(owner.getUuid()))
.orElseThrow(() -> new IllegalStateException("User data not found for " + owner.getUuid()));
if (plugin.getSettings().getEconomy().isEnabled()
if (!ignoreHomeSlots && plugin.getSettings().getEconomy().isEnabled()
&& homes > getFreeHomes(owner) && homes > savedOwner.getHomeSlots()) {
if (!buyAdditionalSlots || plugin.getEconomyHook().isEmpty() || !(owner instanceof OnlineUser online)) {
throw new ValidationException(ValidationException.Type.NOT_ENOUGH_HOME_SLOTS);
Expand Down Expand Up @@ -250,7 +251,7 @@ public void createHome(@NotNull OnlineUser owner, @NotNull String name, @NotNull
throws ValidationException {
this.createHome(
owner, name, position, plugin.getSettings().getGeneral().getNames().isOverwriteExisting(),
true, false
true, false, false
);
}

Expand Down

0 comments on commit d89f798

Please sign in to comment.