diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 300325b..f122ca8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,11 +14,11 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 17 + - name: Set up JDK 25 uses: actions/setup-java@v3 with: distribution: 'adopt' - java-version: 21 + java-version: 25 - name: Cache SonarCloud packages uses: actions/cache@v3 with: diff --git a/.github/workflows/modrinth-publish.yml b/.github/workflows/modrinth-publish.yml index ca8c75f..8b89fe9 100644 --- a/.github/workflows/modrinth-publish.yml +++ b/.github/workflows/modrinth-publish.yml @@ -22,11 +22,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # 2. Set up Java 21 (required by CaveBlock's build) - - name: Set up Java 21 + # 2. Set up Java 25 (required by CaveBlock's build) + - name: Set up Java 25 uses: actions/setup-java@v4 with: - java-version: '21' + java-version: '25' distribution: 'temurin' # 3. Cache Maven dependencies to speed up builds @@ -91,6 +91,7 @@ jobs: 26.1.1 26.1.2 26.2 + 26.3 # Path to the built JAR — Maven produces CaveBlock-.jar in target/ # Note: glob patterns are not supported; use the release tag directly. diff --git a/CLAUDE.md b/CLAUDE.md index a813d0f..4166882 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -14,7 +14,7 @@ mvn test # Run tests (surefire) mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BentoBoxWorld_CaveBlock # CI build with SonarCloud ``` -Java 21 is required. The output JAR goes to `target/`. +Java 25 is required (BentoBox 3.23+ and Paper 26.x are Java 25 artifacts). The output JAR goes to `target/`. ## Architecture @@ -26,7 +26,7 @@ Java 21 is required. The output JAR goes to `target/`. - `generators/ChunkGeneratorWorld.java` — Core chunk generator. Fills the world with the dimension's base blocks (stone/netherrack/end stone) and delegates additional material generation to the populator pipeline. `NoiseCaveGenerator` and `Ore` support noise-based cave carving and ore placement. - `generators/populators/` — `NewMaterialPopulator` (vanilla-like material generation), `CaveDecorationPopulator` (cave decoration), and the biome providers `FlatBiomeProvider` / `NetherBiomeProvider` (biome distribution per dimension). - `listeners/CustomHeightLimitations.java` — Prevents players from going above the configured world depth. Respects `SKY_WALKER_FLAG` and creative/op bypass. -- `listeners/StructureGenerationListener.java` — Suppresses vanilla structures the admin disabled in `world.structures` from the CaveBlock overworld: cancels their spawn (`AsyncStructureSpawnEvent`) and removes them from structure searches (`StructuresLocateEvent`) so `/locate`, explorer maps, etc. don't scan to the radius cap and freeze the server. +- Structure suppression (`world.structures`) is handled by BentoBox core's `StructureListener` (BentoBox 3.19.1+): `Settings#getStructureSettings()` returns the `world.structures` map, and core cancels disabled structures' spawns and strips them from `StructuresLocateEvent` searches in all three CaveBlock worlds. CaveBlock no longer has its own listener. **BentoBox framework patterns to follow:** - Addons use `GameModeAddon` lifecycle, not Bukkit's `JavaPlugin` directly @@ -37,8 +37,9 @@ Java 21 is required. The output JAR goes to `target/`. ## Key Dependencies (provided scope — server supplies at runtime) -- `paper-api` 1.21.11 — Paper API -- `bentobox` 3.14.1-SNAPSHOT — BentoBox framework +- `paper-api` 26.3 (`26.3.build.231-stable`) — Paper API +- `bentobox` 3.23.7 — BentoBox framework +- `mockbukkit-v26.3` 4.119.0 — server mock used in tests (its MC line must match the paper-api version or registry validation fails) ## Branches diff --git a/pom.xml b/pom.xml index 1647ca8..5378a2c 100644 --- a/pom.xml +++ b/pom.xml @@ -39,18 +39,18 @@ UTF-8 UTF-8 - 21 + 25 5.10.2 - 5.11.0 - 4.110.0 + 5.20.0 + 4.119.0 - 1.21.11-R0.1-SNAPSHOT - 3.14.1-SNAPSHOT + 26.3.build.231-stable + 3.23.7 ${build.version}-SNAPSHOT - 1.23.3 + 1.24.0 -LOCAL bentobox-world https://sonarcloud.io @@ -132,7 +132,7 @@ org.mockbukkit.mockbukkit - mockbukkit-v1.21 + mockbukkit-v26.3 ${mock-bukkit.version} test @@ -213,6 +213,7 @@ 3.13.0 ${java.version} + true diff --git a/src/main/java/world/bentobox/caveblock/CaveBlock.java b/src/main/java/world/bentobox/caveblock/CaveBlock.java index b5ea33b..42a6b23 100644 --- a/src/main/java/world/bentobox/caveblock/CaveBlock.java +++ b/src/main/java/world/bentobox/caveblock/CaveBlock.java @@ -20,7 +20,6 @@ import world.bentobox.caveblock.commands.IslandAboutCommand; import world.bentobox.caveblock.generators.ChunkGeneratorWorld; import world.bentobox.caveblock.listeners.CustomHeightLimitations; -import world.bentobox.caveblock.listeners.StructureGenerationListener; public class CaveBlock extends GameModeAddon @@ -80,8 +79,6 @@ public void onEnable() // Register listeners this.registerListener(new CustomHeightLimitations(this)); - // StructureGenerationListener is registered earlier, in createWorlds(), so it is - // active before the first chunks (including the spawn area) are generated. } @@ -149,11 +146,9 @@ public void allLoaded() { @Override public void createWorlds() { - // Register the structure listener before any world is created. createWorlds() runs - // before onEnable(), and generating a world also generates its spawn-area chunks, so a - // listener registered in onEnable() would miss those first structures (issue #116). - this.registerListener(new StructureGenerationListener(this)); - + // Structure suppression (world.structures) is handled by BentoBox core's + // StructureListener via Settings#getStructureSettings(). Core registers it before + // createWorlds(), so spawn-area structures are covered too (issue #116). String worldName = this.settings.getWorldName().toLowerCase(); if (this.getServer().getWorld(worldName) == null) diff --git a/src/main/java/world/bentobox/caveblock/Settings.java b/src/main/java/world/bentobox/caveblock/Settings.java index ca7f7a2..c9d23cd 100644 --- a/src/main/java/world/bentobox/caveblock/Settings.java +++ b/src/main/java/world/bentobox/caveblock/Settings.java @@ -162,13 +162,15 @@ public class Settings implements WorldSettings @ConfigComment("") @ConfigComment("Vanilla structures that may generate in the overworld cave world.") - @ConfigComment("Set a structure to false to stop it generating; structures not listed here") - @ConfigComment("generate as normal. Use the vanilla structure key, for example:") + @ConfigComment("Set a structure to false to stop it generating, or true to force it on even if") + @ConfigComment("BentoBox's global world.disabled-structures list disables it. Structures not listed") + @ConfigComment("here follow that global list. Use the vanilla structure key, for example:") @ConfigComment(" ancient_city, trial_chambers, mineshaft, mineshaft_mesa, stronghold,") @ConfigComment(" mansion, monument, pillager_outpost, ruined_portal, trail_ruins,") @ConfigComment(" village_plains, desert_pyramid, jungle_pyramid, igloo, swamp_hut") @ConfigComment("Large structures like Ancient Cities and Trial Chambers can fill or unbalance") - @ConfigComment("a cave world, so they are disabled by default. Only affects the overworld.") + @ConfigComment("a cave world, so they are disabled by default. Disabled structures are also skipped") + @ConfigComment("by /locate, Eyes of Ender, explorer maps and dolphins. Handled by BentoBox core.") @ConfigEntry(path = "world.structures", since = "1.23.0") private Map generateStructures = defaultStructures(); @@ -321,6 +323,14 @@ public class Settings implements WorldSettings // --------------------------------------------- /* Cave */ + @ConfigComment("Disable the team system in CaveBlock worlds.") + @ConfigComment("When true, players cannot invite, accept team invites, kick, leave, promote, demote") + @ConfigComment("or change cave owner. Trust and coop still work and are the alternative to teams.") + @ConfigComment("After turning this on, run /cbadmin team disbandall once to remove existing team members.") + @ConfigComment("Requires BentoBox 3.16.0 or later.") + @ConfigEntry(path = "cave.teams-disabled", since = "1.24.0") + private boolean teamsDisabled = false; + @ConfigComment("Default max team size") @ConfigComment("Permission size cannot be less than the default below. ") @ConfigEntry(path = "cave.max-team-size") @@ -928,6 +938,15 @@ public List getFallingBannedCommands() } + /** + * @return true if the team subsystem is disabled in this game mode's worlds + */ + @Override + public boolean isTeamsDisabled() + { + return teamsDisabled; + } + /** * This method returns the maxTeamSize object. * @return the maxTeamSize object. @@ -1257,6 +1276,22 @@ public void setGenerateStructures(Map generateStructures) this.generateStructures = generateStructures; } + /** + * @return per-structure generation overrides for this game mode's worlds + */ + @Override + public Map getStructureSettings() + { + return generateStructures; + } + + /** + * @param structureSettings per-structure generation overrides to set + */ + public void setStructureSettings(Map structureSettings) + { + this.generateStructures = structureSettings; + } /** * Fraction of overworld vanilla cave air to re-solidify after generation to @@ -1806,6 +1841,14 @@ public void setFallingBannedCommands(List fallingBannedCommands) } + /** + * @param teamsDisabled whether to disable the team subsystem + */ + public void setTeamsDisabled(boolean teamsDisabled) + { + this.teamsDisabled = teamsDisabled; + } + /** * This method sets the maxTeamSize object value. * @param maxTeamSize the maxTeamSize object new value. diff --git a/src/main/java/world/bentobox/caveblock/listeners/StructureGenerationListener.java b/src/main/java/world/bentobox/caveblock/listeners/StructureGenerationListener.java deleted file mode 100644 index 650768b..0000000 --- a/src/main/java/world/bentobox/caveblock/listeners/StructureGenerationListener.java +++ /dev/null @@ -1,146 +0,0 @@ -package world.bentobox.caveblock.listeners; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.stream.Collectors; - -import org.bukkit.World; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.world.AsyncStructureSpawnEvent; -import org.bukkit.generator.structure.Structure; - -import io.papermc.paper.event.world.StructuresLocateEvent; -import world.bentobox.caveblock.CaveBlock; - -/** - * Prevents configured vanilla structures from generating in the CaveBlock - * overworld. - * - *

The overworld delegates to vanilla generation, which includes structures - * such as Ancient Cities, Trial Chambers and Strongholds. Some of these fill or - * unbalance a cave world (see issue #112). The {@link org.bukkit.generator.ChunkGenerator} - * flag can only turn all structures on or off, so this listener provides - * per-structure control by cancelling the spawn of any structure the admin has - * disabled in {@code world.structures}.

- * - *

{@link AsyncStructureSpawnEvent} fires off the main thread during chunk - * generation, so that handler only reads config and inspects the event. It - * queries the event's world for environment and ownership checks but performs - * no world or block mutation, which is what makes it safe to run async.

- * - *

Cancelling the spawn stops a structure being placed but leaves its - * placement rules intact, so structure searches ({@code /locate}, Eyes of - * Ender, treasure/explorer maps, villager map trades) keep proposing candidate - * positions that are then all cancelled, scanning to the radius cap and freezing - * the server (issue #116). {@link #onStructuresLocate} closes that hole by removing - * disabled structures from the search before it runs.

- * - * @author tastybento - */ -public class StructureGenerationListener implements Listener { - - private final CaveBlock addon; - - /** - * @param addon CaveBlock addon - */ - public StructureGenerationListener(CaveBlock addon) { - this.addon = addon; - } - - /** - * Cancels the spawn of a disabled structure in the CaveBlock overworld. - * - * @param event the structure spawn event - */ - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStructureSpawn(AsyncStructureSpawnEvent event) { - // Only the CaveBlock overworld uses vanilla structures; nether/end do not. - if (!isCaveOverworld(event.getWorld())) { - return; - } - String structureKey = event.getStructure().getKey().getKey(); - if (isDisabled(structureKey)) { - event.setCancelled(true); - } - } - - /** - * Prevents disabled structures from being located. {@link StructuresLocateEvent} - * fires before any structure search — the {@code /locate} command, Eyes of Ender, - * explorer/treasure maps, dolphins and villager map trades. On a cave world where the - * target structure is suppressed, that search never succeeds and scans out to the radius - * cap, freezing the main thread (issue #116). Removing the disabled structures from the - * search list — and cancelling outright when nothing remains — skips the scan entirely so - * the search returns "not found" instantly. - * - * @param event the structure locate event - */ - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onStructuresLocate(StructuresLocateEvent event) { - if (!isCaveOverworld(event.getWorld())) { - return; - } - List targets = event.getStructures(); - // Collect into a mutable list: StructuresLocateEvent#setStructures expects one - // that Paper (or a later listener) can still mutate. Stream#toList() is immutable. - List allowed = targets.stream() - .filter(structure -> !isDisabled(structure.getKey().getKey())) - .collect(Collectors.toCollection(ArrayList::new)); - if (allowed.size() == targets.size()) { - // Nothing disabled in this search — let it run normally. - return; - } - if (allowed.isEmpty()) { - // Every requested structure is disabled here: skip the expensive scan entirely. - event.setCancelled(true); - } else { - event.setStructures(allowed); - } - } - - /** - * @param world a world - * @return {@code true} if {@code world} is the CaveBlock overworld. - * - *

Matches on the configured world name rather than {@link CaveBlock#inWorld(World)} - * because structures in the spawn area are generated during {@code createWorlds()}, - * before the addon's island-world reference is assigned. At that point - * {@code inWorld()} would compare against a null world and fail, so the first - * structures would slip through (issue #116).

- */ - private boolean isCaveOverworld(World world) { - if (world.getEnvironment() != World.Environment.NORMAL) { - return false; - } - String configuredName = addon.getSettings().getWorldName(); - return configuredName != null && world.getName().equalsIgnoreCase(configuredName); - } - - /** - * @param structureKey the vanilla structure key path, e.g. {@code ancient_city} - * @return {@code true} if the config explicitly disables this structure - */ - private boolean isDisabled(String structureKey) { - Map structures = addon.getSettings().getGenerateStructures(); - if (structures == null || structures.isEmpty()) { - return false; - } - // Accept hyphen or underscore separators and any casing on both sides. - String normalizedKey = normalize(structureKey); - for (Map.Entry entry : structures.entrySet()) { - if (normalize(entry.getKey()).equals(normalizedKey) && Boolean.FALSE.equals(entry.getValue())) { - return true; - } - } - return false; - } - - private String normalize(String key) { - return key.toLowerCase(Locale.ROOT).replace('-', '_'); - } -} diff --git a/src/main/resources/addon.yml b/src/main/resources/addon.yml index e476bda..69883b8 100644 --- a/src/main/resources/addon.yml +++ b/src/main/resources/addon.yml @@ -1,7 +1,7 @@ name: CaveBlock main: world.bentobox.caveblock.CaveBlock version: ${version}${build.number} -api-version: 3.14 +api-version: 3.23.0 metrics: true repository: "BentoBoxWorld/CaveBlock" icon: "STONE_PICKAXE" diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b53a161..9857de5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -93,13 +93,15 @@ world: world-depth: 319 # # Vanilla structures that may generate in the overworld cave world. - # Set a structure to false to stop it generating; structures not listed here - # generate as normal. Use the vanilla structure key, for example: + # Set a structure to false to stop it generating, or true to force it on even if + # BentoBox's global world.disabled-structures list disables it. Structures not listed + # here follow that global list. Use the vanilla structure key, for example: # ancient_city, trial_chambers, mineshaft, mineshaft_mesa, stronghold, # mansion, monument, pillager_outpost, ruined_portal, trail_ruins, # village_plains, desert_pyramid, jungle_pyramid, igloo, swamp_hut # Large structures like Ancient Cities and Trial Chambers can fill or unbalance - # a cave world, so they are disabled by default. Only affects the overworld. + # a cave world, so they are disabled by default. Disabled structures are also skipped + # by /locate, Eyes of Ender, explorer maps and dolphins. Handled by BentoBox core. # Added since 1.23.0. structures: ancient_city: false @@ -243,8 +245,15 @@ world: - warp - spawn cave: + # Disable the team system in CaveBlock worlds. + # When true, players cannot invite, accept team invites, kick, leave, promote, demote + # or change cave owner. Trust and coop still work and are the alternative to teams. + # After turning this on, run /cbadmin team disbandall once to remove existing team members. + # Requires BentoBox 3.16.0 or later. + # Added since 1.24.0. + teams-disabled: false # Default max team size - # Permission size cannot be less than the default below. + # Permission size cannot be less than the default below. max-team-size: 4 # Default maximum number of coop rank members per cave # Players can have the caveblock.coop.maxsize. permission to be bigger but diff --git a/src/test/java/world/bentobox/caveblock/SettingsTest.java b/src/test/java/world/bentobox/caveblock/SettingsTest.java new file mode 100644 index 0000000..cf069fb --- /dev/null +++ b/src/test/java/world/bentobox/caveblock/SettingsTest.java @@ -0,0 +1,63 @@ +package world.bentobox.caveblock; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests for the WorldSettings hooks that BentoBox core reads from CaveBlock's {@link Settings}. + */ +class SettingsTest extends CommonTestSetup { + + private Settings s; + + @Override + @BeforeEach + public void setUp() throws Exception { + super.setUp(); + s = new Settings(); + } + + @Override + @AfterEach + public void tearDown() throws Exception { + super.tearDown(); + } + + @Test + void testTeamsDisabled() { + assertFalse(s.isTeamsDisabled()); + s.setTeamsDisabled(true); + assertTrue(s.isTeamsDisabled()); + } + + @Test + void testStructureSettingsDefaultsDisableLargeStructures() { + Map structures = s.getStructureSettings(); + assertEquals(Boolean.FALSE, structures.get("ancient_city")); + assertEquals(Boolean.FALSE, structures.get("trial_chambers")); + assertEquals(Boolean.FALSE, structures.get("mansion")); + assertEquals(Boolean.TRUE, structures.get("mineshaft")); + assertEquals(Boolean.TRUE, structures.get("stronghold")); + } + + @Test + void testStructureSettingsIsTheWorldStructuresConfig() { + Map map = new HashMap<>(); + map.put("monument", false); + s.setGenerateStructures(map); + // Core BentoBox reads getStructureSettings(); it must be the same world.structures map + assertSame(map, s.getStructureSettings()); + Map other = new HashMap<>(); + s.setStructureSettings(other); + assertSame(other, s.getGenerateStructures()); + } +} diff --git a/src/test/java/world/bentobox/caveblock/listeners/StructureGenerationListenerTest.java b/src/test/java/world/bentobox/caveblock/listeners/StructureGenerationListenerTest.java deleted file mode 100644 index 161ff20..0000000 --- a/src/test/java/world/bentobox/caveblock/listeners/StructureGenerationListenerTest.java +++ /dev/null @@ -1,170 +0,0 @@ -package world.bentobox.caveblock.listeners; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.bukkit.NamespacedKey; -import org.bukkit.World; -import org.bukkit.event.world.AsyncStructureSpawnEvent; -import org.bukkit.generator.structure.Structure; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockbukkit.mockbukkit.MockBukkit; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import io.papermc.paper.event.world.StructuresLocateEvent; -import world.bentobox.caveblock.CaveBlock; -import world.bentobox.caveblock.Settings; - -/** - * Tests for {@link StructureGenerationListener}. - */ -@ExtendWith(MockitoExtension.class) -class StructureGenerationListenerTest { - - @Mock - private CaveBlock addon; - @Mock - private Settings settings; - @Mock - private World world; - - private StructureGenerationListener listener; - - @BeforeEach - public void setUp() { - MockBukkit.mock(); - lenient().when(addon.getSettings()).thenReturn(settings); - lenient().when(settings.getGenerateStructures()) - .thenReturn(Map.of("ancient_city", false, "trial_chambers", false, "mineshaft", true)); - lenient().when(settings.getWorldName()).thenReturn("caveblock_world"); - lenient().when(world.getName()).thenReturn("caveblock_world"); - lenient().when(world.getEnvironment()).thenReturn(World.Environment.NORMAL); - listener = new StructureGenerationListener(addon); - } - - @AfterEach - public void tearDown() { - MockBukkit.unmock(); - } - - private AsyncStructureSpawnEvent event(String structureKey) { - Structure structure = mock(Structure.class); - lenient().when(structure.getKey()).thenReturn(NamespacedKey.minecraft(structureKey)); - AsyncStructureSpawnEvent e = mock(AsyncStructureSpawnEvent.class); - lenient().when(e.getWorld()).thenReturn(world); - lenient().when(e.getStructure()).thenReturn(structure); - return e; - } - - @Test - void testDisabledStructureIsCancelled() { - AsyncStructureSpawnEvent e = event("ancient_city"); - listener.onStructureSpawn(e); - verify(e).setCancelled(true); - } - - @Test - void testEnabledStructureIsNotCancelled() { - AsyncStructureSpawnEvent e = event("mineshaft"); - listener.onStructureSpawn(e); - verify(e, never()).setCancelled(true); - } - - @Test - void testUnlistedStructureGeneratesNormally() { - AsyncStructureSpawnEvent e = event("village_plains"); - listener.onStructureSpawn(e); - verify(e, never()).setCancelled(true); - } - - @Test - void testStructureOutsideCaveBlockWorldIsIgnored() { - when(world.getName()).thenReturn("some_other_world"); - AsyncStructureSpawnEvent e = event("ancient_city"); - listener.onStructureSpawn(e); - verify(e, never()).setCancelled(true); - } - - @Test - void testNetherEnvironmentIsIgnored() { - when(world.getEnvironment()).thenReturn(World.Environment.NETHER); - AsyncStructureSpawnEvent e = event("ancient_city"); - listener.onStructureSpawn(e); - verify(e, never()).setCancelled(true); - } - - @Test - void testConfigKeyWithHyphensAndCaseMatches() { - when(settings.getGenerateStructures()).thenReturn(Map.of("Ancient-City", false)); - AsyncStructureSpawnEvent e = event("ancient_city"); - listener.onStructureSpawn(e); - verify(e).setCancelled(true); - } - - private StructuresLocateEvent locateEvent(String... structureKeys) { - // Collect into a mutable list to mirror Paper's StructuresLocateEvent#getStructures(), - // which is documented as mutable; Stream#toList() would return an unmodifiable list. - List structures = Arrays.stream(structureKeys).map(key -> { - Structure structure = mock(Structure.class); - lenient().when(structure.getKey()).thenReturn(NamespacedKey.minecraft(key)); - return structure; - }).collect(Collectors.toCollection(ArrayList::new)); - StructuresLocateEvent e = mock(StructuresLocateEvent.class); - lenient().when(e.getWorld()).thenReturn(world); - lenient().when(e.getStructures()).thenReturn(structures); - return e; - } - - @Test - void testLocateAllDisabledIsCancelled() { - StructuresLocateEvent e = locateEvent("trial_chambers"); - listener.onStructuresLocate(e); - verify(e).setCancelled(true); - verify(e, never()).setStructures(anyList()); - } - - @Test - void testLocateMixedNarrowsToEnabledOnly() { - StructuresLocateEvent e = locateEvent("trial_chambers", "mineshaft"); - listener.onStructuresLocate(e); - verify(e, never()).setCancelled(true); - @SuppressWarnings("unchecked") - ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); - verify(e).setStructures(captor.capture()); - assertEquals(1, captor.getValue().size()); - assertEquals("mineshaft", captor.getValue().get(0).getKey().getKey()); - } - - @Test - void testLocateAllEnabledIsUntouched() { - StructuresLocateEvent e = locateEvent("mineshaft", "village_plains"); - listener.onStructuresLocate(e); - verify(e, never()).setCancelled(true); - verify(e, never()).setStructures(anyList()); - } - - @Test - void testLocateOutsideCaveBlockWorldIsIgnored() { - when(world.getName()).thenReturn("some_other_world"); - StructuresLocateEvent e = locateEvent("trial_chambers"); - listener.onStructuresLocate(e); - verify(e, never()).setCancelled(true); - verify(e, never()).setStructures(anyList()); - } -}