Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 0 additions & 224 deletions catalog/export/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ void textsKeepNoMarkupOrArguments() {
}

@Test
void leavesOutUnregisteredChallenges() {
void leavesOutUnregisteredAndHiddenChallenges() {
ChallengeCatalog catalog = ChallengeCatalog.load();
JsonObject export = JsonParser.parseString(CatalogExport.render(catalog)).getAsJsonObject();
Set<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String[]> subActions = Map.of();
private final TriggerActionChallenge challenge = mock(TriggerActionChallenge.class, CALLS_REAL_METHODS);
private MockedStatic<Bukkit> bukkit;
private MockedStatic<Challenges> 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<Consumer<ScheduledTask>> 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);
}

}
Loading