Skip to content

Commit

Permalink
first attempt at tps check fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 17, 2024
1 parent 57052d7 commit 1bc1e0d
Show file tree
Hide file tree
Showing 23 changed files with 94 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class AnarchyExploitFixes extends JavaPlugin {
private static AnarchyExploitFixes instance;
private static HashMap<String, LanguageCache> languageCacheMap;
private static Config config;
private static TPSCache tpsCache;
private static Logger logger;
private static boolean isServerFolia, foundProtocolLib;

public TPSCache tpsCache;
public final HashSet<UUID> NEW_CHUNK_PLAYERS = new HashSet<>();

@Override
Expand Down Expand Up @@ -97,6 +97,9 @@ public static AnarchyExploitFixes getInstance() {
public static HashMap<String, LanguageCache> getLanguageCacheMap() {
return languageCacheMap;
}
public static TPSCache getTpsCache() {
return tpsCache;
}
public static Config getConfiguration() {
return config;
}
Expand Down Expand Up @@ -131,7 +134,7 @@ public void reloadPlugin() {
private void reloadConfiguration() {
try {
config = new Config();
this.tpsCache = TPSCache.create(config.max_tps_check_interval_millis);
tpsCache = TPSCache.create(config.max_tps_check_interval_millis);
AnarchyExploitFixesModule.reloadModules();
config.saveConfig();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ private void onChunkLoad(ChunkLoadEvent event) {
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (world.getEnvironment() != World.Environment.NETHER) return;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(event) <= pauseTPS)) return;

Chunk chunk = event.getChunk();

if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(),
fixBedrock -> ChunkUtil.createBedrockLayer(chunk, ceilingY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ private void onChunkLoad(ChunkLoadEvent event) {
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (world.getEnvironment() != World.Environment.NETHER) return;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(event) <= pauseTPS)) return;

Chunk chunk = event.getChunk();

if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(),
fixBedrock -> ChunkUtil.createBedrockLayer(chunk, world.getMinHeight()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ private void onChunkLoad(ChunkLoadEvent event) {
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (world.getEnvironment() != World.Environment.NETHER) return;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(event) <= pauseTPS)) return;

Chunk chunk = event.getChunk();

if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(),
fixBedrock -> ChunkUtil.createBedrockLayer(chunk, world.getMinHeight()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void run() {

for (Chunk chunk : world.getLoadedChunks()) {
if (!chunk.isEntitiesLoaded()) continue;
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(),
fixBedrock -> ChunkUtil.createBedrockLayer(chunk, ceilingY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void run() {

for (Chunk chunk : world.getLoadedChunks()) {
if (!chunk.isEntitiesLoaded()) continue;
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(),
fixBedrock -> ChunkUtil.createBedrockLayer(chunk, world.getMinHeight()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void run() {

for (Chunk chunk : world.getLoadedChunks()) {
if (!chunk.isEntitiesLoaded()) continue;
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(),
fixBedrock -> ChunkUtil.createBedrockLayer(chunk, world.getMinHeight()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
return;
}

if (spawn_DenyOnLowTPS && plugin.tpsCache.getTPS(event.getTo()) <= spawn_DenyElytraTPS) {
if (spawn_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event) <= spawn_DenyElytraTPS) {
if (teleportBack) player.teleportAsync(event.getFrom());
else event.setCancelled(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
return;
}

if (global_DenyOnLowTPS && plugin.tpsCache.getTPS(event.getTo()) <= global_DenyElytraTPS) {
if (global_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) <= global_DenyElytraTPS) {
if (teleportBack) player.teleportAsync(event.getFrom());
else event.setCancelled(true);

Expand Down Expand Up @@ -129,7 +129,7 @@ private void onPlayerMove(PlayerMoveEvent event) {

if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) {
// Speed New Chunks
if (global_EnableBursting && plugin.tpsCache.getTPS(event.getTo()) >= global_BurstNewChunk_TPS) {
if (global_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= global_BurstNewChunk_TPS) {
// Burst Speed New Chunks
if (flySpeed > global_BurstSpeedNewChunks+tolerance) {
if (teleportBack) player.teleportAsync(event.getFrom());
Expand Down Expand Up @@ -215,7 +215,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
}
} else {
// Speed Old Chunks
if (global_EnableBursting && plugin.tpsCache.getTPS(event.getTo()) >= global_BurstOldChunk_TPS) {
if (global_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= global_BurstOldChunk_TPS) {
// Burst Speed Old Chunks
if (flySpeed > global_BurstSpeedOldChunks+tolerance) {
if (teleportBack) player.teleportAsync(event.getFrom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
return;
}

if (ceiling_DenyOnLowTPS && plugin.tpsCache.getTPS(event.getTo()) <= ceiling_DenyElytraTPS) {
if (ceiling_DenyOnLowTPS && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) <= ceiling_DenyElytraTPS) {
if (teleportBack) player.teleportAsync(event.getFrom());
else event.setCancelled(true);

Expand Down Expand Up @@ -126,7 +126,7 @@ private void onPlayerMove(PlayerMoveEvent event) {

if (plugin.NEW_CHUNK_PLAYERS.contains(player.getUniqueId())) {
// Speed New Chunks
if (ceiling_EnableBursting && plugin.tpsCache.getTPS(event.getTo()) >= ceiling_BurstNewChunk_TPS) {
if (ceiling_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= ceiling_BurstNewChunk_TPS) {
// Burst Speed New Chunks
if (flySpeed > ceiling_BurstSpeedNewChunks+tolerance) {
if (teleportBack) player.teleportAsync(event.getFrom());
Expand Down Expand Up @@ -211,7 +211,7 @@ private void onPlayerMove(PlayerMoveEvent event) {
}
} else {
// Speed Old Chunks
if (ceiling_EnableBursting && plugin.tpsCache.getTPS(event.getTo()) >= ceiling_BurstOldChunk_TPS) {
if (ceiling_EnableBursting && AnarchyExploitFixes.getTpsCache().getTPS(event.getTo()) >= ceiling_BurstOldChunk_TPS) {
// Burst Speed Old Chunks
if (flySpeed > ceiling_BurstSpeedOldChunks+tolerance) {
if (teleportBack) player.teleportAsync(event.getFrom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void run() {

for (Chunk chunk : world.getLoadedChunks()) {
if (!chunk.isEntitiesLoaded()) continue;
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) continue;

plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> {
if (!chunk.isEntitiesLoaded()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public void disable() {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onChunkLoad(ChunkLoadEvent event) {
if (event.isNewChunk()) return;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(event) <= pauseTPS)) return;

Chunk chunk = event.getChunk();
World world = chunk.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) return;

final int minY = world.getMinHeight();
final int maxY = world.getMaxHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public void disable() {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onChunkLoad(ChunkLoadEvent event) {
if (event.isNewChunk()) return;
if (checkShouldPauseOnLowTPS && (AnarchyExploitFixes.getTpsCache().getTPS(event) <= pauseTPS)) return;

Chunk chunk = event.getChunk();
World world = chunk.getWorld();
if (!naturalSpawners.containsKey(world.getName())) return;
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunk.getX(), chunk.getZ()) <= pauseTPS)) return;

final int minY = world.getMinHeight();
final int maxY = world.getMaxHeight();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

public class BlockMelting implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final double disableMeltingTPS;
private final boolean logIsEnabled;

public BlockMelting() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.disableMeltingTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.melting-blocks.disable-TPS", 16.0);
this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.melting-blocks.log", false);
Expand All @@ -39,6 +37,7 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -54,7 +53,7 @@ public void disable() {

@EventHandler(priority = EventPriority.LOWEST)
private void onBlockFade(BlockFadeEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disableMeltingTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableMeltingTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Stopped block melting because tps is lower than " + disableMeltingTPS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

public class BlockPhysics implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final double disablePhysicsTPS;
private final boolean logIsEnabled;

public BlockPhysics() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("lag-preventions.disable-physics-during-low-tps.block-physics.enable", "Stop block physics (like falling blocks) when the TPS gets below a certain value.");
this.disablePhysicsTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.block-physics.disable-TPS", 16.0);
Expand All @@ -39,6 +37,7 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -54,7 +53,7 @@ public void disable() {

@EventHandler(priority = EventPriority.LOWEST)
private void onEntityChange(BlockPhysicsEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disablePhysicsTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disablePhysicsTPS) {
event.setCancelled(true);
if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled block physics because TPS is lower than " + disablePhysicsTPS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@

public class Explosions implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final double disableExplosionsTPS;
private final boolean logIsEnabled;

public Explosions() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("lag-preventions.disable-physics-during-low-tps.explosions.enable", "Disable explosions during low tps to combat lag.");
this.disableExplosionsTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.explosions.disable-TPS", 14.0);
Expand All @@ -42,6 +40,7 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -57,23 +56,23 @@ public void disable() {

@EventHandler(priority = EventPriority.LOWEST)
private void onEntityExplode(EntityExplodeEvent event) {
if (plugin.tpsCache.getTPS(event.getLocation()) <= disableExplosionsTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableExplosionsTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Cancelled explosion because tps is lower than " + disableExplosionsTPS);
}
}

@EventHandler(priority = EventPriority.LOWEST)
private void onExplodePrime(ExplosionPrimeEvent event) {
if (plugin.tpsCache.getTPS(event.getEntity().getLocation()) <= disableExplosionsTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableExplosionsTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Cancelled explosion because tps is lower than " + disableExplosionsTPS);
}
}

@EventHandler(priority = EventPriority.LOWEST)
private void onBlockExplode(BlockExplodeEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disableExplosionsTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableExplosionsTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Cancelled explosion because tps is lower than " + disableExplosionsTPS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

public class FireSpread implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final double disableFireTPS;
private final boolean logIsEnabled;

public FireSpread() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.disableFireTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.fire-spread.disable-TPS", 14.0);
this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.fire-spread.log", false);
Expand All @@ -39,6 +37,7 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -54,7 +53,7 @@ public void disable() {

@EventHandler(priority = EventPriority.LOWEST)
private void onLiquidSpread(BlockIgniteEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disableFireTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableFireTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Stopped fire spread because tps is lower than " + disableFireTPS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -55,15 +56,15 @@ public void disable() {

@EventHandler(priority = EventPriority.LOWEST)
private void onBlockForm(BlockFormEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disableGrassTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableGrassTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Stopped grass spread because tps is lower than " + disableGrassTPS);
}
}

@EventHandler(priority = EventPriority.LOWEST)
private void onBlockForm(BlockSpreadEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disableGrassTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableGrassTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Stopped grass spread because tps is lower than " + disableGrassTPS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@

public class LeaveDecay implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final double disableLeaveDecayTPS;
private final boolean logIsEnabled;

public LeaveDecay() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.disableLeaveDecayTPS = config.getDouble("lag-preventions.disable-physics-during-low-tps.leave-decay.disable-TPS", 14.0);
this.logIsEnabled = config.getBoolean("lag-preventions.disable-physics-during-low-tps.leave-decay.log", false);
Expand All @@ -39,6 +37,7 @@ public String category() {

@Override
public void enable() {
AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance();
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

Expand All @@ -54,7 +53,7 @@ public void disable() {

@EventHandler(priority = EventPriority.LOWEST)
private void onLeaveDecay(LeavesDecayEvent event) {
if (plugin.tpsCache.getTPS(event.getBlock().getLocation()) <= disableLeaveDecayTPS) {
if (AnarchyExploitFixes.getTpsCache().getTPS(event) <= disableLeaveDecayTPS) {
event.setCancelled(true);
if (logIsEnabled) moduleLog(Level.INFO, name(),"Cancelled leave decay because tps is lower than " + disableLeaveDecayTPS);
}
Expand Down
Loading

0 comments on commit 1bc1e0d

Please sign in to comment.