Skip to content

Commit

Permalink
feat: match the url pattern to detect official Slimefun wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Oct 16, 2024
1 parent e11f430 commit 92645fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Locale;
import java.util.Optional;
import java.util.logging.Level;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -68,6 +69,7 @@
public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {

private static final int MAX_ITEM_GROUPS = 36;
private static final Pattern SLIMEFUN_WIKI_PATTERN = Pattern.compile("^" + Pattern.quote(Slimefun.instance().getWikiUrlTemplate()).replace("%item%", "(.+)") + "$");

private final int[] recipeSlots = { 3, 4, 5, 12, 13, 14, 21, 22, 23 };
private final ItemStack item;
Expand Down Expand Up @@ -516,9 +518,10 @@ public void displayItem(PlayerProfile profile, SlimefunItem item, boolean addToH

if (wiki.isPresent()) {
String message = Slimefun.getLocalization().getMessage(p, "guide.tooltips.wiki.third-party");
if (item.getAddon() instanceof Slimefun) {
if (SLIMEFUN_WIKI_PATTERN.matcher(wiki.get()).matches()) {
message = Slimefun.getLocalization().getMessage(p, "guide.tooltips.wiki.slimefun");
}

menu.addItem(8, new CustomItemStack(
Material.KNOWLEDGE_BOOK,
ChatColor.WHITE + Slimefun.getLocalization().getMessage(p, "guide.tooltips.wiki.button").replace("%addon%", item.getAddon().getName()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ void testWikiPages() {
Optional<String> wiki = item.getWikipage();
Assertions.assertTrue(wiki.isPresent());
Assertions.assertEquals("https://github.com/Slimefun/Slimefun4/wiki/Test", wiki.get());

// wiki page shouldn't be changed if it already exists
Assertions.assertThrows(IllegalStateException.class, () -> item.addWikiPage("Test2"));
}

@Test
Expand Down

0 comments on commit 92645fc

Please sign in to comment.