From e11f430ed763f1035b0fe3cb9f19c3b95a810dad Mon Sep 17 00:00:00 2001 From: ybw0014 Date: Wed, 16 Oct 2024 13:52:11 -0700 Subject: [PATCH] feat: disallow changing wiki URL after it has been set --- .../thebusybiscuit/slimefun4/api/SlimefunAddon.java | 8 ++++---- .../thebusybiscuit/slimefun4/api/items/SlimefunItem.java | 3 ++- .../thebusybiscuit/slimefun4/implementation/Slimefun.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java index e3221fe900..c27d74b69c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAddon.java @@ -98,12 +98,12 @@ default boolean hasDependency(@Nonnull String dependency) { } /** - * This method returns the wiki URL for all the items this {@link SlimefunAddon}. - * The "%item%" placeholder will be replaced with the SlimefunItem's ID. + * This method returns the wiki URL template for all the items this {@link SlimefunAddon}. + * The "%item%" placeholder will be replaced with the SlimefunItem's ID by default. * - * @return The wiki URL for this {@link SlimefunAddon}. + * @return The wiki URL template for this {@link SlimefunAddon}. */ - default @Nonnull String getWikiURL() { + default @Nonnull String getWikiUrlTemplate() { return ""; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index 65592d4358..a116204888 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -907,7 +907,7 @@ public final void addOfficialWikipage(@Nonnull String page) { public final void addWikiPage(@Nonnull String page) { Preconditions.checkArgument(page != null, "Wiki page cannot be null."); Preconditions.checkState(getState() != ItemState.UNREGISTERED, "Wiki page can only be added after item has been registered."); - addCustomWikiPage(getAddon().getWikiURL().replace("%item%", page)); + addCustomWikiPage(getAddon().getWikiUrlTemplate().replace("%item%", page)); } /** @@ -918,6 +918,7 @@ public final void addWikiPage(@Nonnull String page) { */ public final void addCustomWikiPage(@Nonnull String url) { Preconditions.checkArgument(url != null, "Wiki page cannot be null."); + Preconditions.checkState(wikiURL.isEmpty(), "Wiki page cannot be modified after it has been set."); wikiURL = Optional.of(url); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java index fe6615fb91..da960e8df6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -403,7 +403,7 @@ public String getBugTrackerURL() { } @Override - public @Nonnull String getWikiURL() { + public @Nonnull String getWikiUrlTemplate() { return "https://github.com/Slimefun/Slimefun4/wiki/%item%"; }