From 7d4fe97f3cf9f95b1732d2f5bb5937f080e5d558 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD Date: Tue, 12 May 2026 21:24:27 -0500 Subject: [PATCH 1/2] test fixes and improvements --- .../pylonmc/rebar/block/BlockListener.kt | 2 +- .../pylonmc/rebar/config/RebarConfig.kt | 6 ++++++ .../pylonmc/rebar/entity/EntityListener.kt | 6 +++--- .../rebar/entity/base/RebarTickingEntity.kt | 2 +- .../github/pylonmc/rebar/gametest/GameTest.kt | 1 + .../pylonmc/rebar/gametest/GameTestConfig.kt | 11 +++++++++- rebar/src/main/resources/config.yml | 3 +++ .../github/pylonmc/rebar/test/RebarTest.java | 19 +++++++++-------- .../github/pylonmc/rebar/test/base/Test.java | 5 +++++ .../block/{Blocks.java => TestBlocks.java} | 4 ++-- .../test/block/TestRebarSimpleMultiblock.java | 4 ++-- .../rebar/test/block/TickingErrorBlock.java | 1 + .../rebar/test/block/fluid/FluidConsumer.java | 6 +++--- .../rebar/test/block/fluid/FluidProducer.java | 6 +++--- .../rebar/test/entity/EntityEventError.java | 6 ++++-- .../{Entities.java => TestEntities.java} | 4 ++-- .../fluid/{Fluids.java => TestFluids.java} | 2 +- .../test/item/{Items.java => TestItems.java} | 8 +++++-- .../test/test/block/BlockEventErrorTest.java | 5 +++++ .../test/test/block/BlockStorageAddTest.java | 6 ++++-- .../block/BlockStorageFilledChunkTest.java | 9 ++++---- .../test/block/BlockStorageRemoveTest.java | 4 ++-- .../block/SimpleMultiblockRotatedTest.java | 21 +++++++++---------- .../test/test/block/SimpleMultiblockTest.java | 13 +++++------- .../test/block/TickingBlockErrorTest.java | 6 ++++++ .../test/test/block/TickingBlockTest.java | 2 ++ .../test/entity/EntityEventErrorTest.java | 6 ++++-- .../entity/EntityStorageChunkReloadTest.java | 2 ++ .../EntityStorageUnregisteredEntityTest.java | 1 + .../test/test/fluid/FluidConnectionTest.java | 3 +-- .../fluid/FluidCyclicConnectionsTest.java | 3 +-- .../test/test/fluid/FluidFlowRateTest.java | 3 +-- .../test/fluid/FluidPartialReloadTest.java | 11 +++------- .../test/test/fluid/FluidPredicateTest.java | 3 +-- .../test/test/fluid/FluidTickerTest.java | 3 +-- .../fluid/FluidTickerTestWithMixedFluids.java | 3 +-- .../item/RebarItemStackInterfaceTest.java | 5 ++--- .../rebar/test/test/recipe/CraftingTest.java | 4 ++-- .../rebar/test/test/recipe/FurnaceTest.java | 4 ++-- .../pylonmc/rebar/test/util/TestUtil.java | 12 +++++++++-- 40 files changed, 134 insertions(+), 91 deletions(-) rename test/src/main/java/io/github/pylonmc/rebar/test/block/{Blocks.java => TestBlocks.java} (96%) rename test/src/main/java/io/github/pylonmc/rebar/test/entity/{Entities.java => TestEntities.java} (85%) rename test/src/main/java/io/github/pylonmc/rebar/test/fluid/{Fluids.java => TestFluids.java} (95%) rename test/src/main/java/io/github/pylonmc/rebar/test/item/{Items.java => TestItems.java} (66%) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt index 0add561af..1f9d11436 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt @@ -384,7 +384,7 @@ internal object BlockListener : MultiListener { } else { Rebar.logger.severe("Error when handling block(${block.key}, ${block.block.location}) ticking: ${e.localizedMessage}") } - e.printStackTrace() + if (RebarConfig.FULL_ERROR_STACK_TRACES) e.printStackTrace() blockErrMap[block] = blockErrMap[block]?.plus(1) ?: 1 if (blockErrMap[block]!! > RebarConfig.ALLOWED_BLOCK_ERRORS) { BlockStorage.makePhantom(block) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/RebarConfig.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/RebarConfig.kt index d69e4f20f..0ac43c4f6 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/RebarConfig.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/RebarConfig.kt @@ -24,6 +24,12 @@ object RebarConfig { @JvmField val ALLOWED_ENTITY_ERRORS = config.getOrThrow("allowed-entity-errors", ConfigAdapter.INTEGER) + /** + * Mutable so that they can be disabled/enabled live for things like tests, etc. + */ + @JvmField + var FULL_ERROR_STACK_TRACES = config.getOrThrow("full-error-stack-traces", ConfigAdapter.BOOLEAN) + @JvmField val FLUID_TICK_INTERVAL = config.getOrThrow("fluid-tick-interval", ConfigAdapter.INTEGER) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityListener.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityListener.kt index bb2ab7a9e..4ed677bc8 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityListener.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityListener.kt @@ -14,7 +14,7 @@ internal object EntityListener : MultiListener { @JvmSynthetic internal fun logEventHandleErr(event: Event, e: Exception, entity: RebarEntity<*>) { Rebar.logger.severe("Error when handling entity(${entity.key}, ${entity.uuid}, ${entity.entity.location}) event handler ${event.javaClass.simpleName}: ${e.localizedMessage}") - e.printStackTrace() + if (RebarConfig.FULL_ERROR_STACK_TRACES) e.printStackTrace() entityErrMap[entity.uuid] = entityErrMap[entity.uuid]?.plus(1) ?: 1 if (entityErrMap[entity.uuid]!! > RebarConfig.ALLOWED_ENTITY_ERRORS) { entity.entity.remove() @@ -22,9 +22,9 @@ internal object EntityListener : MultiListener { } @JvmSynthetic - internal fun logEventHandleErrTicking(e: Exception, entity: RebarEntity<*>) { + internal fun logTickingErr(e: Exception, entity: RebarEntity<*>) { Rebar.logger.severe("Error when handling ticking entity(${entity.key}, ${entity.uuid}, ${entity.entity.location}): ${e.localizedMessage}") - e.printStackTrace() + if (RebarConfig.FULL_ERROR_STACK_TRACES) e.printStackTrace() entityErrMap[entity.uuid] = entityErrMap[entity.uuid]?.plus(1) ?: 1 if (entityErrMap[entity.uuid]!! > RebarConfig.ALLOWED_ENTITY_ERRORS) { entity.entity.remove() diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt index dc54c562c..a246cda10 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt @@ -132,7 +132,7 @@ interface RebarTickingEntity { tickingEntity.tick() } catch (e: Exception) { withContext(Rebar.mainThreadDispatcher) { - EntityListener.logEventHandleErrTicking(e, tickingEntity as RebarEntity<*>) + EntityListener.logTickingErr(e, tickingEntity as RebarEntity<*>) } } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTest.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTest.kt index 0f07cf8b1..e200350d9 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTest.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTest.kt @@ -127,6 +127,7 @@ class GameTest( } catch (e: Throwable) { result = GameTestFailException(gameTest, "An exception occurred", e) } + gameTest.config.cleanup.accept(gameTest) for (entity in gameTest.world.getNearbyEntities(gameTest.boundingBox)) { if (entity !is Player) { entity.remove() diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTestConfig.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTestConfig.kt index a29549a39..8cfe9f40a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTestConfig.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/gametest/GameTestConfig.kt @@ -19,6 +19,7 @@ class GameTestConfig( private val key: NamespacedKey, val size: Int, val setUp: Consumer, + val cleanup: Consumer, val delayTicks: Long, val timeoutTicks: Long, val positionOverride: BlockPosition? @@ -31,6 +32,7 @@ class GameTestConfig( class Builder(val key: NamespacedKey) { private var size by Delegates.notNull() private var setUp: Consumer = Consumer {} + private var cleanup: Consumer = Consumer {} private var delayTicks = 0L private var timeoutTicks = 5L * 60 * 20 private var positionOverride: BlockPosition? = null @@ -47,6 +49,13 @@ class GameTestConfig( */ fun setUp(setUp: Consumer): Builder = apply { this.setUp = setUp } + /** + * Runs after test ends + */ + fun cleanup(cleanup: Consumer): Builder = apply { + this.cleanup = cleanup + } + /** * Delay in ticks before the test starts. Defaults to 0. */ @@ -62,7 +71,7 @@ class GameTestConfig( */ fun positionOverride(position: BlockPosition): Builder = apply { this.positionOverride = position } - fun build() = GameTestConfig(key, size, setUp, delayTicks, timeoutTicks, positionOverride) + fun build() = GameTestConfig(key, size, setUp, cleanup, delayTicks, timeoutTicks, positionOverride) } /** diff --git a/rebar/src/main/resources/config.yml b/rebar/src/main/resources/config.yml index 4a9b983e5..f349be77b 100644 --- a/rebar/src/main/resources/config.yml +++ b/rebar/src/main/resources/config.yml @@ -11,6 +11,9 @@ allowed-block-errors: 5 # The number of errors a entity can throw before it is disabled allowed-entity-errors: 5 +# When a block or entity errors, should the full error stack trace be printed in the console or just the error message & context? +full-error-stack-traces: true + # The interval (in Minecraft ticks) between fluid network ticks fluid-tick-interval: 5 diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/RebarTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/RebarTest.java index e143c89e8..81aa9caa1 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/RebarTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/RebarTest.java @@ -1,12 +1,13 @@ package io.github.pylonmc.rebar.test; import io.github.pylonmc.rebar.addon.RebarAddon; +import io.github.pylonmc.rebar.config.RebarConfig; import io.github.pylonmc.rebar.test.base.Test; import io.github.pylonmc.rebar.test.base.TestResult; -import io.github.pylonmc.rebar.test.block.Blocks; -import io.github.pylonmc.rebar.test.entity.Entities; -import io.github.pylonmc.rebar.test.fluid.Fluids; -import io.github.pylonmc.rebar.test.item.Items; +import io.github.pylonmc.rebar.test.block.TestBlocks; +import io.github.pylonmc.rebar.test.entity.TestEntities; +import io.github.pylonmc.rebar.test.fluid.TestFluids; +import io.github.pylonmc.rebar.test.item.TestItems; import io.github.pylonmc.rebar.test.test.block.*; import io.github.pylonmc.rebar.test.test.entity.EntityEventErrorTest; import io.github.pylonmc.rebar.test.test.entity.EntityStorageChunkReloadTest; @@ -112,10 +113,10 @@ private static void run() { try { // TODO get rid of these and convert registration to static blocks - Blocks.register(); - Items.register(); - Entities.register(); - Fluids.register(); + TestBlocks.register(); + TestItems.register(); + TestEntities.register(); + TestFluids.register(); } catch (Exception e) { instance().getLogger().severe("Failed to set up tests"); e.printStackTrace(); @@ -130,7 +131,7 @@ private static void run() { List tests = TestUtil.runSync(RebarTest::initTests).join(); List results = tests.stream() - .map(Test::run) + .map(Test::start) .toList(); List succeeded = results.stream() diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/base/Test.java b/test/src/main/java/io/github/pylonmc/rebar/test/base/Test.java index dbf4f9b52..8da59d008 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/base/Test.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/base/Test.java @@ -11,6 +11,11 @@ public interface Test { + default TestResult start() { + RebarTest.instance().getLogger().log(Level.INFO, "Test %s started".formatted(getKey())); + return run(); + } + TestResult run(); default NamespacedKey getKey() { diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/block/Blocks.java b/test/src/main/java/io/github/pylonmc/rebar/test/block/TestBlocks.java similarity index 96% rename from test/src/main/java/io/github/pylonmc/rebar/test/block/Blocks.java rename to test/src/main/java/io/github/pylonmc/rebar/test/block/TestBlocks.java index 8e3b7df1f..eeb49b0c5 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/block/Blocks.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/block/TestBlocks.java @@ -10,9 +10,9 @@ import org.bukkit.NamespacedKey; -public final class Blocks { +public final class TestBlocks { - private Blocks() {} + private TestBlocks() {} public static final NamespacedKey SIMPLE_BLOCK_KEY = RebarTest.key("simple_block"); diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/block/TestRebarSimpleMultiblock.java b/test/src/main/java/io/github/pylonmc/rebar/test/block/TestRebarSimpleMultiblock.java index 06ed0d7f4..58ee51571 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/block/TestRebarSimpleMultiblock.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/block/TestRebarSimpleMultiblock.java @@ -30,8 +30,8 @@ public TestRebarSimpleMultiblock(Block block, PersistentDataContainer pdc) { @Override public @NotNull Map getComponents() { return Map.of( - new Vector3i(1, 1, 4), MultiblockComponent.of(Blocks.SIMPLE_BLOCK_KEY), - new Vector3i(2, -1, 0), MultiblockComponent.of(Blocks.SIMPLE_BLOCK_KEY) + new Vector3i(1, 1, 4), MultiblockComponent.of(TestBlocks.SIMPLE_BLOCK_KEY), + new Vector3i(2, -1, 0), MultiblockComponent.of(TestBlocks.SIMPLE_BLOCK_KEY) ); } } \ No newline at end of file diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/block/TickingErrorBlock.java b/test/src/main/java/io/github/pylonmc/rebar/test/block/TickingErrorBlock.java index 076913bd9..5e5766d63 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/block/TickingErrorBlock.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/block/TickingErrorBlock.java @@ -3,6 +3,7 @@ import io.github.pylonmc.rebar.block.RebarBlock; import io.github.pylonmc.rebar.block.base.RebarTickingBlock; import io.github.pylonmc.rebar.block.context.BlockCreateContext; +import io.github.pylonmc.rebar.config.RebarConfig; import io.github.pylonmc.rebar.test.RebarTest; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidConsumer.java b/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidConsumer.java index 42363023a..fe99d1f14 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidConsumer.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidConsumer.java @@ -11,7 +11,7 @@ import io.github.pylonmc.rebar.fluid.RebarFluid; import io.github.pylonmc.rebar.fluid.VirtualFluidPoint; import io.github.pylonmc.rebar.test.RebarTest; -import io.github.pylonmc.rebar.test.fluid.Fluids; +import io.github.pylonmc.rebar.test.fluid.TestFluids; import lombok.Getter; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; @@ -63,8 +63,8 @@ public double getAmount() { private RebarFluid getFluidType() { return Map.of( - LAVA_CONSUMER_KEY, Fluids.LAVA, - WATER_CONSUMER_KEY, Fluids.WATER + LAVA_CONSUMER_KEY, TestFluids.LAVA, + WATER_CONSUMER_KEY, TestFluids.WATER ).get(getKey()); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidProducer.java b/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidProducer.java index ccca815d9..de63e3abc 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidProducer.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/block/fluid/FluidProducer.java @@ -12,7 +12,7 @@ import io.github.pylonmc.rebar.fluid.RebarFluid; import io.github.pylonmc.rebar.fluid.VirtualFluidPoint; import io.github.pylonmc.rebar.test.RebarTest; -import io.github.pylonmc.rebar.test.fluid.Fluids; +import io.github.pylonmc.rebar.test.fluid.TestFluids; import kotlin.Pair; import lombok.Getter; import org.bukkit.NamespacedKey; @@ -72,8 +72,8 @@ public void onFluidRemoved(@NotNull RebarFluid fluid, double amount) { private RebarFluid getFluidType() { return Map.of( - LAVA_PRODUCER_KEY, Fluids.LAVA, - WATER_PRODUCER_KEY, Fluids.WATER + LAVA_PRODUCER_KEY, TestFluids.LAVA, + WATER_PRODUCER_KEY, TestFluids.WATER ).get(getKey()); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/entity/EntityEventError.java b/test/src/main/java/io/github/pylonmc/rebar/test/entity/EntityEventError.java index 0924ff395..b94b33106 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/entity/EntityEventError.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/entity/EntityEventError.java @@ -1,6 +1,7 @@ package io.github.pylonmc.rebar.test.entity; import io.github.pylonmc.rebar.entity.RebarEntity; +import io.github.pylonmc.rebar.entity.base.RebarDamageableEntity; import io.github.pylonmc.rebar.entity.base.RebarInteractEntity; import io.github.pylonmc.rebar.test.RebarTest; import org.bukkit.Location; @@ -8,11 +9,12 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Skeleton; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.jetbrains.annotations.NotNull; -public class EntityEventError extends RebarEntity implements RebarInteractEntity { +public class EntityEventError extends RebarEntity implements RebarDamageableEntity { public static final NamespacedKey KEY = RebarTest.key("entity_event_error"); @@ -26,7 +28,7 @@ public EntityEventError(@NotNull LivingEntity entity) { } @Override - public void onInteract(@NotNull PlayerInteractEntityEvent event, @NotNull EventPriority priority) { + public void onDamage(@NotNull EntityDamageEvent event, @NotNull EventPriority priority) { throw new RuntimeException("This exception is thrown as part of a test"); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/entity/Entities.java b/test/src/main/java/io/github/pylonmc/rebar/test/entity/TestEntities.java similarity index 85% rename from test/src/main/java/io/github/pylonmc/rebar/test/entity/Entities.java rename to test/src/main/java/io/github/pylonmc/rebar/test/entity/TestEntities.java index 92252e1ba..81b802f51 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/entity/Entities.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/entity/TestEntities.java @@ -4,9 +4,9 @@ import org.bukkit.entity.LivingEntity; -public final class Entities { +public final class TestEntities { - private Entities() {} + private TestEntities() {} public static void register() { RebarEntity.register(SimpleEntity.KEY, LivingEntity.class, SimpleEntity.class); diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/fluid/Fluids.java b/test/src/main/java/io/github/pylonmc/rebar/test/fluid/TestFluids.java similarity index 95% rename from test/src/main/java/io/github/pylonmc/rebar/test/fluid/Fluids.java rename to test/src/main/java/io/github/pylonmc/rebar/test/fluid/TestFluids.java index 6262c0984..838eaf004 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/fluid/Fluids.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/fluid/TestFluids.java @@ -5,7 +5,7 @@ import org.bukkit.Material; -public class Fluids { +public class TestFluids { public static final RebarFluid WATER = new RebarFluid(RebarTest.key("water"), Material.CYAN_CONCRETE); public static final RebarFluid LAVA = new RebarFluid(RebarTest.key("lava"), Material.ORANGE_CONCRETE) diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/item/Items.java b/test/src/main/java/io/github/pylonmc/rebar/test/item/TestItems.java similarity index 66% rename from test/src/main/java/io/github/pylonmc/rebar/test/item/Items.java rename to test/src/main/java/io/github/pylonmc/rebar/test/item/TestItems.java index 0bf7899f6..957186009 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/item/Items.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/item/TestItems.java @@ -3,15 +3,17 @@ import io.github.pylonmc.rebar.item.RebarItem; import io.github.pylonmc.rebar.item.builder.ItemStackBuilder; import io.github.pylonmc.rebar.test.RebarTest; +import io.github.pylonmc.rebar.test.block.TestBlocks; +import io.github.pylonmc.rebar.test.block.TestRebarSimpleMultiblock; import io.papermc.paper.datacomponent.DataComponentTypes; import net.kyori.adventure.text.Component; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; -public final class Items { +public final class TestItems { - private Items() {} + private TestItems() {} public static final NamespacedKey STICKY_STICK_KEY = RebarTest.key("sticky_stick"); public static final ItemStack STICKY_STICK_STACK = ItemStackBuilder.rebar(Material.STICK, STICKY_STICK_KEY) @@ -21,5 +23,7 @@ private Items() {} public static void register() { RebarItem.register(RebarItem.class, STICKY_STICK_STACK); RebarItem.register(OminousBlazePower.class, OminousBlazePower.STACK); + RebarItem.register(RebarItem.class, ItemStackBuilder.rebar(Material.AMETHYST_BLOCK, TestBlocks.SIMPLE_BLOCK_KEY).build()); + RebarItem.register(RebarItem.class, ItemStackBuilder.rebar(Material.AMETHYST_BLOCK, TestRebarSimpleMultiblock.KEY).build()); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockEventErrorTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockEventErrorTest.java index 34fa3fbdf..964db0750 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockEventErrorTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockEventErrorTest.java @@ -19,6 +19,7 @@ public BlockEventErrorTest(){ super(new GameTestConfig.Builder(new NamespacedKey(RebarTest.instance(), "block_event_error_test")) .size(1) .setUp(test -> { + RebarConfig.FULL_ERROR_STACK_TRACES = false; Block block = BlockStorage.placeBlock(test.location(), BlockEventError.KEY).getBlock(); Entity theRinger = test.location().getWorld().spawn(test.location().clone().add(1, 0, 0), Skeleton.class); for(int i = 0; i < RebarConfig.ALLOWED_BLOCK_ERRORS + 1; i++){ @@ -26,6 +27,10 @@ public BlockEventErrorTest(){ } test.succeedWhen(() -> BlockStorage.get(block) instanceof PhantomBlock); }) + .cleanup(test -> { + BlockStorage.breakBlock(test.location()); + RebarConfig.FULL_ERROR_STACK_TRACES = true; + }) .build() ); } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageAddTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageAddTest.java index 128fa91a7..8070bda43 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageAddTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageAddTest.java @@ -5,7 +5,7 @@ import io.github.pylonmc.rebar.gametest.GameTestConfig; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; -import io.github.pylonmc.rebar.test.block.Blocks; +import io.github.pylonmc.rebar.test.block.TestBlocks; import org.bukkit.NamespacedKey; import static org.assertj.core.api.Assertions.assertThat; @@ -16,7 +16,7 @@ public BlockStorageAddTest() { super(new GameTestConfig.Builder(new NamespacedKey(RebarTest.instance(), "block_storage_add_test")) .size(1) .setUp((test) -> { - BlockStorage.placeBlock(test.location(), Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(test.location(), TestBlocks.SIMPLE_BLOCK_KEY); RebarBlock rebarBlock = BlockStorage.get(test.location()); @@ -26,6 +26,8 @@ public BlockStorageAddTest() { assertThat(BlockStorage.getAs(RebarBlock.class, test.location())) .isNotNull(); + + BlockStorage.breakBlock(test.location()); }) .build()); } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageFilledChunkTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageFilledChunkTest.java index fbdbedcb3..1b0843908 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageFilledChunkTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageFilledChunkTest.java @@ -4,7 +4,7 @@ import io.github.pylonmc.rebar.block.RebarBlock; import io.github.pylonmc.rebar.block.RebarBlockSchema; import io.github.pylonmc.rebar.test.base.AsyncTest; -import io.github.pylonmc.rebar.test.block.Blocks; +import io.github.pylonmc.rebar.test.block.TestBlocks; import io.github.pylonmc.rebar.test.util.TestUtil; import org.bukkit.Chunk; import org.bukkit.block.Block; @@ -18,7 +18,7 @@ public class BlockStorageFilledChunkTest extends AsyncTest { @Override public void test() { - Chunk chunk = TestUtil.getRandomChunk(true).join(); + Chunk chunk = TestUtil.getRandomChunk(false).join(); List blocks = new ArrayList<>(); for (int x = 0; x < 16; x++) { @@ -29,10 +29,9 @@ public void test() { } } - TestUtil.loadChunk(chunk).join(); TestUtil.runSync(() -> { for (Block block : blocks) { - BlockStorage.placeBlock(block, Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(block, TestBlocks.SIMPLE_BLOCK_KEY); } }).join(); TestUtil.unloadChunk(chunk).join(); @@ -46,7 +45,7 @@ public void test() { assertThat(rebarBlock.getSchema()) .extracting(RebarBlockSchema::getKey) - .isEqualTo(Blocks.SIMPLE_BLOCK_KEY); + .isEqualTo(TestBlocks.SIMPLE_BLOCK_KEY); } TestUtil.unloadChunk(chunk).join(); } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageRemoveTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageRemoveTest.java index a4053bda1..90fdd0b14 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageRemoveTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageRemoveTest.java @@ -4,7 +4,7 @@ import io.github.pylonmc.rebar.gametest.GameTestConfig; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; -import io.github.pylonmc.rebar.test.block.Blocks; +import io.github.pylonmc.rebar.test.block.TestBlocks; import org.bukkit.NamespacedKey; import static org.assertj.core.api.Assertions.assertThat; @@ -15,7 +15,7 @@ public BlockStorageRemoveTest() { super(new GameTestConfig.Builder(new NamespacedKey(RebarTest.instance(), "block_storage_remove_test")) .size(1) .setUp((test) -> { - BlockStorage.placeBlock(test.location(), Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(test.location(), TestBlocks.SIMPLE_BLOCK_KEY); assertThat(BlockStorage.get(test.location())) .isNotNull(); diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockRotatedTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockRotatedTest.java index d7ffc9f6f..b5d575c47 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockRotatedTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockRotatedTest.java @@ -2,7 +2,7 @@ import io.github.pylonmc.rebar.block.BlockStorage; import io.github.pylonmc.rebar.test.base.AsyncTest; -import io.github.pylonmc.rebar.test.block.Blocks; +import io.github.pylonmc.rebar.test.block.TestBlocks; import io.github.pylonmc.rebar.test.block.TestRebarSimpleMultiblock; import io.github.pylonmc.rebar.test.util.TestUtil; import org.bukkit.Chunk; @@ -16,7 +16,6 @@ public class SimpleMultiblockRotatedTest extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Location multiblockLocation = chunk.getBlock(5, 100, 5).getLocation(); @@ -26,8 +25,8 @@ protected void test() { Location component1Location0 = multiblockLocation.clone().add(1, 1, 4); Location component2Location0 = multiblockLocation.clone().add(2, -1, 0); TestUtil.runSync(() -> { - BlockStorage.placeBlock(component1Location0, Blocks.SIMPLE_BLOCK_KEY); - BlockStorage.placeBlock(component2Location0, Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component1Location0, TestBlocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component2Location0, TestBlocks.SIMPLE_BLOCK_KEY); }).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); @@ -43,8 +42,8 @@ protected void test() { Location component1Location1 = multiblockLocation.clone().add(-4, 1, 1); Location component2Location1 = multiblockLocation.clone().add(0, -1, 2); TestUtil.runSync(() -> { - BlockStorage.placeBlock(component1Location1, Blocks.SIMPLE_BLOCK_KEY); - BlockStorage.placeBlock(component2Location1, Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component1Location1, TestBlocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component2Location1, TestBlocks.SIMPLE_BLOCK_KEY); }).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); @@ -60,8 +59,8 @@ protected void test() { Location component1Location2 = multiblockLocation.clone().add(-1, 1, -4); Location component2Location2 = multiblockLocation.clone().add(-2, -1, 0); TestUtil.runSync(() -> { - BlockStorage.placeBlock(component1Location2, Blocks.SIMPLE_BLOCK_KEY); - BlockStorage.placeBlock(component2Location2, Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component1Location2, TestBlocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component2Location2, TestBlocks.SIMPLE_BLOCK_KEY); }).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); @@ -77,8 +76,8 @@ protected void test() { Location component1Location3 = multiblockLocation.clone().add(4, 1, -1); Location component2Location3 = multiblockLocation.clone().add(0, -1, -2); TestUtil.runSync(() -> { - BlockStorage.placeBlock(component1Location3, Blocks.SIMPLE_BLOCK_KEY); - BlockStorage.placeBlock(component2Location3, Blocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component1Location3, TestBlocks.SIMPLE_BLOCK_KEY); + BlockStorage.placeBlock(component2Location3, TestBlocks.SIMPLE_BLOCK_KEY); }).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); @@ -90,6 +89,6 @@ protected void test() { TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, false); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockTest.java index e883c99e0..4479e87c9 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/SimpleMultiblockTest.java @@ -2,7 +2,7 @@ import io.github.pylonmc.rebar.block.BlockStorage; import io.github.pylonmc.rebar.test.base.AsyncTest; -import io.github.pylonmc.rebar.test.block.Blocks; +import io.github.pylonmc.rebar.test.block.TestBlocks; import io.github.pylonmc.rebar.test.block.TestRebarSimpleMultiblock; import io.github.pylonmc.rebar.test.util.TestUtil; import org.bukkit.Chunk; @@ -23,7 +23,6 @@ public static void assertMultiblockFormed(Location multiblockLocation, boolean f @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Location multiblockLocation = chunk.getBlock(5, 100, 5).getLocation(); Location component1Location = multiblockLocation.clone().add(1, 1, 4); @@ -33,11 +32,11 @@ protected void test() { TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, false); - TestUtil.runSync(() -> BlockStorage.placeBlock(component1Location, Blocks.SIMPLE_BLOCK_KEY)).join(); + TestUtil.runSync(() -> BlockStorage.placeBlock(component1Location, TestBlocks.SIMPLE_BLOCK_KEY)).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, false); - TestUtil.runSync(() -> BlockStorage.placeBlock(component2Location, Blocks.SIMPLE_BLOCK_KEY)).join(); + TestUtil.runSync(() -> BlockStorage.placeBlock(component2Location, TestBlocks.SIMPLE_BLOCK_KEY)).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); @@ -45,12 +44,10 @@ protected void test() { TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, false); - chunk.setForceLoaded(false); TestUtil.unloadChunk(chunk).join(); TestUtil.loadChunk(chunk).join(); - chunk.setForceLoaded(true); - TestUtil.runSync(() -> BlockStorage.placeBlock(component2Location, Blocks.SIMPLE_BLOCK_KEY)).join(); + TestUtil.runSync(() -> BlockStorage.placeBlock(component2Location, TestBlocks.SIMPLE_BLOCK_KEY)).join(); TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); @@ -61,6 +58,6 @@ protected void test() { TestUtil.sleepTicks(2).join(); assertMultiblockFormed(multiblockLocation, true); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockErrorTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockErrorTest.java index f31817f6e..8a7877e76 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockErrorTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockErrorTest.java @@ -2,6 +2,7 @@ import io.github.pylonmc.rebar.block.BlockStorage; import io.github.pylonmc.rebar.block.base.RebarTickingBlock; +import io.github.pylonmc.rebar.config.RebarConfig; import io.github.pylonmc.rebar.gametest.GameTestConfig; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; @@ -14,10 +15,15 @@ public TickingBlockErrorTest() { super(new GameTestConfig.Builder(RebarTest.key("ticking_error_block")) .size(1) .setUp((test) -> { + RebarConfig.FULL_ERROR_STACK_TRACES = false; BlockStorage.placeBlock(test.location(), TickingErrorBlock.KEY); test.succeedWhen(() -> !RebarTickingBlock.isTicking(BlockStorage.get(test.location().getBlock()))); }) + .cleanup(test -> { + BlockStorage.breakBlock(test.location()); + RebarConfig.FULL_ERROR_STACK_TRACES = true; + }) .build()); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockTest.java index 6297c9485..5f2d24f8a 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/TickingBlockTest.java @@ -1,6 +1,7 @@ package io.github.pylonmc.rebar.test.test.block; import io.github.pylonmc.rebar.block.BlockStorage; +import io.github.pylonmc.rebar.config.RebarConfig; import io.github.pylonmc.rebar.gametest.GameTestConfig; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; @@ -17,6 +18,7 @@ public TickingBlockTest() { test.succeedWhen(() -> BlockStorage.getAs(TickingBlock.class, test.location()).ticks >= 5); }) + .cleanup(test -> BlockStorage.breakBlock(test.location())) .build()); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java index 840ae4de7..f924e8b84 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java @@ -7,7 +7,7 @@ import io.github.pylonmc.rebar.test.base.GameTest; import io.github.pylonmc.rebar.test.entity.EntityEventError; import org.bukkit.NamespacedKey; -import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import java.util.UUID; @@ -16,13 +16,15 @@ public EntityEventErrorTest(){ super(new GameTestConfig.Builder(new NamespacedKey(RebarTest.instance(), "entity_event_error_test")) .size(1) .setUp(test -> { + RebarConfig.FULL_ERROR_STACK_TRACES = false; EntityEventError entity = new EntityEventError(test.location()); EntityStorage.add(entity); UUID entityUUID = entity.getUuid(); for(int i = 0; i < RebarConfig.ALLOWED_ENTITY_ERRORS + 1; i++){ // Yes, this is cursed, yes it works. - new PlayerInteractEntityEvent(null, entity.getEntity()).callEvent(); + new EntityDamageEvent(entity.getEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1).callEvent(); } + RebarConfig.FULL_ERROR_STACK_TRACES = true; test.succeedWhen(() -> !EntityStorage.isRebarEntity(entityUUID)); }) .build()); diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java index 9c8ca6c18..34c74c96e 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java @@ -48,5 +48,7 @@ protected void test() { .isEqualTo(69); assertThat(((LivingEntity) EntityStorage.get(uuid).getEntity()).hasAI()) .isFalse(); + + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java index a57acf951..481a5c676 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java @@ -80,5 +80,6 @@ protected void test() { assertThat(EntityStorage.get(uuid)) .isNotNull() .isInstanceOf(UnregisteredEntity.class); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidConnectionTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidConnectionTest.java index 8f6190731..42fc8ba93 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidConnectionTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidConnectionTest.java @@ -17,7 +17,6 @@ public class FluidConnectionTest extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Block consumerBlock = chunk.getBlock(6, 64, 5); FluidConsumer consumer = (FluidConsumer) TestUtil.runSync( @@ -65,6 +64,6 @@ protected void test() { BlockStorage.breakBlock(producerBlock); }).join(); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidCyclicConnectionsTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidCyclicConnectionsTest.java index d681afd7b..b300b5944 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidCyclicConnectionsTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidCyclicConnectionsTest.java @@ -18,7 +18,6 @@ public class FluidCyclicConnectionsTest extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Block producerBlock = chunk.getBlock(2, 64, 5); FluidProducer producer = (FluidProducer) TestUtil.runSync( @@ -67,6 +66,6 @@ protected void test() { .isNotEqualTo(producer.getPoint().getSegment()) .isNotEqualTo(connector.getPoint().getSegment()); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidFlowRateTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidFlowRateTest.java index f29836de5..722d2f152 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidFlowRateTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidFlowRateTest.java @@ -17,7 +17,6 @@ public class FluidFlowRateTest extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Block waterProducerBlock = chunk.getBlock(2, 64, 5); FluidProducer waterProducer = (FluidProducer) TestUtil.runSync( @@ -53,6 +52,6 @@ protected void test() { .isGreaterThan(lavaConsumer.getAmount() - 0.101) .isLessThan(lavaConsumer.getAmount() + 0.101); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPartialReloadTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPartialReloadTest.java index e5e19c558..31f883f0e 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPartialReloadTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPartialReloadTest.java @@ -18,11 +18,8 @@ public class FluidPartialReloadTest extends AsyncTest { @Override protected void test() { Chunk producerChunk = TestUtil.getRandomChunk(false).join(); - producerChunk.setForceLoaded(true); Chunk connectorChunk = TestUtil.getRandomChunk(false).join(); - connectorChunk.setForceLoaded(true); Chunk consumerChunk = TestUtil.getRandomChunk(false).join(); - consumerChunk.setForceLoaded(true); Block consumerBlock = consumerChunk.getBlock(6, 64, 5); FluidConsumer consumer = (FluidConsumer) TestUtil.runSync( @@ -50,21 +47,19 @@ protected void test() { .isEqualTo(producer.getPoint().getSegment()); // After unloading the connector, the producer and consumer should have different segments - connectorChunk.setForceLoaded(false); TestUtil.unloadChunk(connectorChunk).join(); assertThat(consumer.getPoint().getSegment()) .isNotEqualTo(producer.getPoint().getSegment()); // When the chunk is reloaded, all should have the same segment again TestUtil.loadChunk(connectorChunk).join(); - connectorChunk.setForceLoaded(true); FluidConnector reloadedConnector = BlockStorage.getAs(FluidConnector.class, connectorBlock); assertThat(consumer.getPoint().getSegment()) .isEqualTo(reloadedConnector.getPoint().getSegment()) .isEqualTo(producer.getPoint().getSegment()); - producerChunk.setForceLoaded(false); - connectorChunk.setForceLoaded(false); - consumerChunk.setForceLoaded(false); + TestUtil.unloadChunk(producerChunk).join(); + TestUtil.unloadChunk(connectorChunk).join(); + TestUtil.unloadChunk(consumerChunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPredicateTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPredicateTest.java index 503f02a2f..316421981 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPredicateTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidPredicateTest.java @@ -18,7 +18,6 @@ public class FluidPredicateTest extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Block waterProducerBlock = chunk.getBlock(2, 64, 5); FluidProducer waterProducer = (FluidProducer) TestUtil.runSync( @@ -59,6 +58,6 @@ protected void test() { assertThat(lavaConsumer.getAmount()) .isNotEqualTo(0); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTest.java index d9506f116..22608e6ed 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTest.java @@ -18,7 +18,6 @@ public class FluidTickerTest extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Block producerBlock = chunk.getBlock(2, 64, 5); FluidProducer producer = (FluidProducer) TestUtil.runSync( @@ -56,6 +55,6 @@ protected void test() { .isGreaterThanOrEqualTo(99.5) .isLessThanOrEqualTo(100.5); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTestWithMixedFluids.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTestWithMixedFluids.java index 80cdbbe12..f3ab142cd 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTestWithMixedFluids.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/fluid/FluidTickerTestWithMixedFluids.java @@ -16,7 +16,6 @@ public class FluidTickerTestWithMixedFluids extends AsyncTest { @Override protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); - chunk.setForceLoaded(true); Block producerBlock1 = chunk.getBlock(2, 64, 4); FluidProducer producer1 = (FluidProducer) TestUtil.runSync( @@ -52,6 +51,6 @@ protected void test() { TestUtil.waitUntil(() -> consumer1.getAmount() == 100 && consumer2.getAmount() == 100).join(); - chunk.setForceLoaded(false); + TestUtil.unloadChunk(chunk).join(); } } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java index 4394f8d47..ab4d6c77b 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java @@ -1,5 +1,6 @@ package io.github.pylonmc.rebar.test.test.item; +import io.github.pylonmc.rebar.block.BlockStorage; import io.github.pylonmc.rebar.gametest.GameTestConfig; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; @@ -23,9 +24,7 @@ public RebarItemStackInterfaceTest() { Block block = test.getWorld().getBlockAt(test.location()); block.setType(Material.BREWING_STAND); - Bukkit.getPluginManager().callEvent( - new BrewingStandFuelEvent(block, OminousBlazePower.STACK, 1)); - + Bukkit.getPluginManager().callEvent(new BrewingStandFuelEvent(block, OminousBlazePower.STACK, 1)); }) .build()); } diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/CraftingTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/CraftingTest.java index a6e1b8a8f..91dd7fdf3 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/CraftingTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/CraftingTest.java @@ -3,7 +3,7 @@ import io.github.pylonmc.rebar.recipe.RecipeType; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.SyncTest; -import io.github.pylonmc.rebar.test.item.Items; +import io.github.pylonmc.rebar.test.item.TestItems; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -18,7 +18,7 @@ public class CraftingTest extends SyncTest { @Override protected void test() { - ItemStack stickyStick = Items.STICKY_STICK_STACK; + ItemStack stickyStick = TestItems.STICKY_STICK_STACK; ItemStack diamond = new ItemStack(Material.DIAMOND); ItemStack nothing = new ItemStack(Material.AIR); ItemStack normalStick = new ItemStack(Material.STICK); diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java index aa2b5adb4..33fc4ec4f 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java @@ -4,7 +4,7 @@ import io.github.pylonmc.rebar.recipe.RecipeType; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; -import io.github.pylonmc.rebar.test.item.Items; +import io.github.pylonmc.rebar.test.item.TestItems; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Furnace; @@ -19,7 +19,7 @@ public FurnaceTest() { super(new GameTestConfig.Builder(RebarTest.key("furnace_test")) .size(0) .setUp(test -> { - ItemStack stickyStick = Items.STICKY_STICK_STACK; + ItemStack stickyStick = TestItems.STICKY_STICK_STACK; ItemStack diamond = new ItemStack(Material.DIAMOND); RecipeType.VANILLA_FURNACE.addRecipe(new FurnaceRecipe( RebarTest.key("sticky_stick_furnace"), diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java b/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java index 784b24e0c..6360f8422 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java @@ -99,6 +99,8 @@ private TestUtil() {} throw new RuntimeException(e); } } + } else { + chunk.setForceLoaded(true); } return chunk; @@ -145,7 +147,10 @@ private TestUtil() {} @CheckReturnValue public static @NotNull CompletableFuture loadChunk(@NotNull Chunk chunk) { return runAsync(() -> { - runSync(() -> chunk.load()).join(); + runSync(() -> { + chunk.load(); + chunk.setForceLoaded(true); + }).join(); waitUntil(chunk::isLoaded).join(); }); } @@ -154,7 +159,10 @@ private TestUtil() {} public static @NotNull CompletableFuture unloadChunk(@NotNull Chunk chunk) { return runAsync(() -> { ChunkPosition chunkPosition = new ChunkPosition(chunk); - runSync(() -> chunk.unload()).join(); + runSync(() -> { + chunk.setForceLoaded(false); + chunk.unload(); + }).join(); waitUntil(() -> !chunkPosition.isLoaded()).join(); }); } From e2badca6b8654b5e379ee6910fb5a5fed3272c10 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD Date: Thu, 14 May 2026 03:29:15 -0500 Subject: [PATCH 2/2] just use .damage(0) --- .../pylonmc/rebar/test/test/entity/EntityEventErrorTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java index f924e8b84..167d88475 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityEventErrorTest.java @@ -7,7 +7,6 @@ import io.github.pylonmc.rebar.test.base.GameTest; import io.github.pylonmc.rebar.test.entity.EntityEventError; import org.bukkit.NamespacedKey; -import org.bukkit.event.entity.EntityDamageEvent; import java.util.UUID; @@ -22,11 +21,11 @@ public EntityEventErrorTest(){ UUID entityUUID = entity.getUuid(); for(int i = 0; i < RebarConfig.ALLOWED_ENTITY_ERRORS + 1; i++){ // Yes, this is cursed, yes it works. - new EntityDamageEvent(entity.getEntity(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, 1).callEvent(); + entity.getEntity().damage(0); } - RebarConfig.FULL_ERROR_STACK_TRACES = true; test.succeedWhen(() -> !EntityStorage.isRebarEntity(entityUUID)); }) + .cleanup(test -> RebarConfig.FULL_ERROR_STACK_TRACES = true) .build()); } }