|
|
|
@@ -12,11 +12,14 @@ import static org.mockito.Mockito.when;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.Server;
|
|
|
|
|
import org.bukkit.World;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.event.raid.RaidFinishEvent;
|
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
@@ -47,6 +50,7 @@ final class BaseFlightControllerTest {
|
|
|
|
|
PlayerInventory inventory = mock(PlayerInventory.class);
|
|
|
|
|
|
|
|
|
|
doReturn(List.of(player)).when(server).getOnlinePlayers();
|
|
|
|
|
when(server.getPlayer(playerId)).thenReturn(player);
|
|
|
|
|
when(player.getUniqueId()).thenReturn(playerId);
|
|
|
|
|
when(player.getName()).thenReturn("Alex");
|
|
|
|
|
when(player.getGameMode()).thenReturn(org.bukkit.GameMode.SURVIVAL);
|
|
|
|
@@ -62,6 +66,219 @@ final class BaseFlightControllerTest {
|
|
|
|
|
when(player.getAllowFlight()).thenReturn(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void ownerWinningRaidInOwnPocketBaseUnlocksFlight() throws Exception {
|
|
|
|
|
UUID pocketWorldId = UUID.randomUUID();
|
|
|
|
|
World pocketWorld = mock(World.class);
|
|
|
|
|
Player winner = mock(Player.class);
|
|
|
|
|
RaidFinishEvent event = mock(RaidFinishEvent.class);
|
|
|
|
|
PocketBaseManager pocketBases = mock(PocketBaseManager.class);
|
|
|
|
|
PocketBaseState locked = new PocketBaseState(playerId, 1, Optional.empty());
|
|
|
|
|
PocketBaseState unlocked = locked.withFlightUnlocked();
|
|
|
|
|
BaseFlightController pocketController = new BaseFlightController(
|
|
|
|
|
server,
|
|
|
|
|
stateManager,
|
|
|
|
|
new SecondaryProgressionService(PluginSettings.from(Map.of())),
|
|
|
|
|
new BaseBoundsService(PluginSettings.from(Map.of())),
|
|
|
|
|
new PluginSettingsProvider(PluginSettings.from(Map.of())),
|
|
|
|
|
pocketBases,
|
|
|
|
|
Logger.getAnonymousLogger()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
when(event.getWorld()).thenReturn(pocketWorld);
|
|
|
|
|
when(event.getWinners()).thenReturn(List.of(winner));
|
|
|
|
|
when(pocketWorld.getUID()).thenReturn(pocketWorldId);
|
|
|
|
|
when(winner.getUniqueId()).thenReturn(playerId);
|
|
|
|
|
when(pocketBases.ownerForPocketWorld(pocketWorldId)).thenReturn(Optional.of(playerId));
|
|
|
|
|
when(pocketBases.state(playerId)).thenReturn(locked);
|
|
|
|
|
when(pocketBases.unlockFlight(playerId)).thenReturn(unlocked);
|
|
|
|
|
|
|
|
|
|
pocketController.onRaidFinish(event);
|
|
|
|
|
|
|
|
|
|
verify(pocketBases).unlockFlight(playerId);
|
|
|
|
|
verify(winner).sendTitle(anyString(), anyString(), anyInt(), anyInt(), anyInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void raidDoesNotUnlockFlightWhenPocketOwnerIsNotAWinner() throws Exception {
|
|
|
|
|
UUID pocketWorldId = UUID.randomUUID();
|
|
|
|
|
UUID ownerId = UUID.randomUUID();
|
|
|
|
|
World pocketWorld = mock(World.class);
|
|
|
|
|
Player visitor = mock(Player.class);
|
|
|
|
|
RaidFinishEvent event = mock(RaidFinishEvent.class);
|
|
|
|
|
PocketBaseManager pocketBases = mock(PocketBaseManager.class);
|
|
|
|
|
BaseFlightController pocketController = new BaseFlightController(
|
|
|
|
|
server,
|
|
|
|
|
stateManager,
|
|
|
|
|
new SecondaryProgressionService(PluginSettings.from(Map.of())),
|
|
|
|
|
new BaseBoundsService(PluginSettings.from(Map.of())),
|
|
|
|
|
new PluginSettingsProvider(PluginSettings.from(Map.of())),
|
|
|
|
|
pocketBases,
|
|
|
|
|
Logger.getAnonymousLogger()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
when(event.getWorld()).thenReturn(pocketWorld);
|
|
|
|
|
when(event.getWinners()).thenReturn(List.of(visitor));
|
|
|
|
|
when(pocketWorld.getUID()).thenReturn(pocketWorldId);
|
|
|
|
|
when(visitor.getUniqueId()).thenReturn(UUID.randomUUID());
|
|
|
|
|
when(pocketBases.ownerForPocketWorld(pocketWorldId)).thenReturn(Optional.of(ownerId));
|
|
|
|
|
|
|
|
|
|
pocketController.onRaidFinish(event);
|
|
|
|
|
|
|
|
|
|
verify(pocketBases, never()).unlockFlight(ownerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void unlockedOwnerReceivesFlightInsidePocketBaseBuffer() {
|
|
|
|
|
UUID pocketWorldId = UUID.randomUUID();
|
|
|
|
|
World pocketWorld = mock(World.class);
|
|
|
|
|
Location location = mock(Location.class);
|
|
|
|
|
PocketBaseManager pocketBases = mock(PocketBaseManager.class);
|
|
|
|
|
PocketBaseState pocket = new PocketBaseState(playerId, 1, Optional.empty())
|
|
|
|
|
.withFlightUnlocked();
|
|
|
|
|
PlayerState noNormalFlight = PlayerState.newPlayer(playerId, "Alex");
|
|
|
|
|
BaseFlightController pocketController = new BaseFlightController(
|
|
|
|
|
server,
|
|
|
|
|
stateManager,
|
|
|
|
|
new SecondaryProgressionService(PluginSettings.from(Map.of())),
|
|
|
|
|
new BaseBoundsService(PluginSettings.from(Map.of())),
|
|
|
|
|
new PluginSettingsProvider(PluginSettings.from(Map.of())),
|
|
|
|
|
pocketBases,
|
|
|
|
|
Logger.getAnonymousLogger()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
when(stateManager.player(playerId, "Alex")).thenReturn(noNormalFlight);
|
|
|
|
|
when(player.getWorld()).thenReturn(pocketWorld);
|
|
|
|
|
when(player.getLocation()).thenReturn(location);
|
|
|
|
|
when(player.getAllowFlight()).thenReturn(false);
|
|
|
|
|
when(pocketWorld.getUID()).thenReturn(pocketWorldId);
|
|
|
|
|
when(location.getX()).thenReturn(40.5);
|
|
|
|
|
when(location.getZ()).thenReturn(0.5);
|
|
|
|
|
when(location.getBlockX()).thenReturn(40);
|
|
|
|
|
when(location.getBlockZ()).thenReturn(0);
|
|
|
|
|
when(pocketBases.ownerForPocketWorld(pocketWorldId)).thenReturn(Optional.of(playerId));
|
|
|
|
|
when(pocketBases.state(playerId)).thenReturn(pocket);
|
|
|
|
|
when(pocketBases.policy()).thenReturn(
|
|
|
|
|
new PocketBasePolicy(PluginSettings.from(Map.of()))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
pocketController.run();
|
|
|
|
|
|
|
|
|
|
verify(player).setAllowFlight(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void flyingInPocketBaseBufferShowsLeavingWarning() {
|
|
|
|
|
UUID pocketWorldId = UUID.randomUUID();
|
|
|
|
|
World pocketWorld = mock(World.class);
|
|
|
|
|
Location location = mock(Location.class);
|
|
|
|
|
PocketBaseManager pocketBases = mock(PocketBaseManager.class);
|
|
|
|
|
PocketBaseState pocket = new PocketBaseState(playerId, 1, Optional.empty())
|
|
|
|
|
.withFlightUnlocked();
|
|
|
|
|
BaseFlightController pocketController = new BaseFlightController(
|
|
|
|
|
server,
|
|
|
|
|
stateManager,
|
|
|
|
|
new SecondaryProgressionService(PluginSettings.from(Map.of())),
|
|
|
|
|
new BaseBoundsService(PluginSettings.from(Map.of())),
|
|
|
|
|
new PluginSettingsProvider(PluginSettings.from(Map.of())),
|
|
|
|
|
pocketBases,
|
|
|
|
|
Logger.getAnonymousLogger()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
when(stateManager.player(playerId, "Alex")).thenReturn(
|
|
|
|
|
PlayerState.newPlayer(playerId, "Alex")
|
|
|
|
|
);
|
|
|
|
|
when(player.getWorld()).thenReturn(pocketWorld);
|
|
|
|
|
when(player.getLocation()).thenReturn(location);
|
|
|
|
|
when(player.isFlying()).thenReturn(true);
|
|
|
|
|
when(pocketWorld.getUID()).thenReturn(pocketWorldId);
|
|
|
|
|
when(location.getBlockX()).thenReturn(40);
|
|
|
|
|
when(location.getBlockZ()).thenReturn(0);
|
|
|
|
|
when(pocketBases.ownerForPocketWorld(pocketWorldId)).thenReturn(Optional.of(playerId));
|
|
|
|
|
when(pocketBases.state(playerId)).thenReturn(pocket);
|
|
|
|
|
when(pocketBases.policy()).thenReturn(
|
|
|
|
|
new PocketBasePolicy(PluginSettings.from(Map.of()))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
pocketController.run();
|
|
|
|
|
|
|
|
|
|
verify(player).sendTitle(anyString(), anyString(), anyInt(), anyInt(), anyInt());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void pocketBaseFlightEndsBeyondSixteenBlockBuffer() {
|
|
|
|
|
UUID pocketWorldId = UUID.randomUUID();
|
|
|
|
|
World pocketWorld = mock(World.class);
|
|
|
|
|
Location location = mock(Location.class);
|
|
|
|
|
PocketBaseManager pocketBases = mock(PocketBaseManager.class);
|
|
|
|
|
PocketBaseState pocket = new PocketBaseState(playerId, 1, Optional.empty())
|
|
|
|
|
.withFlightUnlocked();
|
|
|
|
|
BaseFlightController pocketController = new BaseFlightController(
|
|
|
|
|
server,
|
|
|
|
|
stateManager,
|
|
|
|
|
new SecondaryProgressionService(PluginSettings.from(Map.of())),
|
|
|
|
|
new BaseBoundsService(PluginSettings.from(Map.of())),
|
|
|
|
|
new PluginSettingsProvider(PluginSettings.from(Map.of())),
|
|
|
|
|
pocketBases,
|
|
|
|
|
Logger.getAnonymousLogger()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
when(stateManager.player(playerId, "Alex")).thenReturn(
|
|
|
|
|
PlayerState.newPlayer(playerId, "Alex")
|
|
|
|
|
);
|
|
|
|
|
when(player.getWorld()).thenReturn(pocketWorld);
|
|
|
|
|
when(player.getLocation()).thenReturn(location);
|
|
|
|
|
when(player.getAllowFlight()).thenReturn(false);
|
|
|
|
|
when(pocketWorld.getUID()).thenReturn(pocketWorldId);
|
|
|
|
|
when(location.getBlockX()).thenReturn(40, 48);
|
|
|
|
|
when(location.getBlockZ()).thenReturn(0);
|
|
|
|
|
when(pocketBases.ownerForPocketWorld(pocketWorldId)).thenReturn(Optional.of(playerId));
|
|
|
|
|
when(pocketBases.state(playerId)).thenReturn(pocket);
|
|
|
|
|
when(pocketBases.policy()).thenReturn(
|
|
|
|
|
new PocketBasePolicy(PluginSettings.from(Map.of()))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
pocketController.run();
|
|
|
|
|
pocketController.run();
|
|
|
|
|
|
|
|
|
|
verify(player).setFlying(false);
|
|
|
|
|
verify(player).setAllowFlight(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void visitorDoesNotReceiveUnlockedOwnersPocketBaseFlight() {
|
|
|
|
|
UUID ownerId = UUID.randomUUID();
|
|
|
|
|
UUID pocketWorldId = UUID.randomUUID();
|
|
|
|
|
World pocketWorld = mock(World.class);
|
|
|
|
|
Location location = mock(Location.class);
|
|
|
|
|
PocketBaseManager pocketBases = mock(PocketBaseManager.class);
|
|
|
|
|
PocketBaseState pocket = new PocketBaseState(ownerId, 1, Optional.empty())
|
|
|
|
|
.withFlightUnlocked();
|
|
|
|
|
BaseFlightController pocketController = new BaseFlightController(
|
|
|
|
|
server,
|
|
|
|
|
stateManager,
|
|
|
|
|
new SecondaryProgressionService(PluginSettings.from(Map.of())),
|
|
|
|
|
new BaseBoundsService(PluginSettings.from(Map.of())),
|
|
|
|
|
new PluginSettingsProvider(PluginSettings.from(Map.of())),
|
|
|
|
|
pocketBases,
|
|
|
|
|
Logger.getAnonymousLogger()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
when(stateManager.player(playerId, "Alex")).thenReturn(
|
|
|
|
|
PlayerState.newPlayer(playerId, "Alex")
|
|
|
|
|
);
|
|
|
|
|
when(player.getWorld()).thenReturn(pocketWorld);
|
|
|
|
|
when(player.getLocation()).thenReturn(location);
|
|
|
|
|
when(player.getAllowFlight()).thenReturn(false);
|
|
|
|
|
when(pocketWorld.getUID()).thenReturn(pocketWorldId);
|
|
|
|
|
when(pocketBases.ownerForPocketWorld(pocketWorldId)).thenReturn(Optional.of(ownerId));
|
|
|
|
|
when(pocketBases.state(ownerId)).thenReturn(pocket);
|
|
|
|
|
|
|
|
|
|
pocketController.run();
|
|
|
|
|
|
|
|
|
|
verify(player, never()).setAllowFlight(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void walkingInWarningBufferDoesNotShowLeavingBaseWarning() {
|
|
|
|
|
when(player.isFlying()).thenReturn(false);
|
|
|
|
|