feat(heights): mount larger players without consent
This commit is contained in:
1 parent
df44bba9c6
commit
a949fd99c4
16 files changed
+585
-206
No files matched your search
@@ -28,7 +28,7 @@ class BukkitCarryTest {
|
||||
private final BukkitCarry carry = new BukkitCarry(id -> id.equals(small.id) ? small.player
|
||||
: id.equals(large.id) ? large.player : null,
|
||||
() -> new HeightSettings(0.4, 2, 0.1, 0.5, 1.5, 20), scheduled::add, logger,
|
||||
p -> actor(p).scale, () -> 0);
|
||||
p -> actor(p).scale);
|
||||
|
||||
private Actor actor(Player p) { return p == small.player ? small : large; }
|
||||
private final class Actor {
|
||||
@@ -39,18 +39,19 @@ class BukkitCarryTest {
|
||||
Entity vehicle;
|
||||
Location location;
|
||||
double scale;
|
||||
boolean sneaking = true, online = true, dead;
|
||||
boolean sneaking, online = true, dead, sleeping;
|
||||
GameMode gameMode = GameMode.SURVIVAL;
|
||||
Actor(String name, double scale, double x) {
|
||||
this.scale = scale; location = new Location(world, x, 64, 0);
|
||||
player = BukkitDoubles.proxy(Player.class, (p, m, a) -> switch (m.getName()) {
|
||||
case "getUniqueId" -> id;
|
||||
case "getName" -> name;
|
||||
case "getWorld" -> world;
|
||||
case "getWorld" -> location.getWorld();
|
||||
case "getLocation" -> location.clone();
|
||||
case "isOnline", "isValid" -> online;
|
||||
case "isDead" -> dead;
|
||||
case "isSleeping" -> false;
|
||||
case "getGameMode" -> GameMode.SURVIVAL;
|
||||
case "isSleeping" -> sleeping;
|
||||
case "getGameMode" -> gameMode;
|
||||
case "isSneaking" -> sneaking;
|
||||
case "isInsideVehicle" -> vehicle != null;
|
||||
case "getVehicle" -> vehicle;
|
||||
@@ -97,13 +98,85 @@ class BukkitCarryTest {
|
||||
event.setCancelled(cancelled); carry.interact(event); return event;
|
||||
}
|
||||
private void start() {
|
||||
click(small, large, EquipmentSlot.HAND, false); carry.command(large.player, "accept");
|
||||
drain();
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertSame(large.player, small.vehicle);
|
||||
}
|
||||
private void drain() {
|
||||
List<Runnable> tasks = List.copyOf(scheduled); scheduled.clear(); tasks.forEach(Runnable::run);
|
||||
}
|
||||
@Test
|
||||
void mountingKeepsFourBlockSameWorldAndAvailableParticipantBoundaries() {
|
||||
large.location.setX(4.000001);
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertNull(small.vehicle);
|
||||
drain();
|
||||
large.location.setX(4);
|
||||
start();
|
||||
carry.command(small.player, "stop");
|
||||
drain();
|
||||
UUID otherWorldId = UUID.randomUUID();
|
||||
World otherWorld = BukkitDoubles.proxy(World.class, (p, m, a) -> {
|
||||
if (m.getName().equals("getUID")) { return otherWorldId; }
|
||||
throw new UnsupportedOperationException(m.getName());
|
||||
});
|
||||
large.location.setWorld(otherWorld);
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertNull(small.vehicle);
|
||||
large.location.setWorld(world);
|
||||
for (Actor unavailable : List.of(small, large)) {
|
||||
for (int state = 0; state < 4; state++) {
|
||||
drain();
|
||||
unavailable.online = state != 0;
|
||||
unavailable.dead = state == 1;
|
||||
unavailable.sleeping = state == 2;
|
||||
unavailable.gameMode = state == 3 ? GameMode.SPECTATOR : GameMode.SURVIVAL;
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertNull(small.vehicle);
|
||||
}
|
||||
unavailable.online = true; unavailable.dead = false; unavailable.sleeping = false;
|
||||
unavailable.gameMode = GameMode.SURVIVAL;
|
||||
}
|
||||
start();
|
||||
}
|
||||
@Test
|
||||
void existingVehiclesOrPassengersOfEitherParticipantAreNeverTouched() {
|
||||
for (Actor busy : List.of(small, large)) {
|
||||
Actor other = busy == small ? large : small;
|
||||
busy.vehicle = other.player;
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertSame(other.player, busy.vehicle);
|
||||
assertEquals(0, nativeDismounts);
|
||||
busy.vehicle = null;
|
||||
drain();
|
||||
busy.passengers.add(other.player);
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertEquals(List.of(other.player), busy.passengers);
|
||||
assertNull(small.vehicle);
|
||||
assertEquals(0, nativeDismounts);
|
||||
busy.passengers.clear();
|
||||
drain();
|
||||
}
|
||||
start();
|
||||
// Additional passengers/mounts involving either occupied role are rejected.
|
||||
UUID extraId = UUID.randomUUID();
|
||||
Entity extra = BukkitDoubles.proxy(Entity.class, (p, m, a) -> {
|
||||
if (m.getName().equals("getUniqueId")) { return extraId; }
|
||||
throw new UnsupportedOperationException(m.getName());
|
||||
});
|
||||
var extraRider = new org.bukkit.event.entity.EntityMountEvent(extra, large.player);
|
||||
carry.mountEvent(extraRider);
|
||||
assertTrue(extraRider.isCancelled());
|
||||
}
|
||||
@Test
|
||||
void removedConsentActionsOnlyShowStopUsage() {
|
||||
for (String action : List.of("accept", "decline", "unknown")) {
|
||||
carry.command(large.player, action);
|
||||
assertEquals("Usage: /heights carry stop", large.messages.getLast());
|
||||
assertNull(small.vehicle);
|
||||
}
|
||||
}
|
||||
@Test
|
||||
void startsWithoutSafeGroundAndNativeStopDoesNotTeleportOrResetMotion() {
|
||||
start();
|
||||
Location before = small.location.clone();
|
||||
@@ -195,7 +268,7 @@ class BukkitCarryTest {
|
||||
}
|
||||
@Test
|
||||
void effectiveScaleChangesUseNativeCleanupAndRespectRefusals() {
|
||||
start(); small.scale = 0.9; dismountAllowed = false;
|
||||
start(); small.scale = 0.95; dismountAllowed = false;
|
||||
carry.tick();
|
||||
assertSame(large.player, small.vehicle);
|
||||
dismountAllowed = true; carry.tick();
|
||||
@@ -225,7 +298,7 @@ class BukkitCarryTest {
|
||||
@Test
|
||||
void partialNativeMountIsTrackedUntilItsInvalidRelationshipCanBeDetached() {
|
||||
invalidMountTopology = true; dismountAllowed = false;
|
||||
click(small, large, EquipmentSlot.HAND, false); carry.command(large.player, "accept");
|
||||
click(small, large, EquipmentSlot.HAND, false);
|
||||
assertSame(large.player, small.vehicle);
|
||||
assertEquals(1, nativeDismounts, "Attempt native cleanup of a partially successful invalid mount");
|
||||
assertFalse(large.messages.getLast().contains("started"));
|
||||
@@ -273,15 +346,13 @@ class BukkitCarryTest {
|
||||
assertEquals("No active ride.", large.messages.getLast());
|
||||
}
|
||||
@Test
|
||||
void onlySneakingUncancelledMainHandRequestsMountAfterAcceptance() {
|
||||
void onlyUncancelledMainHandSmallerInitiatorsMountImmediately() {
|
||||
click(small, large, EquipmentSlot.HAND, true);
|
||||
click(small, large, EquipmentSlot.OFF_HAND, false);
|
||||
small.sneaking = false; click(small, large, EquipmentSlot.HAND, false); small.sneaking = true;
|
||||
assertTrue(large.messages.isEmpty());
|
||||
assertTrue(click(small, large, EquipmentSlot.HAND, false).isCancelled());
|
||||
assertFalse(large.messages.isEmpty());
|
||||
click(large, small, EquipmentSlot.HAND, false);
|
||||
assertNull(small.vehicle);
|
||||
assertTrue(large.passengers.isEmpty());
|
||||
carry.command(large.player, "accept");
|
||||
assertTrue(click(small, large, EquipmentSlot.HAND, false).isCancelled());
|
||||
assertSame(large.player, small.vehicle);
|
||||
assertEquals(List.of(small.player), large.passengers);
|
||||
carry.command(large.player, "stop");
|
||||
|
||||
@@ -5,16 +5,24 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
class CarryPolicyTest {
|
||||
@Test
|
||||
void requiresThreeCurrentStepsWithDecimalBoundaryTolerance() {
|
||||
assertTrue(CarryPolicy.eligible(1.0, 0.7, 0.1));
|
||||
assertTrue(CarryPolicy.eligible(0.7, 0.4, 0.1));
|
||||
assertFalse(CarryPolicy.eligible(1.0, 0.700001, 0.1));
|
||||
assertFalse(CarryPolicy.eligible(1.0, 0.7, 0.2));
|
||||
void usesIndependentGapWithDecimalBoundaryTolerance() {
|
||||
assertTrue(CarryPolicy.eligible(1.0, 0.9, 0.1));
|
||||
assertTrue(CarryPolicy.eligible(0.5, 0.4, 0.1));
|
||||
assertFalse(CarryPolicy.eligible(1.0, 0.900001, 0.1));
|
||||
assertFalse(CarryPolicy.eligible(1.0, 0.9, 0.2));
|
||||
assertTrue(CarryPolicy.eligible(1.0, 0.8, 0.2));
|
||||
assertFalse(CarryPolicy.eligible(0.7, 1.0, 0.1));
|
||||
for (double invalid : new double[] {0, -1, Double.NaN, Double.POSITIVE_INFINITY}) {
|
||||
}
|
||||
|
||||
@Test
|
||||
void zeroGapStillRequiresStrictlyLargerCarrierAndAllInputsMustBeValid() {
|
||||
assertTrue(CarryPolicy.eligible(1, Math.nextDown(1.0), 0));
|
||||
assertFalse(CarryPolicy.eligible(1, 1, 0));
|
||||
assertFalse(CarryPolicy.eligible(0.9, 1, 0));
|
||||
for (double invalid : new double[] {0, -1, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}) {
|
||||
assertFalse(CarryPolicy.eligible(invalid, 0.4, 0.1));
|
||||
assertFalse(CarryPolicy.eligible(1, invalid, 0.1));
|
||||
assertFalse(CarryPolicy.eligible(1, 0.4, invalid));
|
||||
if (invalid != 0) { assertFalse(CarryPolicy.eligible(1, 0.4, invalid)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ class CarryServiceTest {
|
||||
small, new CarryService.State(0.4, true, true),
|
||||
large, new CarryService.State(1, true, true),
|
||||
third, new CarryService.State(2, true, true)));
|
||||
private long now;
|
||||
private double step = 0.1;
|
||||
private double gap = 0.1;
|
||||
private boolean near = true, mountAllowed = true, stopAllowed = true, attached;
|
||||
private int mounts, stops;
|
||||
private Runnable onMount = () -> {};
|
||||
private UUID mountedCarrier, mountedRider;
|
||||
private final List<String> messages = new ArrayList<>();
|
||||
private final CarryService service = new CarryService(new CarryService.Port() {
|
||||
@@ -21,6 +21,7 @@ class CarryServiceTest {
|
||||
public boolean nearby(UUID a, UUID b) { return near; }
|
||||
public boolean mount(UUID carrier, UUID rider) {
|
||||
mounts++; mountedCarrier = carrier; mountedRider = rider;
|
||||
onMount.run();
|
||||
attached = mountAllowed; return mountAllowed;
|
||||
}
|
||||
public boolean attached(UUID carrier, UUID rider) { return attached; }
|
||||
@@ -31,50 +32,80 @@ class CarryServiceTest {
|
||||
return stopAllowed;
|
||||
}
|
||||
public void message(UUID id, String text) { messages.add(text); }
|
||||
}, () -> step, () -> now);
|
||||
}, () -> gap);
|
||||
|
||||
@Test
|
||||
void consentExpiresAtThirtySecondsAndRechecksLiveConditions() {
|
||||
service.request(small, large);
|
||||
now = 30_000;
|
||||
assertFalse(service.accept(large).contains("started"));
|
||||
assertEquals(0, mounts);
|
||||
for (int change = 0; change < 4; change++) {
|
||||
near = true; step = 0.1;
|
||||
states.put(small, new CarryService.State(0.4, true, true));
|
||||
service.request(small, large);
|
||||
switch (change) {
|
||||
case 0 -> near = false;
|
||||
case 1 -> step = 0.3;
|
||||
case 2 -> states.put(small, new CarryService.State(0.8, true, true));
|
||||
case 3 -> states.put(small, new CarryService.State(0.4, false, true));
|
||||
default -> throw new AssertionError();
|
||||
}
|
||||
assertFalse(service.accept(large).contains("started"));
|
||||
assertEquals(0, mounts);
|
||||
}
|
||||
near = true; step = 0.1;
|
||||
states.put(small, new CarryService.State(0.4, true, true));
|
||||
service.request(small, large);
|
||||
now += 29_999;
|
||||
assertTrue(service.accept(large).contains("started"));
|
||||
void shutdownDuringNativeMountDetachesInsteadOfStartingANewRide() {
|
||||
onMount = () -> service.close();
|
||||
String result = service.ride(small, large);
|
||||
assertFalse(result.contains("started"));
|
||||
assertEquals(1, stops);
|
||||
assertFalse(service.involved(small));
|
||||
assertFalse(attached);
|
||||
}
|
||||
|
||||
@Test
|
||||
void eitherParticipantCanWithdrawPendingConsentWithStop() {
|
||||
for (UUID caller : List.of(small, large)) {
|
||||
assertTrue(service.request(small, large).contains("sent"));
|
||||
assertTrue(service.stop(caller).contains("cancelled"));
|
||||
assertTrue(service.accept(large).contains("No pending"));
|
||||
void shutdownDuringMountStillReportsRefusedNativeDetachmentHonestly() {
|
||||
stopAllowed = false;
|
||||
onMount = () -> service.close();
|
||||
String result = service.ride(small, large);
|
||||
assertFalse(result.contains("started"));
|
||||
assertTrue(result.contains("refused"));
|
||||
assertTrue(service.involved(small));
|
||||
assertTrue(attached);
|
||||
assertEquals(1, service.close());
|
||||
stopAllowed = true;
|
||||
assertEquals(0, service.close());
|
||||
}
|
||||
|
||||
@Test
|
||||
void synchronousMountCallbacksCannotStartAnotherRideForEitherParticipant() {
|
||||
onMount = () -> {
|
||||
onMount = () -> {};
|
||||
assertFalse(service.ride(small, third).contains("started"));
|
||||
assertFalse(service.ride(large, third).contains("started"));
|
||||
};
|
||||
assertTrue(service.ride(small, large).contains("started"));
|
||||
assertEquals(1, mounts);
|
||||
assertEquals(large, mountedCarrier);
|
||||
assertEquals(small, mountedRider);
|
||||
assertFalse(service.involved(third));
|
||||
}
|
||||
|
||||
@Test
|
||||
void immediateRideIsSmallerInitiatedOnlyAndChecksCurrentEligibility() {
|
||||
assertFalse(service.ride(large, small).contains("started"));
|
||||
assertEquals(0, mounts);
|
||||
for (int change = 0; change < 5; change++) {
|
||||
near = true; gap = 0.1;
|
||||
states.put(small, new CarryService.State(0.4, true, true));
|
||||
switch (change) {
|
||||
case 0 -> near = false;
|
||||
case 1 -> gap = 0.7;
|
||||
case 2 -> states.put(small, new CarryService.State(0.95, true, true));
|
||||
case 3 -> states.put(small, new CarryService.State(0.4, false, true));
|
||||
case 4 -> states.remove(small);
|
||||
default -> throw new AssertionError();
|
||||
}
|
||||
assertFalse(service.ride(small, large).contains("started"));
|
||||
assertEquals(0, mounts);
|
||||
}
|
||||
near = true; gap = 0.1;
|
||||
states.put(small, new CarryService.State(0.9, true, true));
|
||||
assertTrue(service.ride(small, large).contains("started"));
|
||||
assertEquals(1, mounts);
|
||||
assertEquals(large, mountedCarrier);
|
||||
assertEquals(small, mountedRider);
|
||||
assertTrue(service.involved(small));
|
||||
assertTrue(service.involved(large));
|
||||
assertTrue(messages.stream().noneMatch(message -> message.contains("request")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void automaticNativeRefusalIsReportedOnceRatherThanSilentlyRetried() {
|
||||
service.request(small, large); service.accept(large);
|
||||
service.ride(small, large);
|
||||
messages.clear();
|
||||
states.put(small, new CarryService.State(0.9, true, true));
|
||||
states.put(small, new CarryService.State(0.95, true, true));
|
||||
stopAllowed = false;
|
||||
service.tick(); service.tick();
|
||||
assertEquals(2, messages.size(), "Notify both participants once, not every tick");
|
||||
@@ -84,51 +115,35 @@ class CarryServiceTest {
|
||||
assertFalse(service.involved(small));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reservesOneRequestPerPlayerAndDeclineReleasesBoth() {
|
||||
assertTrue(service.request(small, large).contains("sent"));
|
||||
assertFalse(service.request(third, large).contains("sent"));
|
||||
assertFalse(service.request(small, third).contains("sent"));
|
||||
assertTrue(service.decline(large).contains("declined"));
|
||||
assertTrue(service.request(small, third).contains("sent"));
|
||||
now = 30_000;
|
||||
service.tick();
|
||||
assertTrue(service.request(small, large).contains("sent"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsExistingPassengersVehiclesAndActiveRidesAndFailedMounts() {
|
||||
for (UUID busy : List.of(small, large)) {
|
||||
CarryService.State before = states.get(busy);
|
||||
states.put(busy, new CarryService.State(before.scale(), true, false));
|
||||
assertFalse(service.request(small, large).contains("sent"));
|
||||
assertFalse(service.ride(small, large).contains("started"));
|
||||
assertEquals(0, mounts);
|
||||
states.put(busy, before);
|
||||
}
|
||||
service.request(small, large);
|
||||
states.put(small, new CarryService.State(0.4, true, false));
|
||||
assertFalse(service.accept(large).contains("started"));
|
||||
states.put(small, new CarryService.State(0.4, true, true));
|
||||
service.request(small, large);
|
||||
mountAllowed = false;
|
||||
assertFalse(service.accept(large).contains("started"));
|
||||
assertTrue(service.ride(small, large).contains("refused"));
|
||||
assertFalse(service.involved(small));
|
||||
mountAllowed = true;
|
||||
service.request(small, large);
|
||||
service.accept(large);
|
||||
assertFalse(service.request(third, large).contains("sent"));
|
||||
assertFalse(service.request(small, third).contains("sent"));
|
||||
assertTrue(service.ride(small, large).contains("started"));
|
||||
assertFalse(service.ride(third, large).contains("started"));
|
||||
assertFalse(service.ride(small, third).contains("started"));
|
||||
assertFalse(service.ride(large, third).contains("started"));
|
||||
assertEquals(2, mounts);
|
||||
}
|
||||
|
||||
@Test
|
||||
void lossOfEligibilityAttemptsNativeStopAndRefusedVoluntaryStopsRemainAccuratelyTracked() {
|
||||
service.request(small, large); service.accept(large);
|
||||
service.ride(small, large);
|
||||
stopAllowed = false;
|
||||
states.put(small, new CarryService.State(0.9, true, true));
|
||||
states.put(small, new CarryService.State(0.95, true, true));
|
||||
service.tick();
|
||||
assertEquals(1, stops);
|
||||
assertTrue(service.involved(small));
|
||||
assertTrue(service.stop(large).contains("refused"));
|
||||
// No pending rescue job: if eligibility recovers, a voluntary stop can be requested again.
|
||||
states.put(small, new CarryService.State(0.4, true, true));
|
||||
stopAllowed = true;
|
||||
service.tick();
|
||||
@@ -139,31 +154,30 @@ class CarryServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void lifecycleClearsRequestsAndRidesAndReportsUnresolvedDisable() {
|
||||
service.request(small, large);
|
||||
void lifecycleCleansRidesAndReportsUnresolvedDisable() {
|
||||
service.ride(small, large);
|
||||
assertTrue(service.cleanup(small));
|
||||
assertTrue(service.accept(large).contains("No pending"));
|
||||
service.request(small, large); service.accept(large);
|
||||
service.ride(small, large);
|
||||
assertTrue(service.cleanup(large));
|
||||
assertFalse(service.involved(small));
|
||||
service.request(small, large); service.accept(large);
|
||||
service.ride(small, large);
|
||||
stopAllowed = false;
|
||||
assertFalse(service.cleanup(small));
|
||||
assertEquals(1, service.close());
|
||||
assertTrue(service.involved(small));
|
||||
assertFalse(service.request(third, large).contains("sent"));
|
||||
assertFalse(service.ride(third, large).contains("started"));
|
||||
stopAllowed = true;
|
||||
assertEquals(0, service.close());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unavailableOrDetachedParticipantsTriggerCleanup() {
|
||||
service.request(small, large); service.accept(large);
|
||||
service.ride(small, large);
|
||||
attached = false;
|
||||
service.tick();
|
||||
assertEquals(1, stops);
|
||||
assertFalse(service.involved(large));
|
||||
service.request(small, large); service.accept(large);
|
||||
service.ride(small, large);
|
||||
states.put(large, new CarryService.State(1, false, false));
|
||||
service.tick();
|
||||
assertEquals(2, stops);
|
||||
@@ -171,19 +185,13 @@ class CarryServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void eitherDirectionRequiresOtherPlayersExplicitConsent() {
|
||||
for (boolean pickup : new boolean[] {false, true}) {
|
||||
UUID sender = pickup ? large : small, recipient = pickup ? small : large;
|
||||
assertTrue(service.request(sender, recipient).contains("sent"));
|
||||
assertEquals(0, mounts);
|
||||
assertTrue(service.accept(sender).contains("No pending"));
|
||||
assertTrue(service.accept(recipient).contains("started"));
|
||||
assertEquals(large, mountedCarrier);
|
||||
assertEquals(small, mountedRider);
|
||||
assertTrue(service.involved(small));
|
||||
assertTrue(service.involved(large));
|
||||
assertTrue(service.stop(sender).contains("ended"));
|
||||
mounts = 0;
|
||||
void eitherParticipantCanStopImmediatelyWithoutApprovalOrRemountCooldown() {
|
||||
for (UUID caller : List.of(small, large)) {
|
||||
assertTrue(service.ride(small, large).contains("started"));
|
||||
assertTrue(service.stop(caller).contains("ended"));
|
||||
assertFalse(service.involved(small));
|
||||
}
|
||||
assertEquals(2, mounts);
|
||||
assertEquals(2, stops);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,38 @@ class HeightSettingsTest {
|
||||
assertEquals(16, settings.randomStepCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingGapDefaultsIndependentlyAndBoundsKeepExplicitGap() throws Exception {
|
||||
var config = new org.bukkit.configuration.file.YamlConfiguration();
|
||||
config.loadFromString(java.nio.file.Files.readString(java.nio.file.Path.of("src/main/resources/config.yml")));
|
||||
assertEquals(0.1, SpigotHeightsPlugin.loadSettings(config).carryMinimumScaleGap());
|
||||
config.set("carry.minimum-scale-gap", null);
|
||||
config.set("height.adjustment-step", 0.25);
|
||||
assertEquals(0.1, SpigotHeightsPlugin.loadSettings(config).carryMinimumScaleGap());
|
||||
for (double gap : new double[] {0, 0.2, 1.5}) {
|
||||
config.set("carry.minimum-scale-gap", gap);
|
||||
HeightSettings settings = SpigotHeightsPlugin.loadSettings(config);
|
||||
assertEquals(gap, settings.carryMinimumScaleGap());
|
||||
assertEquals(0.25, settings.adjustmentStep());
|
||||
var live = new LiveHeightSettings(settings, ignored -> {});
|
||||
live.setBound("max", 3);
|
||||
assertEquals(gap, live.get().carryMinimumScaleGap());
|
||||
assertEquals(0.25, live.get().adjustmentStep());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidCarryGapInExistingConfigLoader() throws Exception {
|
||||
var config = new org.bukkit.configuration.file.YamlConfiguration();
|
||||
config.loadFromString(java.nio.file.Files.readString(java.nio.file.Path.of("src/main/resources/config.yml")));
|
||||
for (Object invalid : new Object[] {-0.1, Double.NaN, Double.POSITIVE_INFINITY,
|
||||
Double.NEGATIVE_INFINITY, "garbage", true, java.util.List.of(0.1)}) {
|
||||
config.set("carry.minimum-scale-gap", invalid);
|
||||
assertThrows(IllegalArgumentException.class, () -> SpigotHeightsPlugin.loadSettings(config),
|
||||
"Invalid carry gap must fail startup validation: " + invalid);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidRangesAndNumbers() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
|
||||
@@ -51,19 +51,26 @@ class HeightsCommandTest {
|
||||
for (String action : List.of("accept", "decline", "stop")) {
|
||||
command.onCommand(player, null, "heights", new String[] {"CaRrY", action.toUpperCase()});
|
||||
}
|
||||
assertEquals(List.of("accept", "decline", "stop"), actions);
|
||||
assertEquals(List.of("stop"), actions);
|
||||
assertTrue(messages.stream().allMatch(message -> message.equals("Usage: /heights carry stop")));
|
||||
for (String[] args : new String[][] {{"carry"}, {"carry", "throw"}, {"carry", "stop", "extra"},
|
||||
{"player", "Steve", "0.5"}, {"settings"}}) {
|
||||
command.onCommand(player, null, "heights", args);
|
||||
}
|
||||
command.onCommand(sender(true), null, "heights", new String[] {"carry", "accept"});
|
||||
assertEquals(3, actions.size());
|
||||
assertEquals(1, actions.size());
|
||||
assertEquals(List.of("carry"), complete(player, ""));
|
||||
assertEquals(List.of("accept", "decline", "stop"), complete(player, "carry", ""));
|
||||
assertEquals(List.of("stop"), complete(player, "carry", ""));
|
||||
assertEquals(List.of(), complete(player, "carry", "a"));
|
||||
assertEquals(List.of(), complete(player, "carry", "d"));
|
||||
assertEquals(List.of("stop"), complete(player, "carry", "s"));
|
||||
assertEquals(List.of(), complete(player, "player", ""));
|
||||
org.bukkit.configuration.file.YamlConfiguration yaml = org.bukkit.configuration.file.YamlConfiguration
|
||||
.loadConfiguration(new java.io.File("src/main/resources/plugin.yml"));
|
||||
assertTrue(yaml.getString("commands.heights.usage").contains("carry stop"));
|
||||
assertTrue(!yaml.getString("commands.heights.usage").contains("accept"));
|
||||
assertTrue(!yaml.getString("commands.heights.usage").contains("decline"));
|
||||
assertTrue(!yaml.getString("commands.heights.description").contains("consensual"));
|
||||
assertEquals(null, yaml.getString("commands.heights.permission"));
|
||||
assertEquals("op", yaml.getString("permissions.spigotheights.admin.default"));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user