mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
refactor: add bypass for home slot validation, fix #706
This commit is contained in:
3 files changed
+30
-5
No files matched your search
@@ -69,6 +69,7 @@ public class EssentialsXImporter extends Importer {
|
|||||||
this.normalizeName(homeName),
|
this.normalizeName(homeName),
|
||||||
BukkitHuskHomes.Adapter.adapt(essentialsUser.getHome(homeName), plugin.getServerName()),
|
BukkitHuskHomes.Adapter.adapt(essentialsUser.getHome(homeName), plugin.getServerName()),
|
||||||
true,
|
true,
|
||||||
|
false,
|
||||||
true,
|
true,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -370,7 +370,30 @@ public class BaseHuskHomesAPI {
|
|||||||
public CompletableFuture<Home> createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
|
public CompletableFuture<Home> createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
|
||||||
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes) {
|
boolean overwrite, boolean buyAdditionalSlots, boolean ignoreMaxHomes) {
|
||||||
return plugin.supplyAsync(() -> plugin.getManager().homes().createHome(
|
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
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -786,7 +809,7 @@ public class BaseHuskHomesAPI {
|
|||||||
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, boolean timedTeleport,
|
public final void randomlyTeleportPlayer(@NotNull OnlineUser user, boolean timedTeleport,
|
||||||
@NotNull String... rtpArgs) {
|
@NotNull String... rtpArgs) {
|
||||||
if (plugin.getSettings().getRtp().isCrossServer() && (plugin.getSettings().getCrossServer().isEnabled() &&
|
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();
|
List<String> allowedServers = plugin.getSettings().getRtp().getRandomTargetServers();
|
||||||
String randomServer = allowedServers.get(random.nextInt(allowedServers.size()));
|
String randomServer = allowedServers.get(random.nextInt(allowedServers.size()));
|
||||||
if (randomServer.equals(plugin.getServerName())) {
|
if (randomServer.equals(plugin.getServerName())) {
|
||||||
|
|||||||
@@ -200,7 +200,8 @@ public class HomesManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Home createHome(@NotNull User owner, @NotNull String name, @NotNull Position position,
|
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 {
|
throws ValidationException {
|
||||||
final Optional<Home> existingHome = plugin.getDatabase().getHome(owner, name);
|
final Optional<Home> existingHome = plugin.getDatabase().getHome(owner, name);
|
||||||
if (existingHome.isPresent() && !overwrite) {
|
if (existingHome.isPresent() && !overwrite) {
|
||||||
@@ -220,7 +221,7 @@ public class HomesManager {
|
|||||||
final SavedUser savedOwner = plugin.getSavedUser(owner)
|
final SavedUser savedOwner = plugin.getSavedUser(owner)
|
||||||
.or(() -> plugin.getDatabase().getUser(owner.getUuid()))
|
.or(() -> plugin.getDatabase().getUser(owner.getUuid()))
|
||||||
.orElseThrow(() -> new IllegalStateException("User data not found for " + 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()) {
|
&& 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);
|
||||||
@@ -250,7 +251,7 @@ public class HomesManager {
|
|||||||
throws ValidationException {
|
throws ValidationException {
|
||||||
this.createHome(
|
this.createHome(
|
||||||
owner, name, position, plugin.getSettings().getGeneral().getNames().isOverwriteExisting(),
|
owner, name, position, plugin.getSettings().getGeneral().getNames().isOverwriteExisting(),
|
||||||
true, false
|
true, false, false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user