Skip to content

Commit

Permalink
follow some advice
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 6, 2024
1 parent 4698328 commit 9d952e5
Show file tree
Hide file tree
Showing 62 changed files with 381 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FillNetherCeilingOnChunkload implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final int ceilingY;
private final Set<String> exemptedWorlds;
private final double pauseTPS;
private final int ceilingY;
private final boolean alsoCheckNewChunks, checkShouldPauseOnLowTPS;
private final HashSet<String> exemptedWorlds = new HashSet<>();

public FillNetherCeilingOnChunkload() {
shouldEnable();
Expand All @@ -30,7 +31,7 @@ public FillNetherCeilingOnChunkload() {
this.ceilingY = config.nether_ceiling_max_y;
this.alsoCheckNewChunks = config.getBoolean("bedrock.fill-in-bedrock.nether-ceiling.fill-on-chunkload.also-check-new-chunks", false,
"Recommended to leave off. Only useful if world generation is broken for some reason.");
this.exemptedWorlds.addAll(config.getList("bedrock.fill-in-bedrock.nether-ceiling.exempted-worlds", List.of("exampleworld", "exampleworld2"),
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.fill-in-bedrock.nether-ceiling.exempted-worlds", List.of("exampleworld", "exampleworld2"),
"Case sensitive!"));
this.checkShouldPauseOnLowTPS = config.getBoolean("bedrock.fill-in-bedrock.nether-ceiling.fill-on-chunkload.pause-on-low-tps", true);
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.nether-ceiling.fill-on-chunkload.pause-tps", 16.0,
Expand Down Expand Up @@ -67,13 +68,13 @@ private void onChunkLoad(ChunkLoadEvent event) {
if (!alsoCheckNewChunks && event.isNewChunk()) return;
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (!world.getEnvironment().equals(World.Environment.NETHER)) return;
if (world.getEnvironment() != World.Environment.NETHER) return;

Chunk chunk = event.getChunk();
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> ChunkUtil.createBedrockLayer(chunk, ceilingY));
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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FillNetherFloorOnChunkload implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final Set<String> exemptedWorlds;
private final double pauseTPS;
private final boolean alsoCheckNewChunks, checkShouldPauseOnLowTPS;
private final HashSet<String> exemptedWorlds = new HashSet<>();

public FillNetherFloorOnChunkload() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.alsoCheckNewChunks = config.getBoolean("bedrock.fill-in-bedrock.nether-floor.fill-on-chunkload.also-check-new-chunks", false);
this.exemptedWorlds.addAll(config.getList("bedrock.fill-in-bedrock.nether-floor.exempted-worlds", List.of("exampleworld", "exampleworld2"),
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.fill-in-bedrock.nether-floor.exempted-worlds", List.of("exampleworld", "exampleworld2"),
"Case sensitive!"));
this.checkShouldPauseOnLowTPS = config.getBoolean("bedrock.fill-in-bedrock.nether-floor.fill-on-chunkload.pause-on-low-tps", true);
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.nether-floor.fill-on-chunkload.pause-tps", 16.0);
Expand Down Expand Up @@ -63,13 +64,13 @@ private void onChunkLoad(ChunkLoadEvent event) {
if (!alsoCheckNewChunks && event.isNewChunk()) return;
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (!world.getEnvironment().equals(World.Environment.NETHER)) return;
if (world.getEnvironment() != World.Environment.NETHER) return;

Chunk chunk = event.getChunk();
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> ChunkUtil.createBedrockLayer(chunk, world.getMinHeight()));
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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FillOverworldFloorOnChunkload implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private final Set<String> exemptedWorlds;
private final double pauseTPS;
private final boolean alsoCheckNewChunks, checkShouldPauseOnLowTPS;
private final HashSet<String> exemptedWorlds = new HashSet<>();

public FillOverworldFloorOnChunkload() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.alsoCheckNewChunks = config.getBoolean("bedrock.fill-in-bedrock.overworld-floor.fill-on-chunkload.also-check-new-chunks", false,
"Recommended to leave off. Only useful if world generation is broken for some reason.");
this.exemptedWorlds.addAll(config.getList("bedrock.fill-in-bedrock.overworld-floor.exempted-worlds", List.of("exampleworld", "exampleworld2"),
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.fill-in-bedrock.overworld-floor.exempted-worlds", List.of("exampleworld", "exampleworld2"),
"Case sensitive!"));
this.checkShouldPauseOnLowTPS = config.getBoolean("bedrock.fill-in-bedrock.overworld-floor.fill-on-chunkload.pause-on-low-tps", true,
"Pauses the task during low tps to avoid lag.");
Expand Down Expand Up @@ -66,13 +67,13 @@ private void onChunkLoad(ChunkLoadEvent event) {
if (!alsoCheckNewChunks && event.isNewChunk()) return;
final World world = event.getWorld();
if (exemptedWorlds.contains(world.getName())) return;
if (!world.getEnvironment().equals(World.Environment.NETHER)) return;
if (world.getEnvironment() != World.Environment.NETHER) return;

Chunk chunk = event.getChunk();
final int chunkX = chunk.getX();
final int chunkZ = chunk.getZ();
if (checkShouldPauseOnLowTPS && (plugin.tpsCache.getTPS(world, chunkX, chunkZ) <= pauseTPS)) return;

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> ChunkUtil.createBedrockLayer(chunk, world.getMinHeight()));
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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PeriodicallyFillNetherCeiling implements AnarchyExploitFixesModule {

private final AnarchyExploitFixes plugin;
private ScheduledTask scheduledTask;
private final int ceilingY;
private final Set<String> exemptedWorlds;
private final long checkPeriod;
private final double pauseTPS;
private final int ceilingY;
private final boolean checkShouldPauseOnLowTPS;
private final HashSet<String> exemptedWorlds = new HashSet<>();

public PeriodicallyFillNetherCeiling() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.ceilingY = config.nether_ceiling_max_y;
this.checkPeriod = config.getInt("bedrock.fill-in-bedrock.nether-ceiling.periodically-check-and-fill.check-period-in-seconds", 10) * 20L;
this.exemptedWorlds.addAll(config.getList("bedrock.fill-in-bedrock.nether-ceiling.exempted-worlds", List.of("exampleworld", "exampleworld2")));
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.fill-in-bedrock.nether-ceiling.exempted-worlds", List.of("exampleworld", "exampleworld2")));
this.checkShouldPauseOnLowTPS = config.getBoolean("bedrock.fill-in-bedrock.nether-ceiling.periodically-check-and-fill.pause-on-low-tps", true);
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.nether-ceiling.periodically-check-and-fill.pause-tps", 16.0);
}
Expand All @@ -44,7 +45,7 @@ public String category() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> run(), checkPeriod, checkPeriod);
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, check -> run(), checkPeriod, checkPeriod);
}

@Override
Expand All @@ -59,20 +60,15 @@ public void disable() {

private void run() {
for (World world : plugin.getServer().getWorlds()) {
if (!world.getEnvironment().equals(World.Environment.NETHER)) continue;
if (world.getEnvironment() != World.Environment.NETHER) continue;
if (exemptedWorlds.contains(world.getName())) continue;

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

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
ChunkUtil.createBedrockLayer(chunk, ceilingY);
}
});
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 @@ -10,22 +10,23 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PeriodicallyFillNetherFloor implements AnarchyExploitFixesModule {

private final AnarchyExploitFixes plugin;
private ScheduledTask scheduledTask;
private final Set<String> exemptedWorlds;
private final long checkPeriod;
private final double pauseTPS;
private final boolean checkShouldPauseOnLowTPS;
private final HashSet<String> exemptedWorlds = new HashSet<>();

public PeriodicallyFillNetherFloor() {
shouldEnable();
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
this.checkPeriod = config.getInt("bedrock.fill-in-bedrock.nether-floor.periodically-check-and-fill.check-period-in-seconds", 10) * 20L;
this.exemptedWorlds.addAll(config.getList("bedrock.fill-in-bedrock.nether-floor.exempted-worlds", List.of("exampleworld", "exampleworld2")));
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.fill-in-bedrock.nether-floor.exempted-worlds", List.of("exampleworld", "exampleworld2")));
this.checkShouldPauseOnLowTPS = config.getBoolean("bedrock.fill-in-bedrock.nether-floor.periodically-check-and-fill.pause-on-low-tps", true);
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.nether-floor.periodically-check-and-fill.pause-tps", 16.0);
}
Expand All @@ -42,7 +43,7 @@ public String category() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> run(), checkPeriod, checkPeriod);
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, check -> run(), checkPeriod, checkPeriod);
}

@Override
Expand All @@ -57,20 +58,15 @@ public void disable() {

private void run() {
for (World world : plugin.getServer().getWorlds()) {
if (!world.getEnvironment().equals(World.Environment.NETHER)) continue;
if (world.getEnvironment() != World.Environment.NETHER) continue;
if (exemptedWorlds.contains(world.getName())) continue;

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

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
ChunkUtil.createBedrockLayer(chunk, world.getMinHeight());
}
});
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 @@ -10,23 +10,24 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PeriodicallyFillOverworldFloor implements AnarchyExploitFixesModule {

private final AnarchyExploitFixes plugin;
private ScheduledTask scheduledTask;
private final Set<String> exemptedWorlds;
private final long checkPeriod;
private final double pauseTPS;
private final boolean checkShouldPauseOnLowTPS;
private final HashSet<String> exemptedWorlds = new HashSet<>();

public PeriodicallyFillOverworldFloor() {
shouldEnable();
plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("bedrock.fill-in-bedrock.overworld-floor.periodically-check-and-fill.enable","only checks loaded chunks");
this.checkPeriod = config.getInt("bedrock.fill-in-bedrock.overworld-floor.periodically-check-and-fill.check-period-in-seconds", 10) * 20L;
this.exemptedWorlds.addAll(config.getList("bedrock.fill-in-bedrock.overworld-floor.exempted-worlds", List.of("exampleworld", "exampleworld2")));
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.fill-in-bedrock.overworld-floor.exempted-worlds", List.of("exampleworld", "exampleworld2")));
this.checkShouldPauseOnLowTPS = config.getBoolean("bedrock.fill-in-bedrock.overworld-floor.periodically-check-and-fill.pause-on-low-tps", true);
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.overworld-floor.periodically-check-and-fill.pause-tps", 16.0);
}
Expand All @@ -43,7 +44,7 @@ public String category() {

@Override
public void enable() {
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> run(), checkPeriod, checkPeriod);
this.scheduledTask = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, check -> run(), checkPeriod, checkPeriod);
}

@Override
Expand All @@ -58,20 +59,15 @@ public void disable() {

private void run() {
for (World world : plugin.getServer().getWorlds()) {
if (!world.getEnvironment().equals(World.Environment.NORMAL)) continue;
if (world.getEnvironment() != World.Environment.NORMAL) continue;
if (exemptedWorlds.contains(world.getName())) continue;

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

plugin.getServer().getRegionScheduler().run(plugin, world, chunkX, chunkZ, task -> {
Chunk.LoadLevel level = chunk.getLoadLevel();
if (level.equals(Chunk.LoadLevel.ENTITY_TICKING) || level.equals(Chunk.LoadLevel.TICKING)) {
ChunkUtil.createBedrockLayer(chunk, world.getMinHeight());
}
});
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 @@ -16,18 +16,19 @@

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;

public class PreventGoingBelowBedrockFloor implements AnarchyExploitFixesModule, Listener {

private final HashSet<String> exemptedWorlds = new HashSet<>();
private final Set<String> exemptedWorlds;
private final Material fillMaterial;

public PreventGoingBelowBedrockFloor() {
shouldEnable();
Config config = AnarchyExploitFixes.getConfiguration();
config.addComment("bedrock.prevent-going-below-bedrock-floor.enable", "Fills the bedrock hole and teleports player above.");
this.exemptedWorlds.addAll(config.getList("bedrock.prevent-going-below-bedrock-floor.exempted-worlds", List.of("world_the_end", "skyblock_world")));
this.exemptedWorlds = new HashSet<>(config.getList("bedrock.prevent-going-below-bedrock-floor.exempted-worlds", List.of("world_the_end", "skyblock_world")));
String configuredFillMaterial = config.getString("bedrock.prevent-going-below-bedrock-floor.filler-material", "BEDROCK");
Material filler_material = Material.BEDROCK;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private boolean isSuspectedScanPacket(String buffer) {
private void onAsyncCommandTabComplete(AsyncTabCompleteEvent event) {
if (event.getSender().hasPermission("anarchyexploitfixes.chatbypass")) return;
if (!(event.getSender() instanceof Player)) return;
if (isSuspectedScanPacket(event.getBuffer())) {
if (this.isSuspectedScanPacket(event.getBuffer())) {
event.setCancelled(true);
}
}
Expand All @@ -63,7 +63,7 @@ private void onAsyncCommandTabComplete(AsyncTabCompleteEvent event) {
private void onCommandTabComplete(TabCompleteEvent event) {
if (event.getSender().hasPermission("anarchyexploitfixes.chatbypass")) return;
if (!(event.getSender() instanceof Player)) return;
if (isSuspectedScanPacket(event.getBuffer())) {
if (this.isSuspectedScanPacket(event.getBuffer())) {
event.setCancelled(true);
}
}
Expand Down
Loading

0 comments on commit 9d952e5

Please sign in to comment.