> getUserOfflinePosition(@NotNull User user) {
return plugin.supplyAsync(() -> plugin.getDatabase().getOfflinePosition(user));
}
/**
* Returns where the user last set their spawn point by right-clicking a bed or respawn anchor.
*
* The optional returned by this method will be empty unless HuskHomes is running cross-server mode
* and global respawning is enabled
*
* @param user The {@link User} to get the respawn position of
* @return The user's respawn {@link Position} if they have one, otherwise an empty {@link Optional}
* @since 3.0
*/
public CompletableFuture> getUserRespawnPosition(@NotNull User user) {
if (!plugin.getSettings().doCrossServer() || plugin.getSettings().isGlobalRespawning()) {
return CompletableFuture.completedFuture(Optional.empty());
}
return plugin.supplyAsync(() -> plugin.getDatabase().getRespawnPosition(user));
}
/**
* Returns if a user is currently warming up for a timed teleport; that is, they are in the state where they
* must stand still and not take damage for the set number of seconds before a teleport can be executed.
*
* @param user The {@link User} to check
* @return {@code true} if the user is currently warming up, otherwise {@code false}
* @since 3.0.2
*/
public boolean isUserWarmingUp(@NotNull User user) {
return plugin.isWarmingUp(user.getUuid());
}
/**
* Save {@link SavedUser} to the database, updating it if data for the user already exists,
* or adding new user data if it doesn't.
*
* @param savedUser The {@link SavedUser} to save
* @since 3.0
*/
public final void saveUserData(@NotNull SavedUser savedUser) {
plugin.runAsync(() -> plugin.getDatabase().updateUserData(savedUser));
}
/**
* Edit {@link SavedUser} data for a given player by username, if they exist.
*
* @param username The username of the user to edit data for.
* @param editor A {@link Consumer} that will be passed the {@link SavedUser} to edit
* @since 4.0
*/
public final void editUserData(@NotNull String username, @NotNull Consumer editor) {
plugin.getSavedUsers().stream()
.filter(u -> u.getUsername().equalsIgnoreCase(username)).findFirst()
.ifPresent(savedUser -> {
editor.accept(savedUser);
saveUserData(savedUser);
});
}
/**
* Edit {@link SavedUser} data for the given player's account {@link UUID}, if they exist.
*
* @param uuid The {@link UUID} of the user to edit data for.
* @param editor A {@link Consumer} that will be passed the {@link SavedUser} to edit
* @since 4.0
*/
public final void editUserData(@NotNull UUID uuid, @NotNull Consumer editor) {
plugin.getSavedUsers().stream()
.filter(u -> u.getUserUuid().equals(uuid)).findFirst()
.ifPresent(savedUser -> {
if (savedUser.getUser().getUuid().equals(uuid)) {
editor.accept(savedUser);
saveUserData(savedUser);
}
});
}
/**
* Get a list of {@link Home}s set by the given user.
*
* @param user The {@link User} to get the homes of
* @return A {@link CompletableFuture} that will complete with a list of {@link Home}s set by the user
*/
public final CompletableFuture> getUserHomes(@NotNull User user) {
return plugin.supplyAsync(() -> plugin.getDatabase().getHomes(user));
}
/**
* Get a list of {@link Home}s set by the given user that they have made public.
*
* @return A {@link CompletableFuture} with the user's public homes (where {@link Home#isPublic()})
* @since 3.0
*/
public final CompletableFuture> getUserPublicHomes(@NotNull User user) {
return plugin.supplyAsync(() -> plugin.getDatabase().getHomes(user).stream()
.filter(Home::isPublic)
.collect(Collectors.toList()));
}
/**
* Get a list of public homes local to this server.
*
* @param user The {@link User} to get the local public homes of
* @return A {@link CompletableFuture} that will complete with a list of public {@link Home}s local to the server
* @since 4.0
*/
public final CompletableFuture> getLocalPublicHomes(@NotNull User user) {
return plugin.supplyAsync(() -> plugin.getDatabase().getLocalPublicHomes(plugin));
}
/**
* Get a list of homes that have been made public ("public homes").
*
* @return A {@link CompletableFuture} that will complete with a list of public {@link Home}s
* @since 3.0
*/
public final CompletableFuture> getPublicHomes() {
return plugin.supplyAsync(() -> plugin.getDatabase().getPublicHomes());
}
/**
* Get a {@link Home} from the database owned by a given {@link User} with the specified name.
*
* @param user The {@link User} to get the home of
* @param homeName The name of the home to get
* @return A {@link CompletableFuture} with the {@link Home} if it exists, otherwise an empty {@link Optional}
* @since 3.0
*/
public final CompletableFuture> getHome(@NotNull User user, @NotNull String homeName) {
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(user, homeName));
}
/**
* Get a {@link Home} from the database by its {@link UUID unique ID}.
*
* @param homeUuid The {@link UUID} of the home to get
* @return A {@link CompletableFuture} with the {@link Home} if it exists, otherwise an empty {@link Optional}
*/
public final CompletableFuture> getHome(@NotNull UUID homeUuid) {
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(homeUuid));
}
/**
* 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
* @return a {@link CompletableFuture} that will complete with the created {@link Home}.
* @since 4.5
*/
public CompletableFuture createHome(@NotNull User owner, @NotNull String name, @NotNull Position position) {
return createHome(owner, name, position, false, false, 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
* @return a {@link CompletableFuture} that will complete with the created {@link Home}.
* @since 4.5.1
*/
public CompletableFuture 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
));
}
/**
* Delete a home for a given user with the specified name.
*
* @param owner The {@link User} to delete the home for
* @param name The name of the home
* @since 4.0
*/
public final void deleteHome(@NotNull User owner, @NotNull String name) {
plugin.runAsync(() -> plugin.getManager().homes().deleteHome(owner, name));
}
/**
* Delete a home.
*
* @param home The {@link Home} to delete
* @since 4.0
*/
public final void deleteHome(@NotNull Home home) {
plugin.runAsync(() -> plugin.getManager().homes().deleteHome(home));
}
/**
* Rename a home for a given user.
*
* @param owner The {@link User} to rename the home for
* @param oldName The name of the home to rename
* @param newName The new name of the home
* @since 4.0
*/
public final void renameHome(@NotNull User owner, @NotNull String oldName, @NotNull String newName) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeName(owner, oldName, newName));
}
/**
* Rename a home.
*
* @param home The {@link Home} to rename
* @param newName The new name of the home
* @since 4.0
*/
public final void renameHome(@NotNull Home home, @NotNull String newName) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeName(home, newName));
}
/**
* Set the privacy of a home.
*
* @param owner The {@link User} to set the privacy of the home for
* @param name The name of the home
* @param isPublic Whether the home should be public or not
* @since 4.0
*/
public final void setHomePrivacy(@NotNull User owner, @NotNull String name, boolean isPublic) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePrivacy(owner, name, isPublic));
}
/**
* Set the privacy of a home.
*
* @param home The {@link Home} to set the privacy of
* @param isPublic Whether the home should be public or not
* @since 4.0
*/
public final void setHomePrivacy(@NotNull Home home, boolean isPublic) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePrivacy(home, isPublic));
}
/**
* Set the description of a home.
*
* @param owner The {@link User} to set the description of the home for
* @param name The name of the home
* @param description The description of the home
* @since 4.0
*/
public final void setHomeDescription(@NotNull User owner, @NotNull String name, @NotNull String description) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeDescription(owner, name, description));
}
/**
* Set the description of a home.
*
* @param home The {@link Home} to set the description of
* @param description The description of the home
* @since 4.0
*/
public final void setHomeDescription(@NotNull Home home, @NotNull String description) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeDescription(home, description));
}
/**
* Relocate a home for a given user.
*
* @param owner The {@link User} to relocate the home for
* @param name The name of the home
* @param position The new {@link Position} of the home
* @since 4.0
*/
public final void relocateHome(@NotNull User owner, @NotNull String name, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePosition(owner, name, position));
}
/**
* Relocate a home.
*
* @param home The {@link Home} to relocate
* @param position The new {@link Position} of the home
* @since 4.0
*/
public final void relocateHome(@NotNull Home home, @NotNull Position position) {
plugin.runAsync(() -> plugin.getManager().homes().setHomePosition(home, position));
}
/**
* Set the meta tags of a home.
*
* @param owner The {@link User} to set the meta tags of the home for
* @param name The name of the home
* @param tags The meta tags to set
* @since 4.0
*/
public final void setHomeMetaTags(@NotNull User owner, @NotNull String name, @NotNull Map tags) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeMetaTags(owner, name, tags));
}
/**
* Set the meta tags of a home.
*
* @param home The {@link Home} to set the meta tags of
* @param tags The meta tags to set
* @since 4.0
*/
public final void setHomeMetaTags(@NotNull Home home, @NotNull Map tags) {
plugin.runAsync(() -> plugin.getManager().homes().setHomeMetaTags(home, tags));
}
/**
* Edit the meta tags of a home.
*
* @param owner The {@link User} to edit the meta tags of the home for
* @param name The name of the home
* @param tagEditor The {@link Consumer} to edit the meta tags with
* @since 4.0
*/
public final void editHomeMetaTags(@NotNull User owner, @NotNull String name,
@NotNull Consumer