From 06d34fd3458346ac0c135d7a39c8248d886e61ac Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 1 Jul 2023 21:06:12 -0300 Subject: [PATCH] Also limit BlockFormEvent when tps is too low --- .../kaboom/extras/modules/block/BlockPhysics.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java index c7dc005..f6f5405 100644 --- a/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java +++ b/src/main/java/pw/kaboom/extras/modules/block/BlockPhysics.java @@ -5,6 +5,7 @@ import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFormEvent; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockRedstoneEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; @@ -12,7 +13,7 @@ import org.bukkit.scheduler.BukkitScheduler; import pw.kaboom.extras.Main; public final class BlockPhysics implements Listener { - + private static final double MINIMUM_TPS = 10; // This class contains code to prevent large areas of non-solid blocks // from crashing the server private static double tps = 20; @@ -37,15 +38,20 @@ public final class BlockPhysics implements Listener { @EventHandler void onBlockRedstone(final BlockRedstoneEvent event) { - final int maxTps = 10; - - if (tps < maxTps) { + if (tps < MINIMUM_TPS) { event.setNewCurrent(0); } } private int fallingBlockCount; + @EventHandler + void onBlockForm(final BlockFormEvent event) { + if (tps < MINIMUM_TPS) { + event.setCancelled(true); + } + } + @EventHandler void onEntityChangeBlock(final EntityChangeBlockEvent event) { if (event.getEntityType() == EntityType.FALLING_BLOCK