Skip to content

Commit

Permalink
curate chunk-limits
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 2, 2024
1 parent f7e98cd commit 8071f9a
Show file tree
Hide file tree
Showing 23 changed files with 594 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public FillNetherCeilingOnChunkload() {
this.plugin = AnarchyExploitFixes.getInstance();
Config config = AnarchyExploitFixes.getConfiguration();
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"), "Case sensitive!"));
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"),
"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, "The TPS at which bedrock filling will pause to avoid lag.");
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.nether-ceiling.fill-on-chunkload.pause-tps", 16.0,
"The TPS at which bedrock filling will pause to avoid lag.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public FillNetherFloorOnChunkload() {
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"), "Case sensitive!"));
this.exemptedWorlds.addAll(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
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ 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"), "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.");
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.overworld-floor.fill-on-chunkload.pause-tps", 16.0, "The TPS at which bedrock filling will pause.");
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"),
"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.");
this.pauseTPS = config.getDouble("bedrock.fill-in-bedrock.overworld-floor.fill-on-chunkload.pause-tps", 16.0,
"The TPS at which bedrock filling will pause.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ public class CWChatPacketListener extends PacketAdapter {
private final HashSet<String> bannedSubCommands;
private final boolean shouldLog;

protected CWChatPacketListener(
AnarchyExploitFixes plugin,
HashSet<String> allowedCommands,
HashSet<String> bannedSubCommands,
boolean shouldLog
) {
protected CWChatPacketListener(AnarchyExploitFixes plugin, HashSet<String> allowedCommands, HashSet<String> bannedSubCommands, boolean shouldLog) {
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT);
this.allowedCommands = allowedCommands;
this.bannedSubCommands = bannedSubCommands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ public CommandWhitelist() {
"This will make it pretty much impossible to find your plugins as only the commands you specify will be able to work.\n" +
"Allow bypass using permission: anarchyexploitfixes.commandwhitelistbypass"
);
this.shouldLog = config.getBoolean("chat.command-whitelist.log", false, "Will show logs when a command was denied.");
this.shouldUseProtocolLib = config.getBoolean("chat.command-whitelist.use-protocollib", false, "Enable only if you have problems with the regular commandwhitelist. Otherwise not recommended to use.");
this.shouldLog = config.getBoolean("chat.command-whitelist.log", false,
"Will show logs when a command was denied.");
this.shouldUseProtocolLib = config.getBoolean("chat.command-whitelist.use-protocollib", false,
"Enable only if you have problems with the regular commandwhitelist. Otherwise not recommended to use.");
config.getList("chat.command-whitelist.whitelisted-commands", List.of(
"help", "vote", "kill", "discord", "togglechat", "toggleconnectionmsgs", "toggletells", "togglewhispering", "toggleprivatemsgs",
"ignore", "ignorelist", "ignorehard", "toggledeathmsg", "dmt", "worldstats", "stats", "tps", "msg", "whisper", "w", "m", "t",
"pm", "tell", "r", "reply", "last"
), "Add all commands you want your players to be able to access (without the '/'). Not case sensitive.").forEach(configuredAllowedCmd -> this.allowedCommands.add(configuredAllowedCmd.toLowerCase()));
), "Add all commands you want your players to be able to access (without the '/'). Not case sensitive."
).forEach(configuredAllowedCmd -> this.allowedCommands.add(configuredAllowedCmd.toLowerCase()));
bannedSubCommands.addAll(config.getList("chat.command-whitelist.blacklisted-subcommands", List.of(
"help about", "vote List", "vote Best", "vote Total", "worldstats reload", "stats reload"
)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public BlockLimit() {
defaults.put("YELLOW_BANNER", 12);
defaults.put("YELLOW_WALL_BANNER", 12);

ConfigSection section = AnarchyExploitFixes.getConfiguration().getConfigSection("chunk-limits.block-limit.max-blocks-per-chunk", defaults, "Attempt to prevent ChunkBan / Client FPS Lag");
ConfigSection section = AnarchyExploitFixes.getConfiguration().getConfigSection("chunk-limits.block-limit.max-blocks-per-chunk", defaults,
"Attempt to prevent ChunkBan / Client FPS Lag");
for (String configuredMaterial : section.getKeys(false)) {
try {
Material blockMaterial = Material.valueOf(configuredMaterial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
public class CustomEntityLimit implements AnarchyExploitFixesModule, Listener {

private final AnarchyExploitFixes plugin;
private ScheduledTask scheduledTask;
private final HashMap<EntityType, Integer> entityLimits = new HashMap<>();
private final boolean logIsEnabled, enableChunkAgeSkip, forceLoadEntities;
private ScheduledTask scheduledTask;
private final long checkPeriod, minChunkAge;
private final boolean logIsEnabled, enableChunkAgeSkip, forceLoadEntities;

public CustomEntityLimit() {
shouldEnable();
Expand Down Expand Up @@ -157,58 +157,56 @@ public void disable() {
if (scheduledTask != null) scheduledTask.cancel();
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onSpawn(EntitySpawnEvent event) {
final EntityType spawnedType = event.getEntityType();
if (!entityLimits.containsKey(spawnedType)) return;

final int maxAllowed = entityLimits.get(spawnedType);
final int maxAllowedPerChunk = entityLimits.get(spawnedType);
int entityCount = 0;

for (Entity entity : event.getEntity().getChunk().getEntities()) {
int count = 0;
if (entity.getType().equals(spawnedType)) {
count++;
if (count > maxAllowed) {
entity.getScheduler().run(plugin, kill -> entity.remove(), null);
if (logIsEnabled) LogUtils.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType()
+ " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ()
+ " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowed
);
}
}
if (!entity.getType().equals(spawnedType)) continue;

entityCount++;
if (entityCount <= maxAllowedPerChunk) continue;

entity.getScheduler().run(plugin, kill -> entity.remove(), null);
if (logIsEnabled) LogUtils.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType()
+ " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ()
+ " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowedPerChunk);
}
}

private void run() {
for (World world : plugin.getServer().getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) {
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), task -> {
plugin.getServer().getRegionScheduler().run(plugin, world, chunk.getX(), chunk.getZ(), chunkCheck -> {
if (!forceLoadEntities && !chunk.isEntitiesLoaded()) return;
if (enableChunkAgeSkip && chunk.getInhabitedTime() < minChunkAge) return;

Entity[] chunkEntities = chunk.getEntities();

for (Map.Entry<EntityType, Integer> limit : entityLimits.entrySet()) {

final int maxAllowed = limit.getValue();
int count = 0;
final int maxAllowedPerChunk = limit.getValue();
int entityCount = 0;

for (Entity entity : chunkEntities) {
if (entity.getType().equals(limit.getKey())) {
count++;
if (count > maxAllowed) {
entity.getScheduler().run(plugin, kill -> {
entity.remove();
if (logIsEnabled) LogUtils.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType()
+ " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ()
+ " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowed
);
}, null);
}
}
if (!entity.getType().equals(limit.getKey())) continue;

entityCount++;
if (entityCount <= maxAllowedPerChunk) continue;

entity.getScheduler().run(plugin, kill -> {
entity.remove();
if (logIsEnabled) LogUtils.moduleLog(Level.INFO, name(), "Removed entity " + entity.getType()
+ " at x:" + entity.getLocation().getX() + " y:" + entity.getLocation().getY() + " z:" + entity.getLocation().getZ()
+ " in "+entity.getWorld().getName()+" because reached limit of " + maxAllowedPerChunk);
}, null);
}
}
});
}
}
}
}
}
Loading

0 comments on commit 8071f9a

Please sign in to comment.