feat(travel): grant finite native Speed I on Dirt Paths
This commit is contained in:
1 parent
01e6ac6e5a
commit
ea760815bd
22 files changed
+1489
-23
No files matched your search
+3
-2
@@ -20,7 +20,7 @@ class AdminActionConfigurationCatalogNativeTest {
|
||||
|
||||
private static final List<List<String>> FAMILIES = List.of(
|
||||
List.of("adventure-mode"), List.of(AdminReviveSettings.KEY), List.of(SwitchDelaySettings.KEY),
|
||||
List.of(RoleplaySettings.KEY), List.of(PartySettings.KEY), PartyEconomySettings.keys(),
|
||||
List.of(RoleplaySettings.KEY), PathSpeedSettings.keys(), List.of(PartySettings.KEY), PartyEconomySettings.keys(),
|
||||
GearSettings.keys(), RareSettings.keys(), DownedSettings.keys(), CoinSettings.keys(),
|
||||
List.of(HardMobXpSettings.KEY), AdventureQuestSettings.keys(),
|
||||
List.of(SheetResourcePackSettings.URL_KEY, SheetResourcePackSettings.SHA1_KEY),
|
||||
@@ -35,7 +35,7 @@ class AdminActionConfigurationCatalogNativeTest {
|
||||
|
||||
private void seed() throws Exception {
|
||||
Files.writeString(data.resolve("config.yml"),
|
||||
"retained: untouched\nfrost-shard-range-blocks: 48\nadventure-mode: true\nroleplay-disabled: false\n");
|
||||
"retained: untouched\nfrost-shard-range-blocks: 48\nadventure-mode: true\nroleplay-disabled: false\npath-speed-enabled: true\npath-speed-lease-ticks: 20\n");
|
||||
}
|
||||
|
||||
private static JsonObject values(JsonObject row) { return row.getAsJsonObject("data"); }
|
||||
@@ -150,6 +150,7 @@ class AdminActionConfigurationCatalogNativeTest {
|
||||
private static final List<String[]> WRITES = List.of(
|
||||
new String[]{"adventure-mode", "false"}, new String[]{AdminReviveSettings.KEY, "61"},
|
||||
new String[]{SwitchDelaySettings.KEY, "901"}, new String[]{RoleplaySettings.KEY, "true"},
|
||||
new String[]{PathSpeedSettings.ENABLED, "false"},
|
||||
new String[]{PartySettings.KEY, "7"}, new String[]{"party-registration-price", "11"},
|
||||
new String[]{"gear-price-leather", "3"}, new String[]{"rare-price-reskill", "2001"},
|
||||
new String[]{"downed-timeout-seconds", "301"}, new String[]{"starting-coins-min", "2"},
|
||||
|
||||
@@ -418,6 +418,8 @@ class CharacterBookNativeTest {
|
||||
var categorized = new java.util.LinkedHashMap<String, java.util.List<String>>();
|
||||
var indexPageByAbility = new java.util.HashMap<String, Integer>();
|
||||
int partyPage = firstPageStarting(pages, "Party");
|
||||
assertTrue(firstPageStarting(pages, "Dirt Path travel") > partyPage,
|
||||
"Road guidance must preserve the existing linked detail/inventory/party section boundaries");
|
||||
for (int page = index; page < pages.size() && pages.get(page).getString().startsWith("Ability index"); page++) {
|
||||
var lines = pages.get(page).getString().split("\\n");
|
||||
assertTrue(lines.length >= 2); String category = lines[1];
|
||||
|
||||
@@ -60,8 +60,10 @@ class FantasyStickLifecycleNativeTest {
|
||||
assertTrue(fixture.order.indexOf("CharacterChatNames") >= 0);
|
||||
assertTrue(fixture.order.indexOf("CharacterChatNames") < recipe);
|
||||
assertNotNull(fixture.packetListener);
|
||||
assertEquals(19, fixture.timers.size(),
|
||||
"Presentation, ability/bond/rally/banner cleanup, provenance, reward retry, recovery, passive effects, armor/rare/adventure/fishing/dungeon/downed refresh and session particles");
|
||||
assertTrue(fixture.order.indexOf("PathSpeed") >= 0);
|
||||
assertTrue(fixture.order.indexOf("PathSpeed") < recipe);
|
||||
assertEquals(20, fixture.timers.size(),
|
||||
"Presentation, ability/bond/rally/banner cleanup, provenance, reward retry, recovery, passive effects, road travel, armor/rare/adventure/fishing/dungeon/downed refresh and session particles");
|
||||
assertTrue(fixture.order.indexOf("PartyCombat") >= 0);
|
||||
assertTrue(fixture.order.indexOf("PartyCombat") < recipe);
|
||||
assertTrue(fixture.order.indexOf("CombatExperience") >= 0);
|
||||
@@ -1618,7 +1620,7 @@ class FantasyStickLifecycleNativeTest {
|
||||
assertNotNull(actor.core.marker());assertTrue(actor.core.marker().endsWith("|PACKED"));
|
||||
}
|
||||
private void captureWorkers(JavaPlugin instance) {
|
||||
for (String name : List.of("characters", "receipts", "adventureSettings", "revivals", "trainingDummies",
|
||||
for (String name : List.of("characters", "receipts", "adventureSettings", "pathSpeedSettings", "revivals", "trainingDummies",
|
||||
"hardMobXpSettings", "adventureQuestSettings", "adventureQuests")) {
|
||||
var store = field(instance, name);
|
||||
if (store != null) {
|
||||
@@ -1792,6 +1794,9 @@ class FantasyStickLifecycleNativeTest {
|
||||
case "getHandle" -> nativePlayer;
|
||||
case "getTicksLived" -> nativePlayer.tickCount;
|
||||
case "getEntityId" -> 42;
|
||||
// Inventory-only actors have no physics support; road cases explicitly supply these ports.
|
||||
case "isOnGround", "isFlying", "isSwimming", "isGliding" -> false;
|
||||
case "getVelocity" -> new org.bukkit.util.Vector();
|
||||
case "getName" -> accountName;
|
||||
case "hasPermission" -> allowed;
|
||||
case "getWorld" -> core.location.getWorld();
|
||||
|
||||
@@ -413,13 +413,13 @@ class PassivePotionCleanupNativeTest {
|
||||
&& listener.getListener().getClass().getName().equals("games.dmg.fantasystick.passive.PersistentPotionEffect")).count();
|
||||
}
|
||||
|
||||
private static void acceptDeath(FantasyStickLifecycleNativeTest.Fixture f, FantasyStickLifecycleNativeTest.Actor actor) throws Exception {
|
||||
static void acceptDeath(FantasyStickLifecycleNativeTest.Fixture f, FantasyStickLifecycleNativeTest.Actor actor) throws Exception {
|
||||
clickMenu(f, actor, 11);
|
||||
ReskillEventsNativeTest.await(f, () -> sessions(f).active(actor.core.id).isEmpty());
|
||||
DownedSessionNativeTest.awaitTail(f, actor);
|
||||
assertTrue(sessions(f).downed(actor.core.id).isEmpty());
|
||||
}
|
||||
private static void clickMenu(FantasyStickLifecycleNativeTest.Fixture f, FantasyStickLifecycleNativeTest.Actor actor, int slot) {
|
||||
static void clickMenu(FantasyStickLifecycleNativeTest.Fixture f, FantasyStickLifecycleNativeTest.Actor actor, int slot) {
|
||||
var menu = actor.inventories.getLast();
|
||||
var view = new org.bukkit.craftbukkit.inventory.CraftAbstractInventoryView() {
|
||||
@Override public org.bukkit.inventory.Inventory getTopInventory() { return menu; }
|
||||
@@ -462,7 +462,7 @@ class PassivePotionCleanupNativeTest {
|
||||
var effect = port.current(type); assertNotNull(effect); assertTrue(effect.isInfinite()); assertEquals(0, effect.getAmplifier());
|
||||
}
|
||||
}
|
||||
private static void down(FantasyStickLifecycleNativeTest.Fixture f, FantasyStickLifecycleNativeTest.Actor actor) throws Exception {
|
||||
static void down(FantasyStickLifecycleNativeTest.Fixture f, FantasyStickLifecycleNativeTest.Actor actor) throws Exception {
|
||||
actor.core.health = 0;
|
||||
doReturn(null).when(actor.player).getLastDamageCause(); doReturn(null).when(actor.player).getFishHook();
|
||||
var source = new org.bukkit.craftbukkit.damage.CraftDamageSource(new net.minecraft.world.damagesource.DamageSource(
|
||||
@@ -522,7 +522,7 @@ class PassivePotionCleanupNativeTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class NativePort implements org.bukkit.event.Listener {
|
||||
static final class NativePort implements org.bukkit.event.Listener {
|
||||
boolean cancelRemoval, lateCancelRemoval, failAfterRemoval, deferRemoval, failRemovalAfterDecision;
|
||||
final List<Runnable> deferred = new ArrayList<>();
|
||||
int failedObservations;
|
||||
@@ -555,10 +555,12 @@ class PassivePotionCleanupNativeTest {
|
||||
var field = net.minecraft.world.entity.LivingEntity.class.getDeclaredField("tickingEffects"); field.setAccessible(true);
|
||||
field.setBoolean(actor.nativePlayer, value); deferRemoval = value;
|
||||
}
|
||||
private void remove(PotionEffectType type) {
|
||||
void milk() { for (var type : List.copyOf(effects.keySet())) remove(type, EntityPotionEffectEvent.Cause.MILK); }
|
||||
private void remove(PotionEffectType type) { remove(type, EntityPotionEffectEvent.Cause.PLUGIN); }
|
||||
private void remove(PotionEffectType type, EntityPotionEffectEvent.Cause cause) {
|
||||
var old = current(type);
|
||||
if (old == null) return;
|
||||
var event = new EntityPotionEffectEvent(actor.player, old, null, null, EntityPotionEffectEvent.Cause.PLUGIN,
|
||||
var event = new EntityPotionEffectEvent(actor.player, old, null, null, cause,
|
||||
EntityPotionEffectEvent.Action.REMOVED, false);
|
||||
fixture.dispatcher.accept(event); decisions.add(event);
|
||||
if (failRemovalAfterDecision) throw new IllegalStateException("Native removal failed after decision, before mutation");
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package games.dmg.fantasystick;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class PathSpeedConfigurationNativeTest {
|
||||
@TempDir Path data;
|
||||
@BeforeAll static void bootstrap() throws Exception { NativeRuntime.bootstrap(); }
|
||||
@Test void registeredAdministratorReadUpdateAndCompletionUseDurableRoadPolicy() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var sender = new EquipmentAdminCommandNativeTest.Sender();
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks"});
|
||||
assertTrue(sender.messages.getLast().contains("path-speed-lease-ticks=20"), "Registered config read reports the effective road lease");
|
||||
assertEquals(List.of("path-speed-enabled", "path-speed-lease-ticks"), f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-"}));
|
||||
assertEquals(List.of("false", "true"), f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", ""}));
|
||||
assertEquals(List.of("20"), f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks", ""}));
|
||||
var actor = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, actor); PathSpeedNativeTest.support(actor);
|
||||
f.players.put(actor.core.id, actor.player); f.activate(actor); PathSpeedNativeTest.pulse(f);
|
||||
assertEquals(20, effects.current(org.bukkit.potion.PotionEffectType.SPEED).getDuration());
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks", "1"});
|
||||
assertEquals(20, effects.current(org.bukkit.potion.PotionEffectType.SPEED).getDuration(), "Queued save alone cannot change native policy");
|
||||
f.tick();
|
||||
assertEquals(20, effects.current(org.bukkit.potion.PotionEffectType.SPEED).getDuration(), "A shorter refused refresh preserves the captured existing finite budget");
|
||||
actor.core.location.setY(65); PathSpeedNativeTest.pulse(f);
|
||||
actor.core.location.setY(64.9375); PathSpeedNativeTest.pulse(f);
|
||||
assertEquals(1, effects.current(org.bukkit.potion.PotionEffectType.SPEED).getDuration());
|
||||
assertTrue(sender.messages.getLast().contains("Saved path-speed-lease-ticks=1"));
|
||||
assertTrue(java.nio.file.Files.readString(data.resolve("config.yml")).contains("path-speed-lease-ticks: 1"));
|
||||
assertEquals(List.of("1", "20"), f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks", ""}));
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "false"}); f.tick();
|
||||
assertTrue(sender.messages.getLast().contains("Saved path-speed-enabled=false"));
|
||||
assertNull(effects.current(org.bukkit.potion.PotionEffectType.SPEED));
|
||||
f.plugin.setEnabled(false); f.plugin.setEnabled(true);
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks"});
|
||||
assertTrue(sender.messages.getLast().contains("=1"));
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled"});
|
||||
assertTrue(sender.messages.getLast().contains("=false"));
|
||||
}
|
||||
}
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||
void lostCompletionPermissionCannotPublishItsPolicyOrLeakThroughASubsequentDifferentKey(boolean subsequentLease) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var sender = new EquipmentAdminCommandNativeTest.Sender();
|
||||
var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); PathSpeedNativeTest.support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); PathSpeedNativeTest.pulse(f);
|
||||
var original = effects.effects.get(org.bukkit.potion.PotionEffectType.SPEED);
|
||||
var settings = (games.dmg.fantasystick.persistence.PathSpeedSettings) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedSettings");
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "false"});
|
||||
sender.allowed = false; f.tick();
|
||||
if (subsequentLease) {
|
||||
sender.allowed = true;
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks", "7"}); f.tick();
|
||||
assertEquals(7, settings.settings().leaseTicks());
|
||||
}
|
||||
assertTrue(settings.settings().enabled(), "Native completion must recheck authority, and another key cannot publish the interrupted toggle");
|
||||
assertSame(original, effects.effects.get(org.bukkit.potion.PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
|
||||
@Test void acceptedRoadWriteDrainsBeforeNewLifetimeStartsAndOldCallbackCannotPublish() throws Exception {
|
||||
var release = new java.util.concurrent.CountDownLatch(1);
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
try {
|
||||
f.plugin.setEnabled(true);
|
||||
var old = (games.dmg.fantasystick.persistence.PathSpeedSettings) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedSettings");
|
||||
var worker = (java.util.concurrent.ExecutorService) FantasyStickLifecycleNativeTest.Fixture.field(old, "worker");
|
||||
var entered = new java.util.concurrent.CountDownLatch(1);
|
||||
worker.execute(() -> { entered.countDown(); try { release.await(); } catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); } });
|
||||
assertTrue(entered.await(5, java.util.concurrent.TimeUnit.SECONDS));
|
||||
var sender = new EquipmentAdminCommandNativeTest.Sender();
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "false"});
|
||||
f.plugin.setEnabled(false); f.plugin.setEnabled(true);
|
||||
assertNull(FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "sessions"));
|
||||
release.countDown();
|
||||
ReskillEventsNativeTest.await(f, () -> FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "sessions") != null);
|
||||
var current = (games.dmg.fantasystick.persistence.PathSpeedSettings) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedSettings");
|
||||
assertNotSame(old, current); assertFalse(current.settings().enabled()); assertTrue(old.settings().enabled());
|
||||
assertFalse(sender.messages.stream().anyMatch(message -> message.startsWith("Saved path-speed-enabled")));
|
||||
} finally { release.countDown(); }
|
||||
}
|
||||
}
|
||||
|
||||
@Test void registeredValidationPermissionAndReadOnlyCompletionCannotMutateRoadPolicy() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var sender = new EquipmentAdminCommandNativeTest.Sender();
|
||||
var setting = (games.dmg.fantasystick.persistence.PathSpeedSettings) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedSettings");
|
||||
for (String value : List.of("0", "201", "-1", "1.5", "", "999999999999999999999")) {
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-lease-ticks", value});
|
||||
assertTrue(sender.messages.getLast().contains("1–200")); assertEquals(20, setting.settings().leaseTicks());
|
||||
}
|
||||
for (String value : List.of("TRUE", "yes", "1", "")) {
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", value});
|
||||
assertTrue(sender.messages.getLast().contains("true or false")); assertTrue(setting.settings().enabled());
|
||||
}
|
||||
var file = data.resolve("config.yml"); boolean existed = java.nio.file.Files.exists(file);
|
||||
var before = existed ? java.nio.file.Files.readAllBytes(file) : new byte[0];
|
||||
assertTrue(f.command.tabComplete(sender.port, "fstickadmin", new String[]{""}).contains("config"));
|
||||
assertEquals(List.of("config"), f.command.tabComplete(sender.port, "fstickadmin", new String[]{"con"}));
|
||||
assertEquals(List.of("true"), f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "t"}));
|
||||
assertTrue(f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "true", ""}).isEmpty());
|
||||
assertTrue(f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "not-a-key", ""}).isEmpty());
|
||||
assertEquals(existed, java.nio.file.Files.exists(file));
|
||||
if (existed) assertArrayEquals(before, java.nio.file.Files.readAllBytes(file));
|
||||
sender.allowed = false;
|
||||
assertTrue(f.command.tabComplete(sender.port, "fstickadmin", new String[]{"config", "path-speed-"}).isEmpty());
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "false"});
|
||||
assertTrue(sender.messages.getLast().contains("Permission denied")); assertTrue(setting.settings().enabled());
|
||||
sender.allowed = true;
|
||||
f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "false", "extra"});
|
||||
assertTrue(sender.messages.getLast().contains("Usage")); assertTrue(setting.settings().enabled());
|
||||
}
|
||||
}
|
||||
@Test void failedRegisteredSaveLeavesEffectivePolicyAndActiveRoadLayerUnchanged() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var sender = new EquipmentAdminCommandNativeTest.Sender();
|
||||
var actor = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, actor); PathSpeedNativeTest.support(actor);
|
||||
f.players.put(actor.core.id, actor.player); f.activate(actor); PathSpeedNativeTest.pulse(f);
|
||||
var original = effects.effects.get(org.bukkit.potion.PotionEffectType.SPEED);
|
||||
try (var channel = java.nio.channels.FileChannel.open(data.resolve(".config.lock"), java.nio.file.StandardOpenOption.CREATE, java.nio.file.StandardOpenOption.WRITE);
|
||||
var lock = channel.lock()) {
|
||||
assertTrue(lock.isValid()); f.command.execute(sender.port, "fstickadmin", new String[]{"config", "path-speed-enabled", "false"}); f.tick();
|
||||
}
|
||||
assertTrue(sender.messages.getLast().contains("save failed"));
|
||||
assertSame(original, effects.effects.get(org.bukkit.potion.PotionEffectType.SPEED));
|
||||
var settings = (games.dmg.fantasystick.persistence.PathSpeedSettings) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedSettings");
|
||||
assertTrue(settings.settings().enabled());
|
||||
}
|
||||
}
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(strings = {"path-speed-enabled: 'true'", "path-speed-enabled: 1", "path-speed-lease-ticks: 0", "path-speed-lease-ticks: 201", "path-speed-lease-ticks: 1.5", "path-speed-lease-ticks: '20'"})
|
||||
void invalidTypedStartupIsRefusedBeforeFeatureInstallation(String contents) throws Exception {
|
||||
java.nio.file.Files.writeString(data.resolve("config.yml"), contents + "\n");
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
assertThrows(IllegalArgumentException.class, () -> f.plugin.setEnabled(true)); assertTrue(f.order.isEmpty()); assertTrue(f.pulses.isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package games.dmg.fantasystick;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static games.dmg.fantasystick.PathSpeedNativeTest.*;
|
||||
import java.nio.file.Path;
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
class PathSpeedInterruptionNativeTest {
|
||||
@TempDir Path data;
|
||||
@BeforeAll static void bootstrap() throws Exception { NativeRuntime.bootstrap(); }
|
||||
@ParameterizedTest @ValueSource(booleans = {false, true})
|
||||
void realMilkDecisionCreatesANewApplicationOnlyAfterAcceptedRemoval(boolean veto) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var original = effects.effects.get(PotionEffectType.SPEED);
|
||||
ReskillEventsNativeTest.await(f, () -> roadEvents(data).size() == 1);
|
||||
effects.lateCancelRemoval = veto; effects.milk(); pulse(f);
|
||||
assertTrue(effects.decisions.stream().anyMatch(e -> e.getCause() == EntityPotionEffectEvent.Cause.MILK && e.isCancelled() == veto));
|
||||
if (veto) assertSame(original, effects.effects.get(PotionEffectType.SPEED));
|
||||
else assertNotSame(original, effects.effects.get(PotionEffectType.SPEED));
|
||||
effects.lateCancelRemoval = false; f.plugin.setEnabled(false);
|
||||
ReskillEventsNativeTest.await(f, () -> roadEvents(data).size() == (veto ? 2 : 4));
|
||||
var rows = roadEvents(data);
|
||||
assertEquals(veto ? 1 : 2, rows.stream().filter(r -> r.get("type").getAsString().endsWith("effect.applied")).count());
|
||||
assertEquals(veto ? 1 : 2, rows.stream().map(r -> r.getAsJsonObject("data").get("application_id")).distinct().count());
|
||||
assertNull(effects.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
@Test void transferredSheetAndRetiredTimerCannotBoostTheFormerHolder() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var first = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var sheet = a.core.inventory.getItemInOffHand().clone();
|
||||
a.core.inventory.setItemInOffHand(null); f.changed(a); f.awaitCharacterAndReceipt(a); PartyBookNativeTest.drain(f); pulse(f);
|
||||
assertNull(first.current(PotionEffectType.SPEED));
|
||||
var b = new FantasyStickLifecycleNativeTest.Actor(data); var second = new PassivePotionCleanupNativeTest.NativePort(f, b); support(b);
|
||||
b.core.inventory.setItemInOffHand(sheet); f.players.put(b.core.id, b.player); f.activate(b); pulse(f);
|
||||
var sessions = (games.dmg.fantasystick.session.EquipmentSessions) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "sessions");
|
||||
assertEquals(a.core.record.id(), sessions.active(b.core.id).orElseThrow().character());
|
||||
assertNull(first.current(PotionEffectType.SPEED)); assertNotNull(second.current(PotionEffectType.SPEED));
|
||||
var retired = f.pulses.stream().filter(p -> p.getClass().getName().startsWith("games.dmg.fantasystick.passive.PathSpeed")).findFirst().orElseThrow();
|
||||
f.plugin.setEnabled(false); f.plugin.setEnabled(true); retired.run();
|
||||
assertNull(first.current(PotionEffectType.SPEED)); assertNull(second.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
@Test void writerFailureRetainsReplayableFactsButNeverReplaysSpeed() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a);
|
||||
((games.dmg.fantasystick.events.LocalEventLog) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "eventLog")).close();
|
||||
pulse(f); assertEquals(20, effects.current(PotionEffectType.SPEED).getDuration());
|
||||
a.core.location.setY(65); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
f.plugin.setEnabled(false);
|
||||
((java.util.concurrent.CompletionStage<?>) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedAuditDrain")).toCompletableFuture().get(5, java.util.concurrent.TimeUnit.SECONDS);
|
||||
f.plugin.setEnabled(true);
|
||||
ReskillEventsNativeTest.await(f, () -> roadEvents(data).size() == 2);
|
||||
assertNull(effects.current(PotionEffectType.SPEED));
|
||||
var start = roadEvents(data).getFirst().getAsJsonObject("data"); var end = roadEvents(data).getLast().getAsJsonObject("data");
|
||||
assertEquals(start.get("application_id"), end.get("application_id"));
|
||||
assertEquals(start.get("owner_session_id"), end.get("owner_session_id"));
|
||||
assertEquals(a.core.record.id().toString(), start.get("owner_character_id").getAsString());
|
||||
}
|
||||
}
|
||||
@Test void failedAuditContextCaptureIsNotRetriedAsANewBusinessApplicationOnRefresh() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a);
|
||||
doThrow(new IllegalStateException("Controlled audit-context capture refusal")).when(a.player).getName();
|
||||
pulse(f); assertEquals(20, effects.current(PotionEffectType.SPEED).getDuration());
|
||||
doReturn("Account").when(a.player).getName();
|
||||
for (int tick = 0; tick < 3; tick++) { effects.effects.get(PotionEffectType.SPEED).tickClient(); a.nativePlayer.tickCount++; pulse(f); }
|
||||
f.plugin.setEnabled(false);
|
||||
((java.util.concurrent.CompletionStage<?>) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedAuditDrain")).toCompletableFuture().get(5, java.util.concurrent.TimeUnit.SECONDS);
|
||||
assertTrue(roadEvents(data).isEmpty(), "Lost native observations cannot be synthesized from later lease refreshes");
|
||||
}
|
||||
}
|
||||
@ParameterizedTest @ValueSource(booleans = {false, true})
|
||||
void nativeApplicationCallbacksThatExitOrCloseCannotLeaveANewRoadGrantBehind(boolean close) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a);
|
||||
class Invalidate implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
|
||||
public void invalidate(EntityPotionEffectEvent event) {
|
||||
if (event.getEntity() != a.player || event.getAction() != EntityPotionEffectEvent.Action.ADDED) return;
|
||||
if (close) f.plugin.setEnabled(false);
|
||||
else { a.core.inventory.setItemInOffHand(null); f.changed(a); }
|
||||
}
|
||||
}
|
||||
f.dispatcher.register(new Invalidate(), f.plugin); pulse(f);
|
||||
assertNull(effects.current(PotionEffectType.SPEED), "Post-mutation context invalidation requires proved-layer cleanup, not an ordinary-holder grant");
|
||||
}
|
||||
}
|
||||
@Test void acceptedSameSignatureForeignMutationNestedBeforeTheObserverIsNotMistakenForACancelledRoadRefresh() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var foreign = effects.effects.get(PotionEffectType.SPEED);
|
||||
class Replace implements org.bukkit.event.Listener {
|
||||
boolean fired; boolean nested;
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.HIGHEST)
|
||||
public void replace(EntityPotionEffectEvent event) {
|
||||
if (event.getEntity() != a.player || event.getAction() != EntityPotionEffectEvent.Action.CHANGED) return;
|
||||
if (nested) { event.setOverride(true); return; }
|
||||
if (fired) return; fired = true; event.setCancelled(true); nested = true;
|
||||
try { assertTrue(effects.add(new org.bukkit.potion.PotionEffect(PotionEffectType.SPEED, 20, 0, false, false, true))); }
|
||||
finally { nested = false; }
|
||||
}
|
||||
}
|
||||
f.dispatcher.register(new Replace(), f.plugin); pulse(f);
|
||||
a.core.location.setY(65); pulse(f);
|
||||
assertSame(foreign, effects.effects.get(PotionEffectType.SPEED), "Final cancellation and identical native fields do not hide a separately accepted nested foreign mutation");
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest @ValueSource(strings = {"cancelled", "thrown", "native_tick_phase"})
|
||||
void refusedApplicationNeverAcquiresOwnershipOrPublishesSuccess(String refusal) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a);
|
||||
if (refusal.equals("native_tick_phase")) effects.ticking(true);
|
||||
else if (refusal.equals("thrown")) doThrow(new IllegalStateException("Controlled native admission failure")).when(a.player)
|
||||
.addPotionEffect(org.mockito.ArgumentMatchers.any(org.bukkit.potion.PotionEffect.class), org.mockito.ArgumentMatchers.anyBoolean());
|
||||
else {
|
||||
class Veto implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.HIGHEST)
|
||||
public void veto(EntityPotionEffectEvent event) { if (event.getEntity() == a.player) event.setCancelled(true); }
|
||||
}
|
||||
f.dispatcher.register(new Veto(), f.plugin);
|
||||
}
|
||||
pulse(f); pulse(f);
|
||||
assertNull(effects.current(PotionEffectType.SPEED)); assertTrue(effects.deferred.isEmpty());
|
||||
var road = (games.dmg.fantasystick.passive.PathSpeed) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeed");
|
||||
assertFalse(road.hasRoadLease(a.player));
|
||||
effects.ticking(false); f.plugin.setEnabled(false);
|
||||
((java.util.concurrent.CompletionStage<?>) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "pathSpeedAuditDrain")).toCompletableFuture().get(5, java.util.concurrent.TimeUnit.SECONDS);
|
||||
assertTrue(roadEvents(data).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test void partialRoadRegistrationClosesAllInstalledTimersAndNeverExposesTheRecipe() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.failRegistrationAt = "PathSpeed"; assertThrows(IllegalStateException.class, () -> f.plugin.setEnabled(true));
|
||||
assertFalse(f.recipes.containsKey(games.dmg.fantasystick.items.CharacterSheets.RECIPE));
|
||||
f.timers.forEach(timer -> verify(timer).cancel());
|
||||
}
|
||||
}
|
||||
@Test void boundedSessionTraversalRotatesFairlyAndDiscardsRetiredSessionIdentities() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var actors = new java.util.ArrayList<FantasyStickLifecycleNativeTest.Actor>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
var a = new FantasyStickLifecycleNativeTest.Actor(data); f.players.put(a.core.id, a.player); f.activate(a); actors.add(a);
|
||||
}
|
||||
var sessions = (games.dmg.fantasystick.session.EquipmentSessions) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "sessions");
|
||||
var seen = new java.util.HashSet<java.util.UUID>();
|
||||
for (int turn = 0; turn < 3; turn++) { var batch = sessions.rotateActiveCharacters(2); assertTrue(batch.size() <= 2); batch.forEach(v -> seen.add(v.session().player())); }
|
||||
assertEquals(5, seen.size()); var retired = sessions.active(actors.getFirst().core.id).orElseThrow();
|
||||
actors.getFirst().core.inventory.setItemInOffHand(null); f.changed(actors.getFirst());
|
||||
for (int turn = 0; turn < 3; turn++) assertTrue(sessions.rotateActiveCharacters(2).stream().noneMatch(v -> v.session().equals(retired)));
|
||||
assertThrows(IllegalArgumentException.class, () -> sessions.rotateActiveCharacters(0));
|
||||
assertThrows(IllegalArgumentException.class, () -> sessions.rotateActiveCharacters(257));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,370 @@
|
||||
package games.dmg.fantasystick;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class PathSpeedNativeTest {
|
||||
@TempDir Path data;
|
||||
@BeforeAll static void bootstrap() throws Exception { NativeRuntime.bootstrap(); }
|
||||
|
||||
static void pulse(FantasyStickLifecycleNativeTest.Fixture f) {
|
||||
for (var task : f.pulses) if (task.getClass().getName().startsWith("games.dmg.fantasystick.passive.PathSpeed")) task.run();
|
||||
}
|
||||
static void support(FantasyStickLifecycleNativeTest.Actor actor) {
|
||||
actor.core.location.setX(0.5); actor.core.location.setY(64.9375); actor.core.location.setZ(0.5);
|
||||
doReturn(true).when(actor.player).isOnGround();
|
||||
doReturn(false).when(actor.player).isSwimming(); doReturn(false).when(actor.player).isFlying();
|
||||
doReturn(false).when(actor.player).isGliding();
|
||||
var level = actor.nativePlayer.level();
|
||||
doReturn(Blocks.DIRT_PATH.defaultBlockState()).when(level).getBlockStateIfLoaded(any(BlockPos.class));
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(strings = {"jump", "jump_takeoff", "native_dead", "swim", "fly", "glide", "mount", "full_height", "airborne_path", "replaced", "unloaded", "inactive"})
|
||||
void excludedStatesAndStationaryTerrainChangesRemoveOnlyTheOwnedRoadLayer(String state) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
assertNotNull(effects.current(PotionEffectType.SPEED));
|
||||
switch (state) {
|
||||
case "jump" -> doReturn(false).when(a.player).isOnGround();
|
||||
case "jump_takeoff" -> doReturn(new org.bukkit.util.Vector(0, 0.42, 0)).when(a.player).getVelocity();
|
||||
case "native_dead" -> a.core.health = 0;
|
||||
case "swim" -> doReturn(true).when(a.player).isSwimming();
|
||||
case "fly" -> doReturn(true).when(a.player).isFlying();
|
||||
case "glide" -> doReturn(true).when(a.player).isGliding();
|
||||
case "mount" -> doReturn(true).when(a.player).isInsideVehicle();
|
||||
case "full_height" -> a.core.location.setY(65);
|
||||
case "airborne_path" -> a.core.location.setY(66);
|
||||
case "replaced", "unloaded" -> {
|
||||
var level = a.nativePlayer.level();
|
||||
doReturn(state.equals("unloaded") ? null : Blocks.DIRT.defaultBlockState()).when(level).getBlockStateIfLoaded(any(BlockPos.class));
|
||||
}
|
||||
case "inactive" -> { a.core.inventory.setItemInOffHand(null); f.changed(a); }
|
||||
default -> throw new AssertionError(state);
|
||||
}
|
||||
pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
|
||||
@Test void cancelledCleanupRetainsIdentityAndRetriesWithoutRenewingIneligibleSpeed() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var original = effects.effects.get(PotionEffectType.SPEED);
|
||||
effects.lateCancelRemoval = true; a.core.location.setY(65); pulse(f); pulse(f);
|
||||
assertSame(original, effects.effects.get(PotionEffectType.SPEED)); assertEquals(20, original.getDuration());
|
||||
effects.lateCancelRemoval = false; pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
|
||||
@Test void foreignRemovalCancelledAfterRoadObserverRetainsTheRoadLeaseAndRenewalAuthority() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var original = effects.effects.get(PotionEffectType.SPEED); effects.lateCancelRemoval = true;
|
||||
a.player.removePotionEffect(PotionEffectType.SPEED); assertSame(original, effects.effects.get(PotionEffectType.SPEED));
|
||||
original.tickClient(); a.nativePlayer.tickCount++; pulse(f);
|
||||
assertEquals(20, effects.current(PotionEffectType.SPEED).getDuration(), "A finally cancelled foreign removal cannot discard current road ownership");
|
||||
effects.lateCancelRemoval = false; a.core.location.setY(65); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
|
||||
@Test void learnedSpeedTakingOverRoadSpeedRemainsAfterLeavingRoad() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
// Completed passive acquisition prerequisite, using the existing strict saved-record fixture.
|
||||
SpeedINativeTest.withDex(data, a, java.util.List.of("", "", ""));
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
assertNotNull(effects.current(PotionEffectType.SPEED));
|
||||
// Learn through the supported native book route; roads themselves spend nothing.
|
||||
PartyBookNativeTest.open(f, a);
|
||||
PartyBookNativeTest.click(f, a, SpeedINativeTest.action(a, "[Learn]", "speed_i"));
|
||||
PartyBookNativeTest.drain(f); PartyBookNativeTest.drain(f);
|
||||
((games.dmg.fantasystick.passive.SpeedI) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "speedI")).sweep();
|
||||
a.core.location.setY(65); pulse(f);
|
||||
var speed = effects.current(PotionEffectType.SPEED);
|
||||
assertNotNull(speed, "Leaving the road cannot remove the other applicable learned Speed I layer");
|
||||
assertTrue(speed.isInfinite());
|
||||
}
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||
void realRallyingCryAndRoadSourcesPreserveTheSurvivorInBothActivationOrders(boolean rallyFirst) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
RallyingCryNativeTest.prepareCaster(data, a, true);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
org.mockito.Mockito.doReturn(java.util.List.of()).when(a.player).getNearbyEntities(
|
||||
org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble());
|
||||
f.players.put(a.core.id, a.player); f.activate(a);
|
||||
if (!rallyFirst) pulse(f);
|
||||
RallyingCryNativeTest.use(f, a); PartyBookNativeTest.drain(f); PartyBookNativeTest.drain(f);
|
||||
if (rallyFirst) pulse(f);
|
||||
assertNotNull(effects.current(PotionEffectType.SPEED));
|
||||
assertTrue(effects.current(PotionEffectType.SPEED).isInfinite(), "Rally keeps its native persistent policy rather than borrowing an expiring road layer");
|
||||
a.core.location.setY(65); pulse(f); assertNotNull(effects.current(PotionEffectType.SPEED));
|
||||
assertTrue(effects.current(PotionEffectType.SPEED).isInfinite());
|
||||
a.core.location.setY(64.9375);
|
||||
f.delayed.getLast().run(); pulse(f);
|
||||
assertNotNull(effects.current(PotionEffectType.SPEED));
|
||||
assertFalse(effects.current(PotionEffectType.SPEED).isInfinite());
|
||||
assertEquals(20, effects.current(PotionEffectType.SPEED).getDuration());
|
||||
}
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(ints = {1, 20, 200})
|
||||
void genuineNativeTickExpiryKeepsOneLogicalApplicationAcrossContinuousRoadLeases(int lease) throws Exception {
|
||||
java.nio.file.Files.writeString(data.resolve("config.yml"), "path-speed-lease-ticks: " + lease + "\n");
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
for (int tick = 0; tick < 25; tick++) {
|
||||
var effect = effects.effects.get(PotionEffectType.SPEED); assertNotNull(effect); a.nativePlayer.tickCount++;
|
||||
if (!effect.tickServer(a.nativePlayer.level(), a.nativePlayer, () -> {})) {
|
||||
var event = new org.bukkit.event.entity.EntityPotionEffectEvent(a.player, effects.current(PotionEffectType.SPEED), null, null,
|
||||
org.bukkit.event.entity.EntityPotionEffectEvent.Cause.EXPIRATION, org.bukkit.event.entity.EntityPotionEffectEvent.Action.REMOVED, false);
|
||||
f.dispatcher.accept(event); assertFalse(event.isCancelled()); effects.effects.remove(PotionEffectType.SPEED);
|
||||
}
|
||||
pulse(f); assertEquals(lease, effects.current(PotionEffectType.SPEED).getDuration());
|
||||
}
|
||||
f.plugin.setEnabled(false);
|
||||
var rows = roadEvents(data);
|
||||
assertEquals(2, rows.size(), "Continuous native one-tick renewals are one logical start/end, not per-tick business spam");
|
||||
assertEquals(rows.getFirst().getAsJsonObject("data").get("application_id"), rows.getLast().getAsJsonObject("data").get("application_id"));
|
||||
}
|
||||
}
|
||||
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(ints = {0, 1})
|
||||
void existingEqualOrStrongerForeignSpeedAndOrdinaryInactiveHoldersAreUntouched(int tier) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
assertTrue(effects.add(new org.bukkit.potion.PotionEffect(PotionEffectType.SPEED, 200, tier)));
|
||||
var foreign = effects.effects.get(PotionEffectType.SPEED); f.activate(a); pulse(f);
|
||||
assertSame(foreign, effects.effects.get(PotionEffectType.SPEED));
|
||||
a.core.location.setY(65); pulse(f); assertSame(foreign, effects.effects.get(PotionEffectType.SPEED));
|
||||
assertEquals(200, foreign.getDuration()); assertTrue(roadEvents(data).isEmpty());
|
||||
}
|
||||
}
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(strings = {"extended", "stronger_hidden", "identical_replacement"})
|
||||
void inPlaceAndIdenticalForeignLayersIncludingHiddenNativeChainsArePreserved(String change) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var original = effects.effects.get(PotionEffectType.SPEED);
|
||||
if (change.equals("identical_replacement")) effects.effects.put(PotionEffectType.SPEED, new net.minecraft.world.effect.MobEffectInstance(original));
|
||||
else assertTrue(effects.add(new org.bukkit.potion.PotionEffect(PotionEffectType.SPEED,
|
||||
change.equals("extended") ? 40 : 10, change.equals("extended") ? 0 : 1, false, false, true)));
|
||||
var foreign = effects.effects.get(PotionEffectType.SPEED); var hidden = foreign.hiddenEffect;
|
||||
if (change.equals("stronger_hidden")) assertNotNull(hidden);
|
||||
else if (!change.equals("identical_replacement")) assertSame(original, foreign, "Native update mutates the same instance; identity alone is not ownership");
|
||||
pulse(f); a.core.location.setY(65); pulse(f);
|
||||
assertSame(foreign, effects.effects.get(PotionEffectType.SPEED)); assertSame(hidden, foreign.hiddenEffect);
|
||||
assertEquals(change.equals("extended") ? 40 : change.equals("stronger_hidden") ? 10 : 20, foreign.getDuration());
|
||||
}
|
||||
}
|
||||
@Test void refusedForeignNoOpDoesNotDiscardOwnershipAndUnsafeNativePhaseDefersCleanup() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
assertFalse(effects.add(new org.bukkit.potion.PotionEffect(PotionEffectType.SPEED, 20, 0, false, false, true)));
|
||||
var original = effects.effects.get(PotionEffectType.SPEED); original.tickClient(); a.nativePlayer.tickCount++; pulse(f);
|
||||
assertEquals(20, original.getDuration());
|
||||
a.core.location.setY(65); effects.ticking(true); int before = effects.decisions.size(); pulse(f);
|
||||
assertSame(original, effects.effects.get(PotionEffectType.SPEED)); assertEquals(before, effects.decisions.size()); assertTrue(effects.deferred.isEmpty());
|
||||
effects.ticking(false); effects.failRemovalAfterDecision = true; pulse(f);
|
||||
assertSame(original, effects.effects.get(PotionEffectType.SPEED));
|
||||
effects.failRemovalAfterDecision = false; pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||
void actualDownedContainmentRetainsFiniteCleanupAndFinalDeathOrPhoenixRescueReconcilesIt(boolean rescue) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var sessions = (games.dmg.fantasystick.session.EquipmentSessions) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "sessions");
|
||||
var active = sessions.active(a.core.id).orElseThrow(); var original = effects.effects.get(PotionEffectType.SPEED);
|
||||
if (rescue) {
|
||||
var inventory = (games.dmg.fantasystick.shop.RareInventoryDirectory) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "rareInventory");
|
||||
inventory.add(active.character(), games.dmg.fantasystick.shop.RareProduct.PHOENIX_DOWN, java.util.UUID.randomUUID()).join();
|
||||
}
|
||||
PassivePotionCleanupNativeTest.down(f, a); pulse(f); pulse(f);
|
||||
assertSame(original, effects.effects.get(PotionEffectType.SPEED)); assertFalse(effects.current(PotionEffectType.SPEED).isInfinite());
|
||||
assertTrue(effects.decisions.stream().anyMatch(event -> event.getAction() == org.bukkit.event.entity.EntityPotionEffectEvent.Action.REMOVED && event.isCancelled()));
|
||||
if (rescue) {
|
||||
PassivePotionCleanupNativeTest.clickMenu(f, a, 13); ReskillEventsNativeTest.await(f, () -> sessions.current(active)); pulse(f);
|
||||
assertSame(original, effects.effects.get(PotionEffectType.SPEED));
|
||||
a.core.location.setY(65); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
} else { PassivePotionCleanupNativeTest.acceptDeath(f, a); pulse(f); assertNull(effects.current(PotionEffectType.SPEED)); }
|
||||
}
|
||||
}
|
||||
@org.junit.jupiter.params.ParameterizedTest
|
||||
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||
void finallyCancelledMoveOrTeleportNeverGrantsAHypotheticalPathDestination(boolean teleport) throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a); a.core.location.setY(65);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
class Veto implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
|
||||
public void veto(org.bukkit.event.player.PlayerMoveEvent event) {
|
||||
if (event.getPlayer() == a.player) { event.setCancelled(true); pulse(f); }
|
||||
}
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
|
||||
public void teleportVeto(org.bukkit.event.player.PlayerTeleportEvent event) { veto(event); }
|
||||
}
|
||||
f.dispatcher.register(new Veto(), f.plugin); var from = a.player.getLocation(); var to = from.clone(); to.setY(64.9375);
|
||||
org.bukkit.event.player.PlayerMoveEvent event = teleport ? new org.bukkit.event.player.PlayerTeleportEvent(a.player, from, to,
|
||||
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.PLUGIN) : new org.bukkit.event.player.PlayerMoveEvent(a.player, from, to);
|
||||
f.dispatcher.accept(event); assertTrue(event.isCancelled()); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
// Accepted continuation changes actual position; event proposals alone never do.
|
||||
a.core.location.setY(64.9375); pulse(f); assertNotNull(effects.current(PotionEffectType.SPEED));
|
||||
a.core.location.setY(65); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
}
|
||||
}
|
||||
|
||||
@Test void cancelledNativeExpiryDuringDowningRetainsCleanupResponsibilityThroughFinalDeath() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
var original = effects.effects.get(PotionEffectType.SPEED); PassivePotionCleanupNativeTest.down(f, a);
|
||||
for (int tick = 0; tick < 20; tick++) {
|
||||
a.nativePlayer.tickCount++;
|
||||
if (!original.tickServer(a.nativePlayer.level(), a.nativePlayer, () -> {})) {
|
||||
var event = new org.bukkit.event.entity.EntityPotionEffectEvent(a.player, effects.current(PotionEffectType.SPEED), null, null,
|
||||
org.bukkit.event.entity.EntityPotionEffectEvent.Cause.EXPIRATION, org.bukkit.event.entity.EntityPotionEffectEvent.Action.REMOVED, false);
|
||||
f.dispatcher.accept(event); assertTrue(event.isCancelled());
|
||||
}
|
||||
}
|
||||
assertEquals(0, original.getDuration()); pulse(f); assertSame(original, effects.effects.get(PotionEffectType.SPEED));
|
||||
PassivePotionCleanupNativeTest.acceptDeath(f, a); pulse(f);
|
||||
assertNull(effects.current(PotionEffectType.SPEED), "A finally refused native expiry does not erase the road cleanup lease");
|
||||
}
|
||||
}
|
||||
|
||||
@Test void reentrantSessionExitDuringRoadHandoffCannotPublishAnInfinitePassiveOnTheFormerHolder() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
SpeedINativeTest.withDex(data, a, java.util.List.of("", "", ""));
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
PartyBookNativeTest.open(f, a); PartyBookNativeTest.click(f, a, SpeedINativeTest.action(a, "[Learn]", "speed_i"));
|
||||
PartyBookNativeTest.drain(f); PartyBookNativeTest.drain(f);
|
||||
class Exit implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
|
||||
public void exit(org.bukkit.event.entity.EntityPotionEffectEvent event) {
|
||||
if (event.getEntity() == a.player && event.getAction() == org.bukkit.event.entity.EntityPotionEffectEvent.Action.REMOVED) {
|
||||
a.core.inventory.setItemInOffHand(null); f.changed(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
f.dispatcher.register(new Exit(), f.plugin);
|
||||
((games.dmg.fantasystick.passive.SpeedI) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "speedI")).sweep();
|
||||
assertNull(effects.current(PotionEffectType.SPEED), "Handoff native callbacks must not grant persistent Speed after current-session authority disappears");
|
||||
}
|
||||
}
|
||||
|
||||
@Test void reentrantSessionExitDuringRoadRallyHandoffCannotPublishAnInfiniteSpeedLayer() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
RallyingCryNativeTest.prepareCaster(data, a, true);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
org.mockito.Mockito.doReturn(java.util.List.of()).when(a.player).getNearbyEntities(
|
||||
org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble(), org.mockito.ArgumentMatchers.anyDouble());
|
||||
f.players.put(a.core.id, a.player); f.activate(a); pulse(f);
|
||||
class Exit implements org.bukkit.event.Listener {
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
|
||||
public void exit(org.bukkit.event.entity.EntityPotionEffectEvent event) {
|
||||
if (event.getEntity() == a.player && event.getAction() == org.bukkit.event.entity.EntityPotionEffectEvent.Action.REMOVED) {
|
||||
a.core.inventory.setItemInOffHand(null); f.changed(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
f.dispatcher.register(new Exit(), f.plugin); RallyingCryNativeTest.use(f, a);
|
||||
PartyBookNativeTest.drain(f); PartyBookNativeTest.drain(f);
|
||||
assertNull(effects.current(PotionEffectType.SPEED), "Rally handoff cannot publish persistent Speed on a former source holder");
|
||||
}
|
||||
}
|
||||
|
||||
@Test void actualBookAndJsonlExplainAndRecordTheRoadJourneyWithoutRefreshSpam() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true); var a = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var effects = new PassivePotionCleanupNativeTest.NativePort(f, a); support(a);
|
||||
f.players.put(a.core.id, a.player); f.activate(a);
|
||||
PartyBookNativeTest.open(f, a);
|
||||
assertTrue(PartyBookNativeTest.text(a).contains("Dirt Path travel"), "The real character book teaches the automatic road benefit");
|
||||
pulse(f);
|
||||
for (int i = 0; i < 50; i++) { effects.effects.get(PotionEffectType.SPEED).tickClient(); a.nativePlayer.tickCount++; pulse(f); }
|
||||
var storage = (games.dmg.fantasystick.persistence.CharacterStorage) FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "characters");
|
||||
var record = storage.find(a.core.record.id()).get().orElseThrow();
|
||||
assertEquals(a.core.record.unspentPoints(), record.unspentPoints()); assertEquals(a.core.record.passives(), record.passives());
|
||||
a.core.location.setY(65); pulse(f); assertNull(effects.current(PotionEffectType.SPEED));
|
||||
ReskillEventsNativeTest.await(f, () -> roadEvents(data).size() == 2);
|
||||
var rows = roadEvents(data); assertEquals(2, rows.size());
|
||||
assertEquals(games.dmg.fantasystick.events.LocalEventLog.TYPE_PREFIX + "effect.applied", rows.getFirst().get("type").getAsString());
|
||||
assertEquals(games.dmg.fantasystick.events.LocalEventLog.TYPE_PREFIX + "effect.ended", rows.getLast().get("type").getAsString());
|
||||
var start = rows.getFirst().getAsJsonObject("data"); var end = rows.getLast().getAsJsonObject("data");
|
||||
assertEquals(start.get("application_id"), end.get("application_id"));
|
||||
for (var row : rows) {
|
||||
var values = row.getAsJsonObject("data");
|
||||
assertEquals(a.core.id.toString(), values.get("player_id").getAsString());
|
||||
assertEquals(record.id().toString(), values.get("character_id").getAsString());
|
||||
assertTrue(values.has("session_id")); assertTrue(values.has("location")); assertFalse(values.has("passive_id"));
|
||||
assertEquals(0, values.get("amplifier").getAsInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
static java.util.List<com.google.gson.JsonObject> roadEvents(Path directory) {
|
||||
try { return ReskillEventsNativeTest.records(directory).stream().filter(row -> {
|
||||
var values = row.getAsJsonObject("data"); return values.has("feature_id") && values.get("feature_id").getAsString().equals("dirt_path_speed");
|
||||
}).toList(); } catch (Exception failure) { throw new IllegalStateException(failure); }
|
||||
}
|
||||
|
||||
@Test void registeredRoadSweepGrantsFiniteSpeedToAnOrdinaryActiveCharacterOnNativeLoweredPath() throws Exception {
|
||||
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true);
|
||||
var actor = new FantasyStickLifecycleNativeTest.Actor(data);
|
||||
var nativeEffects = new PassivePotionCleanupNativeTest.NativePort(f, actor);
|
||||
actor.core.location.setX(0.5); actor.core.location.setY(64.9375); actor.core.location.setZ(0.5);
|
||||
doReturn(true).when(actor.player).isOnGround();
|
||||
doReturn(false).when(actor.player).isSwimming();
|
||||
doReturn(false).when(actor.player).isFlying();
|
||||
doReturn(false).when(actor.player).isGliding();
|
||||
var level = actor.nativePlayer.level();
|
||||
doReturn(Blocks.DIRT_PATH.defaultBlockState()).when(level).getBlockStateIfLoaded(any(BlockPos.class));
|
||||
f.players.put(actor.core.id, actor.player); f.activate(actor);
|
||||
// Invoke the actual installed feature timer, not an imagined domain helper.
|
||||
for (var pulse : f.pulses) {
|
||||
if (pulse.getClass().getName().startsWith("games.dmg.fantasystick.passive.PathSpeed")) pulse.run();
|
||||
}
|
||||
var speed = nativeEffects.current(PotionEffectType.SPEED);
|
||||
assertNotNull(speed, "A genuine active character supported by a loaded native Dirt Path receives road Speed I");
|
||||
assertEquals(0, speed.getAmplifier()); assertEquals(20, speed.getDuration()); assertFalse(speed.isInfinite());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,7 +304,7 @@ class RallyingCryNativeTest {
|
||||
.withCausingEntity(attacker).withDirectEntity(attacker).build();
|
||||
return new EntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, source, amount);
|
||||
}
|
||||
private static void use(FantasyStickLifecycleNativeTest.Fixture fixture, FantasyStickLifecycleNativeTest.Actor actor) {
|
||||
static void use(FantasyStickLifecycleNativeTest.Fixture fixture, FantasyStickLifecycleNativeTest.Actor actor) {
|
||||
actor.core.inventory.getInventory().setSelectedSlot(2);
|
||||
fixture.dispatcher.accept(new PlayerInteractEvent(actor.player, org.bukkit.event.block.Action.RIGHT_CLICK_AIR,
|
||||
actor.core.inventory.getItem(2), null, org.bukkit.block.BlockFace.SELF, EquipmentSlot.HAND));
|
||||
@@ -333,7 +333,7 @@ class RallyingCryNativeTest {
|
||||
&& payload.value().contains(":" + ability)) return custom;
|
||||
for (var child : component.getSiblings()) { var found = button(child, label, ability); if (found != null) return found; } return null;
|
||||
}
|
||||
private static void prepareCaster(Path directory, FantasyStickLifecycleNativeTest.Actor actor, boolean learned) throws Exception {
|
||||
static void prepareCaster(Path directory, FantasyStickLifecycleNativeTest.Actor actor, boolean learned) throws Exception {
|
||||
java.nio.file.Files.createDirectories(directory); var repository = new YamlCharacterRepository(directory);
|
||||
var old = repository.load(actor.core.record.id()).orElseThrow(); var stats = new EnumMap<>(old.stats());
|
||||
stats.put(Stat.CHR, BigInteger.valueOf(16)); stats.put(Stat.CON, BigInteger.valueOf(12));
|
||||
|
||||
Reference in new issue
Block a user