feat(quests): allow nearby command creation
This commit is contained in:
@@ -69,6 +69,24 @@ final class BoardRegistryTest {
|
||||
assertEquals(0, repository.saveCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
void proximityUsesSameWorldAndAcceptsExactFiveBlockBoundary() throws Exception {
|
||||
RecordingRepository repository = new RecordingRepository(new BoardState(Set.of(BOARD)));
|
||||
BoardRegistry registry = new BoardRegistry(repository);
|
||||
|
||||
assertTrue(registry.isWithin(
|
||||
BOARD.id().worldId(), BOARD.id().x() + 3.0, BOARD.id().y() + 4.0,
|
||||
BOARD.id().z(), 5.0
|
||||
));
|
||||
assertFalse(registry.isWithin(
|
||||
BOARD.id().worldId(), BOARD.id().x() + 3.01, BOARD.id().y() + 4.0,
|
||||
BOARD.id().z(), 5.0
|
||||
));
|
||||
assertFalse(registry.isWithin(
|
||||
UUID.randomUUID(), BOARD.id().x(), BOARD.id().y(), BOARD.id().z(), 5.0
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void failedPersistenceDoesNotPublishBoard() throws Exception {
|
||||
BoardRepository repository = new BoardRepository() {
|
||||
|
||||
@@ -41,6 +41,10 @@ final class PhysicalBoardCreatorTest {
|
||||
assertTrue(repository.state.boards().stream().allMatch(
|
||||
board -> board.worldName().equals("survival")
|
||||
));
|
||||
assertTrue(PhysicalBoardPlan.create(ANCHOR, BoardFacing.NORTH)
|
||||
.interactionLocations().stream().allMatch(location -> registry.isWithin(
|
||||
location.worldId(), location.x(), location.y(), location.z(), 5.0
|
||||
)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -44,6 +46,54 @@ final class PluginCommandWiringTest {
|
||||
assertTrue(worldLookups.get() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void playerCommandUsesBoardRegistryForNearbyCreation() throws Exception {
|
||||
UUID worldId = UUID.randomUUID();
|
||||
BoardId boardId = new BoardId(worldId, 10, 64, 20);
|
||||
BoardRegistry boards = new BoardRegistry(new BoardRepository() {
|
||||
@Override public BoardState load() {
|
||||
return new BoardState(Set.of(new RegisteredBoard(boardId, "survival")));
|
||||
}
|
||||
@Override public void save(BoardState state) { }
|
||||
});
|
||||
PlayerCommandSettings settings = new PlayerCommandSettings(
|
||||
new PlayerCommandSettingsRepository() {
|
||||
@Override public boolean loadEnabled() { return false; }
|
||||
@Override public void saveEnabled(boolean enabled) { }
|
||||
}
|
||||
);
|
||||
QuestCreationGateway creator = mock(QuestCreationGateway.class);
|
||||
Quest created = mock(Quest.class);
|
||||
when(created.id()).thenReturn(UUID.randomUUID());
|
||||
when(creator.create(
|
||||
org.mockito.ArgumentMatchers.any(),
|
||||
org.mockito.ArgumentMatchers.anyString(),
|
||||
org.mockito.ArgumentMatchers.anyInt(),
|
||||
org.mockito.ArgumentMatchers.any()
|
||||
)).thenReturn(created);
|
||||
SpigotQuestBoardPlugin.CommandHandlers handlers =
|
||||
SpigotQuestBoardPlugin.commandHandlers(
|
||||
boards, settings, creator, mock(QuestBrowser.class), null, null, null,
|
||||
Clock.systemUTC()
|
||||
);
|
||||
World world = mock(World.class);
|
||||
when(world.getUID()).thenReturn(worldId);
|
||||
Player player = mock(Player.class);
|
||||
when(player.getWorld()).thenReturn(world);
|
||||
when(player.getLocation()).thenReturn(new Location(world, 13, 68, 20));
|
||||
|
||||
assertTrue(handlers.quests().onCommand(
|
||||
player, mock(Command.class), "quests", new String[] {"create", "stone", "1"}
|
||||
));
|
||||
|
||||
verify(creator).create(
|
||||
org.mockito.ArgumentMatchers.eq(player),
|
||||
org.mockito.ArgumentMatchers.eq("stone"),
|
||||
org.mockito.ArgumentMatchers.eq(1),
|
||||
org.mockito.ArgumentMatchers.any()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void adminAndPlayerCommandsShareThePersistedSetting() throws Exception {
|
||||
PlayerCommandSettings settings = new PlayerCommandSettings(
|
||||
|
||||
@@ -14,15 +14,19 @@ import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class QuestCommandTest {
|
||||
private static final Instant NOW = Instant.parse("2026-09-05T03:00:00Z");
|
||||
private static final UUID WORLD_ID =
|
||||
UUID.fromString("00000000-0000-0000-0000-000000000099");
|
||||
|
||||
@Test
|
||||
void disabledSettingGatesEveryPlayerCommandFormAndAutocomplete() throws Exception {
|
||||
void disabledSettingGatesNonCreationCommandForms() throws Exception {
|
||||
QuestCreationGateway creator = mock(QuestCreationGateway.class);
|
||||
QuestBrowser browser = mock(QuestBrowser.class);
|
||||
QuestCompletionGateway completer = mock(QuestCompletionGateway.class);
|
||||
@@ -43,7 +47,6 @@ final class QuestCommandTest {
|
||||
List<String[]> forms = List.of(
|
||||
new String[] {},
|
||||
new String[] {"list"},
|
||||
new String[] {"create", "stone", "1"},
|
||||
new String[] {"complete", "quest-id"},
|
||||
new String[] {"cancel", "quest-id"},
|
||||
new String[] {"claim"}
|
||||
@@ -62,6 +65,97 @@ final class QuestCommandTest {
|
||||
verifyNoInteractions(creator, browser, completer, canceller, claimant);
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledSettingAllowsNearbyCreationAndOnlyCreationAutocomplete() throws Exception {
|
||||
RecordingCreator creator = new RecordingCreator();
|
||||
PlayerCommandSettings settings = settings(false);
|
||||
BoardProximity proximity = (worldId, x, y, z, maximumDistance) -> {
|
||||
assertEquals(WORLD_ID, worldId);
|
||||
assertEquals(4.0, x);
|
||||
assertEquals(3.0, y);
|
||||
assertEquals(0.0, z);
|
||||
assertEquals(5.0, maximumDistance);
|
||||
return true;
|
||||
};
|
||||
QuestCommand executor = new QuestCommand(
|
||||
creator, now -> List.of(), null, null, null,
|
||||
Clock.fixed(NOW, ZoneOffset.UTC), settings, proximity
|
||||
);
|
||||
Player player = playerAt(4.0, 3.0, 0.0);
|
||||
Command command = mock(Command.class);
|
||||
|
||||
assertTrue(executor.onCommand(
|
||||
player, command, "quests", new String[] {"create", "stone", "1"}
|
||||
));
|
||||
|
||||
assertEquals(1, creator.calls);
|
||||
assertEquals(List.of("create"), executor.onTabComplete(
|
||||
player, command, "quests", new String[] {""}
|
||||
));
|
||||
assertTrue(executor.onTabComplete(
|
||||
player, command, "quests", new String[] {"li"}
|
||||
).isEmpty());
|
||||
assertEquals(List.of("STONE", "STONE_BRICKS"), executor.onTabComplete(
|
||||
player, command, "quests", new String[] {"create", "sto"}
|
||||
));
|
||||
assertEquals(List.of("1", "16", "32", "64"), executor.onTabComplete(
|
||||
player, command, "quests", new String[] {"create", "stone", ""}
|
||||
));
|
||||
assertTrue(executor.onTabComplete(
|
||||
player, command, "quests", new String[] {"complete", ""}
|
||||
).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledSettingRejectsAwayCreationBeforeCreatorOrEscrowGateway() throws Exception {
|
||||
QuestCreationGateway creator = mock(QuestCreationGateway.class);
|
||||
QuestCommand executor = new QuestCommand(
|
||||
creator, mock(QuestBrowser.class), null, null, null,
|
||||
Clock.fixed(NOW, ZoneOffset.UTC), settings(false),
|
||||
(worldId, x, y, z, maximumDistance) -> false
|
||||
);
|
||||
Player player = playerAt(5.01, 0.0, 0.0);
|
||||
Command command = mock(Command.class);
|
||||
|
||||
assertTrue(executor.onCommand(
|
||||
player, command, "quests", new String[] {"create", "stone", "1"}
|
||||
));
|
||||
|
||||
verify(player).sendMessage("Move closer to a quest board to create a quest by command.");
|
||||
verifyNoInteractions(creator);
|
||||
assertTrue(executor.onTabComplete(
|
||||
player, command, "quests", new String[] {""}
|
||||
).isEmpty());
|
||||
assertTrue(executor.onTabComplete(
|
||||
player, command, "quests", new String[] {"create", "sto"}
|
||||
).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledSettingPreservesAllCommandsWithoutConsultingProximity() throws Exception {
|
||||
RecordingCreator creator = new RecordingCreator();
|
||||
QuestBrowser browser = now -> List.of(creator.quest(1));
|
||||
QuestCommand executor = new QuestCommand(
|
||||
creator, browser, null, null, null, Clock.fixed(NOW, ZoneOffset.UTC),
|
||||
settings(true),
|
||||
(worldId, x, y, z, maximumDistance) -> {
|
||||
throw new AssertionError("Enabled commands must bypass board proximity");
|
||||
}
|
||||
);
|
||||
Player player = mock(Player.class);
|
||||
Command command = mock(Command.class);
|
||||
|
||||
assertTrue(executor.onCommand(
|
||||
player, command, "quests", new String[] {"create", "stone", "1"}
|
||||
));
|
||||
assertTrue(executor.onCommand(player, command, "quests", new String[] {"list"}));
|
||||
assertEquals(List.of("create"), executor.onTabComplete(
|
||||
player, command, "quests", new String[] {"cr"}
|
||||
));
|
||||
|
||||
assertEquals(1, creator.calls);
|
||||
}
|
||||
|
||||
@Test
|
||||
void routesValidatedCreateArgumentsWithCurrentUtcTime() {
|
||||
RecordingCreator creator = new RecordingCreator();
|
||||
@@ -238,6 +332,23 @@ final class QuestCommandTest {
|
||||
).isEmpty());
|
||||
}
|
||||
|
||||
private static PlayerCommandSettings settings(boolean enabled) throws Exception {
|
||||
return new PlayerCommandSettings(new PlayerCommandSettingsRepository() {
|
||||
@Override public boolean loadEnabled() { return enabled; }
|
||||
@Override public void saveEnabled(boolean newValue) { }
|
||||
});
|
||||
}
|
||||
|
||||
private static Player playerAt(double x, double y, double z) {
|
||||
World world = mock(World.class);
|
||||
when(world.getUID()).thenReturn(WORLD_ID);
|
||||
Location location = new Location(world, x, y, z);
|
||||
Player player = mock(Player.class);
|
||||
when(player.getWorld()).thenReturn(world);
|
||||
when(player.getLocation()).thenReturn(location);
|
||||
return player;
|
||||
}
|
||||
|
||||
private static QuestCommand command(RecordingCreator creator) {
|
||||
return command(creator, now -> List.of());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user