Also limit BlockFormEvent when tps is too low

This commit is contained in:
Luna 2023-07-01 21:06:12 -03:00
parent 1a0a0ab0a0
commit 06d34fd345
1 changed files with 10 additions and 4 deletions

View File

@ -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