mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-27 01:45:44 -05:00
Attempt to improve server performance under intense redstone load (#338)
This commit is contained in:
parent
98df416d89
commit
1f18704dcd
2 changed files with 17 additions and 2 deletions
|
@ -93,6 +93,8 @@ public final class Main extends JavaPlugin {
|
|||
this.getCommand("username").setExecutor(new CommandUsername());
|
||||
|
||||
/* Block-related modules */
|
||||
BlockPhysics.init(this);
|
||||
|
||||
this.getServer().getPluginManager().registerEvents(new BlockCheck(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new BlockPhysics(), this);
|
||||
|
||||
|
|
|
@ -16,12 +16,14 @@ import org.bukkit.event.block.BlockRedstoneEvent;
|
|||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
|
||||
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import pw.kaboom.extras.Main;
|
||||
|
||||
public final class BlockPhysics implements Listener {
|
||||
|
||||
// This class contains code to prevent large areas of non-solid blocks
|
||||
// from crashing the server
|
||||
|
||||
private static double tps = 20;
|
||||
private static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
||||
|
||||
@EventHandler
|
||||
|
@ -141,7 +143,6 @@ public final class BlockPhysics implements Listener {
|
|||
|
||||
@EventHandler
|
||||
void onBlockRedstone(final BlockRedstoneEvent event) {
|
||||
final double tps = Bukkit.getServer().getTPS()[0];
|
||||
final int maxTps = 10;
|
||||
|
||||
if (tps < maxTps) {
|
||||
|
@ -169,4 +170,16 @@ public final class BlockPhysics implements Listener {
|
|||
public static HashSet<BlockFace> getBlockFaces() {
|
||||
return blockFaces;
|
||||
}
|
||||
|
||||
private static void updateTPS() {
|
||||
final double[] tpsValues = Bukkit.getTPS();
|
||||
|
||||
tps = tpsValues[0];
|
||||
}
|
||||
|
||||
public static void init(final Main main) {
|
||||
final BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||
|
||||
scheduler.runTaskTimer(main, BlockPhysics::updateTPS, 0L, 1200L); // 1 minute
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue