From 3fbb1289f2b42ace2cad4249bb391642adec3b55 Mon Sep 17 00:00:00 2001 From: Dominik Sievert Date: Mon, 26 Oct 2026 12:22:10 +0100 Subject: [PATCH] fix: leave hidden challenges out of the catalog export / purpur regressions in jump and run and interval actions --- catalog/export/catalog.json | 224 ------------------ .../challenges/catalog/CatalogExport.java | 4 +- .../challenges/catalog/CatalogExportTest.java | 4 +- .../custom/TriggerActionChallenge.java | 8 + .../extraworld/JumpAndRunChallenge.java | 2 + .../extraworld/WaterMLGChallenge.java | 3 + .../custom/TriggerActionChallengeTest.java | 78 ++++++ 7 files changed, 95 insertions(+), 228 deletions(-) create mode 100644 plugin/src/test/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallengeTest.java diff --git a/catalog/export/catalog.json b/catalog/export/catalog.json index c0e180e71..f4dc83bd9 100644 --- a/catalog/export/catalog.json +++ b/catalog/export/catalog.json @@ -41558,230 +41558,6 @@ } } }, - { - "id": "collecteverything", - "category": "misc_goal", - "icon": { - "material": "DRAGON_EGG" - }, - "name": { - "en": "Collect Everything", - "de": "Alles sammeln" - }, - "description": { - "en": [ - "Together, find every item, kill every mob and get every advancement once" - ], - "de": [ - "Gemeinsam jedes Item finden, jeden Mob töten und jedes Advancement einmal holen" - ] - }, - "styled": { - "en": { - "name": [ - { - "text": "Collect Everything", - "color": "#FFAA00" - } - ], - "description": [ - [ - { - "text": "Together, find " - }, - { - "text": "every item", - "color": "#FFAA00" - }, - { - "text": "," - } - ], - [ - { - "text": "kill " - }, - { - "text": "every mob", - "color": "#FFAA00" - }, - { - "text": " and get" - } - ], - [ - { - "text": "every advancement", - "color": "#FFAA00" - }, - { - "text": " once" - } - ] - ], - "tooltip": [ - [ - { - "text": "»", - "color": "#555555" - }, - { - "text": " " - }, - { - "text": "Collect Everything", - "color": "#FFAA00" - } - ], - [ - { - "text": " " - } - ], - [ - { - "text": "Together, find ", - "color": "#AAAAAA" - }, - { - "text": "every item", - "color": "#FFAA00" - }, - { - "text": ",", - "color": "#AAAAAA" - } - ], - [ - { - "text": "kill ", - "color": "#AAAAAA" - }, - { - "text": "every mob", - "color": "#FFAA00" - }, - { - "text": " and get", - "color": "#AAAAAA" - } - ], - [ - { - "text": "every advancement", - "color": "#FFAA00" - }, - { - "text": " once", - "color": "#AAAAAA" - } - ] - ] - }, - "de": { - "name": [ - { - "text": "Alles sammeln", - "color": "#FFAA00" - } - ], - "description": [ - [ - { - "text": "Gemeinsam " - }, - { - "text": "jedes Item", - "color": "#FFAA00" - }, - { - "text": " finden," - } - ], - [ - { - "text": "jeden Mob", - "color": "#FFAA00" - }, - { - "text": " töten und " - }, - { - "text": "jedes", - "color": "#FFAA00" - } - ], - [ - { - "text": "Advancement", - "color": "#FFAA00" - }, - { - "text": " einmal holen" - } - ] - ], - "tooltip": [ - [ - { - "text": "»", - "color": "#555555" - }, - { - "text": " " - }, - { - "text": "Alles sammeln", - "color": "#FFAA00" - } - ], - [ - { - "text": " " - } - ], - [ - { - "text": "Gemeinsam ", - "color": "#AAAAAA" - }, - { - "text": "jedes Item", - "color": "#FFAA00" - }, - { - "text": " finden,", - "color": "#AAAAAA" - } - ], - [ - { - "text": "jeden Mob", - "color": "#FFAA00" - }, - { - "text": " töten und ", - "color": "#AAAAAA" - }, - { - "text": "jedes", - "color": "#FFAA00" - } - ], - [ - { - "text": "Advancement", - "color": "#FFAA00" - }, - { - "text": " einmal holen", - "color": "#AAAAAA" - } - ] - ] - } - } - }, { "id": "damagerulenone", "category": "damage_rule", diff --git a/catalog/src/main/java/net/cyperia/challenges/catalog/CatalogExport.java b/catalog/src/main/java/net/cyperia/challenges/catalog/CatalogExport.java index c09b612b8..ea505b81c 100644 --- a/catalog/src/main/java/net/cyperia/challenges/catalog/CatalogExport.java +++ b/catalog/src/main/java/net/cyperia/challenges/catalog/CatalogExport.java @@ -32,7 +32,7 @@ import java.util.function.Function; import java.util.regex.Pattern; -// The registered challenges and their categories with their texts in every bundled language, plain and as +// The registered challenges that are not hidden, and their categories with their texts in every bundled language, plain and as // coloured runs the way the menu shows them, for readers without the plugin such as a website. The file is // committed, so it can be read at a stable URL. public final class CatalogExport { @@ -74,7 +74,7 @@ public static String render(@NotNull ChallengeCatalog catalog) { JsonArray challenges = new JsonArray(); for (Challenge challenge : catalog.challenges()) { - if (!challenge.registered()) continue; + if (!challenge.registered() || challenge.hidden()) continue; JsonObject json = new JsonObject(); json.addProperty("id", challenge.id()); if (!challenge.fallbackIds().isEmpty()) { diff --git a/catalog/src/test/java/net/cyperia/challenges/catalog/CatalogExportTest.java b/catalog/src/test/java/net/cyperia/challenges/catalog/CatalogExportTest.java index 4dde46e15..c62868225 100644 --- a/catalog/src/test/java/net/cyperia/challenges/catalog/CatalogExportTest.java +++ b/catalog/src/test/java/net/cyperia/challenges/catalog/CatalogExportTest.java @@ -33,12 +33,12 @@ void textsKeepNoMarkupOrArguments() { } @Test - void leavesOutUnregisteredChallenges() { + void leavesOutUnregisteredAndHiddenChallenges() { ChallengeCatalog catalog = ChallengeCatalog.load(); JsonObject export = JsonParser.parseString(CatalogExport.render(catalog)).getAsJsonObject(); Set exported = export.getAsJsonArray("challenges").asList().stream() .map(entry -> entry.getAsJsonObject().get("id").getAsString()).collect(Collectors.toSet()); - catalog.challenges().forEach(challenge -> assertEquals(challenge.registered(), exported.contains(challenge.id()), challenge.id())); + catalog.challenges().forEach(challenge -> assertEquals(challenge.registered() && !challenge.hidden(), exported.contains(challenge.id()), challenge.id())); } @Test diff --git a/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallenge.java b/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallenge.java index f8192e16f..688814118 100644 --- a/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallenge.java +++ b/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallenge.java @@ -1,10 +1,13 @@ package net.cyperia.challenges.plugin.challenges.custom; +import net.cyperia.challenges.plugin.Challenges; import net.cyperia.challenges.plugin.challenges.custom.settings.ChallengeExecutionData; import net.cyperia.challenges.plugin.challenges.custom.settings.action.ChallengeAction; import net.cyperia.challenges.plugin.challenges.custom.settings.trigger.ChallengeTrigger; import net.cyperia.challenges.plugin.challenges.custom.settings.trigger.IChallengeTrigger; import net.cyperia.challenges.plugin.challenges.type.IChallenge; +import net.cyperia.commons.bukkit.utils.misc.Regions; +import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -94,6 +97,11 @@ default boolean isTriggerMet(ChallengeExecutionData data) { default void executeAction(ChallengeExecutionData challengeExecutionData) { ChallengeAction action = getAction(); if (action == null) return; + // Async triggers (the interval) hand their actions to the next tick, as actions touch the world + if (!Bukkit.isPrimaryThread()) { + Regions.nextTick(Challenges.getInstance(), () -> action.execute(challengeExecutionData, getSubActions())); + return; + } action.execute(challengeExecutionData, getSubActions()); } diff --git a/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/JumpAndRunChallenge.java b/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/JumpAndRunChallenge.java index f1f73ce10..826cbcb2d 100644 --- a/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/JumpAndRunChallenge.java +++ b/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/JumpAndRunChallenge.java @@ -199,6 +199,8 @@ public void onMove(@NotNull PlayerMoveEvent event) { if (!isInExtraWorld()) return; if (targetBlock == null) return; if (event.getTo() == null) return; + // The teleport into the extra world completes later, until then the player still moves in the game world + if (event.getTo().getWorld() != getExtraWorld()) return; if (BlockUtils.isSameBlockLocation(event.getTo(), targetBlock.getLocation().add(0, 1, 0))) { if (++currentJump >= jumps) { diff --git a/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/WaterMLGChallenge.java b/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/WaterMLGChallenge.java index 79fa55fa1..1d31c3a8a 100644 --- a/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/WaterMLGChallenge.java +++ b/plugin/src/main/java/net/cyperia/challenges/plugin/challenges/implementation/challenge/extraworld/WaterMLGChallenge.java @@ -42,6 +42,7 @@ public void startWorldChallenge() { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerBucketEmpty(@NotNull PlayerBucketEmptyEvent event) { if (!isInExtraWorld()) return; + if (event.getBlock().getWorld() != getExtraWorld()) return; Regions.later(plugin, event.getBlock().getLocation(), () -> { event.getBlock().setType(Material.AIR); @@ -56,6 +57,8 @@ public void onPlayerBucketEmpty(@NotNull PlayerBucketEmptyEvent event) { public void onEntityDamage(@NotNull EntityDamageEvent event) { if (!(event.getEntity() instanceof Player player)) return; if (!isInExtraWorld()) return; + // The teleport into the extra world completes later, damage before the arrival is not the landing + if (player.getWorld() != getExtraWorld()) return; if (AbstractChallenge.getFirstInstance(OneTeamLifeSetting.class).isEnabled()) { teleportBack(); diff --git a/plugin/src/test/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallengeTest.java b/plugin/src/test/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallengeTest.java new file mode 100644 index 000000000..956f0e160 --- /dev/null +++ b/plugin/src/test/java/net/cyperia/challenges/plugin/challenges/custom/TriggerActionChallengeTest.java @@ -0,0 +1,78 @@ +package net.cyperia.challenges.plugin.challenges.custom; + +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; +import io.papermc.paper.threadedregions.scheduler.ScheduledTask; +import net.cyperia.challenges.plugin.Challenges; +import net.cyperia.challenges.plugin.challenges.custom.settings.ChallengeExecutionData; +import net.cyperia.challenges.plugin.challenges.custom.settings.action.ChallengeAction; +import org.bukkit.Bukkit; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.MockedStatic; + +import java.util.Map; +import java.util.function.Consumer; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +class TriggerActionChallengeTest { + + private final Challenges plugin = mock(Challenges.class); + private final GlobalRegionScheduler global = mock(GlobalRegionScheduler.class); + private final ChallengeAction action = mock(ChallengeAction.class); + private final ChallengeExecutionData data = mock(ChallengeExecutionData.class); + private final Map subActions = Map.of(); + private final TriggerActionChallenge challenge = mock(TriggerActionChallenge.class, CALLS_REAL_METHODS); + private MockedStatic bukkit; + private MockedStatic challenges; + + @BeforeEach + void mockServer() { + bukkit = mockStatic(Bukkit.class); + bukkit.when(Bukkit::getGlobalRegionScheduler).thenReturn(global); + challenges = mockStatic(Challenges.class); + challenges.when(Challenges::getInstance).thenReturn(plugin); + when(challenge.getAction()).thenReturn(action); + when(challenge.getSubActions()).thenReturn(subActions); + } + + @AfterEach + void closeServer() { + challenges.close(); + bukkit.close(); + } + + @Test + void executeAction_runsInlineOnATickThread() { + bukkit.when(Bukkit::isPrimaryThread).thenReturn(true); + + challenge.executeAction(data); + + verify(action).execute(data, subActions); + verify(global, never()).run(any(), any()); + } + + @Test + @SuppressWarnings("unchecked") + void executeAction_fromAnAsyncTrigger_runsOnTheNextTick() { + bukkit.when(Bukkit::isPrimaryThread).thenReturn(false); + ArgumentCaptor> task = ArgumentCaptor.forClass(Consumer.class); + + challenge.executeAction(data); + + verify(action, never()).execute(any(), any()); + verify(global).run(eq(plugin), task.capture()); + task.getValue().accept(mock(ScheduledTask.class)); + verify(action).execute(data, subActions); + } + +}