forked from kaboomserver/extras
Also limit BlockFormEvent when tps is too low
This commit is contained in:
parent
1a0a0ab0a0
commit
06d34fd345
1 changed files with 10 additions and 4 deletions
|
@ -5,6 +5,7 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockFormEvent;
|
||||||
import org.bukkit.event.block.BlockPhysicsEvent;
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.block.BlockRedstoneEvent;
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
@ -12,7 +13,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||||
import pw.kaboom.extras.Main;
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class BlockPhysics implements Listener {
|
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
|
// This class contains code to prevent large areas of non-solid blocks
|
||||||
// from crashing the server
|
// from crashing the server
|
||||||
private static double tps = 20;
|
private static double tps = 20;
|
||||||
|
@ -37,15 +38,20 @@ public final class BlockPhysics implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockRedstone(final BlockRedstoneEvent event) {
|
void onBlockRedstone(final BlockRedstoneEvent event) {
|
||||||
final int maxTps = 10;
|
if (tps < MINIMUM_TPS) {
|
||||||
|
|
||||||
if (tps < maxTps) {
|
|
||||||
event.setNewCurrent(0);
|
event.setNewCurrent(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int fallingBlockCount;
|
private int fallingBlockCount;
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
void onBlockForm(final BlockFormEvent event) {
|
||||||
|
if (tps < MINIMUM_TPS) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onEntityChangeBlock(final EntityChangeBlockEvent event) {
|
void onEntityChangeBlock(final EntityChangeBlockEvent event) {
|
||||||
if (event.getEntityType() == EntityType.FALLING_BLOCK
|
if (event.getEntityType() == EntityType.FALLING_BLOCK
|
||||||
|
|
Loading…
Reference in a new issue