diff --git a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java index d4f9ddfd..59c56bb9 100644 --- a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java +++ b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java @@ -16,6 +16,7 @@ import net.william278.huskhomes.user.User; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -352,6 +353,46 @@ public abstract class BaseHuskHomesAPI { 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> tagEditor) { + plugin.runAsync(() -> plugin.getDatabase().getHome(owner, name).ifPresent(home -> { + final Map tags = home.getMeta().getTags(); + tagEditor.accept(tags); + setHomeMetaTags(home, tags); + })); + } + /** * Get a list of {@link Warp}s local to this server * @@ -482,6 +523,45 @@ public abstract class BaseHuskHomesAPI { plugin.runAsync(() -> plugin.getManager().warps().setWarpPosition(warp, position)); } + /** + * Set the meta tags of a {@link Warp} by name + * + * @param name The name of the warp to set the meta tags of + * @param tags The new meta tags of the warp + * @since 4.0 + */ + public final void setWarpMetaTags(@NotNull String name, @NotNull Map tags) { + plugin.runAsync(() -> plugin.getManager().warps().setWarpMetaTags(name, tags)); + } + + /** + * Set the meta tags of a {@link Warp} + * + * @param warp The {@link Warp} to set the meta tags of + * @param tags The new meta tags of the warp + * @since 4.0 + */ + public final void setWarpMetaTags(@NotNull Warp warp, @NotNull Map tags) { + plugin.runAsync(() -> plugin.getManager().warps().setWarpMetaTags(warp, tags)); + } + + /** + * Edit the meta tags of a {@link Warp} by name + * + * @param name The name of the warp to edit the meta tags of + * @param tagEditor A {@link Consumer} that will be passed the current meta tags of the warp + * and should edit them in-place + * @since 4.0 + */ + public final void editWarpMetaTag(@NotNull String name, @NotNull Consumer> tagEditor) { + plugin.runAsync(() -> plugin.getDatabase().getWarp(name).ifPresent(warp -> { + final Map tags = warp.getMeta().getTags(); + tagEditor.accept(tags); + setWarpMetaTags(warp, tags); + })); + } + + /** * Get the canonical {@link Position} of the spawn point. Note that if cross-server and global spawn * are enabled in the config, this may not return a position on this server. diff --git a/common/src/main/java/net/william278/huskhomes/manager/HomesManager.java b/common/src/main/java/net/william278/huskhomes/manager/HomesManager.java index 2ac52cd3..9ae08e88 100644 --- a/common/src/main/java/net/william278/huskhomes/manager/HomesManager.java +++ b/common/src/main/java/net/william278/huskhomes/manager/HomesManager.java @@ -264,4 +264,19 @@ public class HomesManager { this.cacheHome(home, true); } + public void setHomeMetaTags(@NotNull User owner, @NotNull String name, @NotNull Map tags) throws ValidationException { + final Optional optionalHome = plugin.getDatabase().getHome(owner, name); + if (optionalHome.isEmpty()) { + throw new ValidationException(ValidationException.Type.NOT_FOUND); + } + + this.setHomeMetaTags(optionalHome.get(), tags); + } + + public void setHomeMetaTags(@NotNull Home home, @NotNull Map tags) { + home.getMeta().setTags(tags); + plugin.getDatabase().saveHome(home); + this.cacheHome(home, true); + } + } diff --git a/common/src/main/java/net/william278/huskhomes/manager/WarpsManager.java b/common/src/main/java/net/william278/huskhomes/manager/WarpsManager.java index a9ac6501..83b876c6 100644 --- a/common/src/main/java/net/william278/huskhomes/manager/WarpsManager.java +++ b/common/src/main/java/net/william278/huskhomes/manager/WarpsManager.java @@ -11,6 +11,7 @@ import net.william278.huskhomes.util.ValidationException; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; @@ -175,4 +176,19 @@ public class WarpsManager { this.cacheWarp(warp, true); } + public void setWarpMetaTags(@NotNull String name, @NotNull Map tags) throws ValidationException { + final Optional optionalWarp = plugin.getDatabase().getWarp(name); + if (optionalWarp.isEmpty()) { + throw new ValidationException(ValidationException.Type.NOT_FOUND); + } + + this.setWarpMetaTags(optionalWarp.get(), tags); + } + + public void setWarpMetaTags(@NotNull Warp warp, @NotNull Map tags) { + warp.getMeta().setTags(tags); + plugin.getDatabase().saveWarp(warp); + this.cacheWarp(warp, true); + } + }