mirror of
https://github.com/kaboomserver/extras.git
synced 2025-01-06 22:51:53 +00: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());
|
this.getCommand("username").setExecutor(new CommandUsername());
|
||||||
|
|
||||||
/* Block-related modules */
|
/* Block-related modules */
|
||||||
|
BlockPhysics.init(this);
|
||||||
|
|
||||||
this.getServer().getPluginManager().registerEvents(new BlockCheck(), this);
|
this.getServer().getPluginManager().registerEvents(new BlockCheck(), this);
|
||||||
this.getServer().getPluginManager().registerEvents(new BlockPhysics(), 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 org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
|
||||||
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
import com.destroystokyo.paper.event.block.BlockDestroyEvent;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import pw.kaboom.extras.Main;
|
||||||
|
|
||||||
public final class BlockPhysics implements Listener {
|
public final class BlockPhysics implements Listener {
|
||||||
|
|
||||||
// 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 HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
private static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -141,7 +143,6 @@ public final class BlockPhysics implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onBlockRedstone(final BlockRedstoneEvent event) {
|
void onBlockRedstone(final BlockRedstoneEvent event) {
|
||||||
final double tps = Bukkit.getServer().getTPS()[0];
|
|
||||||
final int maxTps = 10;
|
final int maxTps = 10;
|
||||||
|
|
||||||
if (tps < maxTps) {
|
if (tps < maxTps) {
|
||||||
|
@ -169,4 +170,16 @@ public final class BlockPhysics implements Listener {
|
||||||
public static HashSet<BlockFace> getBlockFaces() {
|
public static HashSet<BlockFace> getBlockFaces() {
|
||||||
return blockFaces;
|
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