Skip to content

Commit

Permalink
more legacy optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Mar 8, 2024
1 parent 4d72bdb commit c78fb9b
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Map;
import java.util.logging.Level;

public class CustomEntityLimit implements AnarchyExploitFixesModule, Listener, Runnable {
public class CustomEntityLimit implements AnarchyExploitFixesModule, Runnable, Listener {

private final AnarchyExploitFixes plugin;
private final Map<EntityType, Integer> entityLimits = new HashMap<>();
Expand All @@ -36,83 +36,83 @@ public CustomEntityLimit() {
this.checkPeriod = config.getInt("chunk-limits.entity-limits.custom-limit.check-period-in-ticks", 1200,
"Check all chunks every x ticks.");

Map<String, Object> defaults = new HashMap<>();
defaults.put("WITHER", 16);
defaults.put("WITHER_SKULL", 10);
defaults.put("BLAZE", 10);
defaults.put("CREEPER", 10);
defaults.put("ENDERMAN", 10);
defaults.put("MAGMA_CUBE", 10);
defaults.put("PHANTOM", 10);
defaults.put("SLIME", 10);
defaults.put("SKELETON", 10);
defaults.put("STRAY", 10);
defaults.put("WITHER_SKELETON", 10);
defaults.put("SPIDER", 10);
defaults.put("CAVE_SPIDER", 10);
defaults.put("ZOMBIE", 10);
defaults.put("DROWNED", 10);
defaults.put("HUSK", 10);
defaults.put("PIGLIN_BRUTE", 10);
defaults.put("ZOMBIFIED_PIGLIN", 20);
defaults.put("HOGLIN", 10);
defaults.put("ZOGLIN", 10);
defaults.put("CHICKEN", 10);
defaults.put("PIG", 10);
defaults.put("SHEEP", 10);
defaults.put("COW", 10);
defaults.put("MUSHROOM_COW", 10);
defaults.put("WOLF", 10);
defaults.put("DONKEY", 10);
defaults.put("HORSE", 10);
defaults.put("MULE", 10);
defaults.put("SKELETON_HORSE", 10);
defaults.put("ZOMBIE_HORSE", 10);
defaults.put("GOAT", 10);
defaults.put("LLAMA", 10);
defaults.put("TRADER_LLAMA", 10);
defaults.put("BAT", 3);
defaults.put("CAT", 10);
defaults.put("OCELOT", 3);
defaults.put("DOLPHIN", 4);
defaults.put("ENDERMITE", 3);
defaults.put("FOX", 10);
defaults.put("PANDA", 5);
defaults.put("PARROT", 10);
defaults.put("POLAR_BEAR", 5);
defaults.put("RABBIT", 5);
defaults.put("SILVERFISH", 3);
defaults.put("STRIDER", 3);
defaults.put("EVOKER", 15);
defaults.put("VEX", 15);
defaults.put("PILLAGER", 15);
defaults.put("VINDICATOR", 15);
defaults.put("WITCH", 15);
defaults.put("RAVAGER", 15);
defaults.put("AXOLOTL", 10);
defaults.put("COD", 6);
defaults.put("SALMON", 6);
defaults.put("TROPICAL_FISH", 6);
defaults.put("PUFFERFISH", 3);
defaults.put("SQUID", 20);
defaults.put("GLOW_SQUID", 20);
defaults.put("FROG", 20);
defaults.put("TADPOLE", 20);
defaults.put("ALLAY", 20);
defaults.put("BEE", 15);
defaults.put("TURTLE", 20);
defaults.put("GUARDIAN", 20);
defaults.put("PIGLIN", 25);
defaults.put("IRON_GOLEM", 15);
defaults.put("ZOMBIE_VILLAGER", 25);
defaults.put("WANDERING_TRADER", 10);
Map<String, Integer> universal = new HashMap<>();
universal.put("WITHER", 16);
universal.put("WITHER_SKULL", 10);
universal.put("BLAZE", 10);
universal.put("CREEPER", 10);
universal.put("ENDERMAN", 10);
universal.put("MAGMA_CUBE", 10);
universal.put("PHANTOM", 10);
universal.put("SLIME", 10);
universal.put("SKELETON", 10);
universal.put("STRAY", 10);
universal.put("WITHER_SKELETON", 10);
universal.put("SPIDER", 10);
universal.put("CAVE_SPIDER", 10);
universal.put("ZOMBIE", 10);
universal.put("DROWNED", 10);
universal.put("HUSK", 10);
universal.put("PIGLIN_BRUTE", 10);
universal.put("ZOMBIFIED_PIGLIN", 20);
universal.put("HOGLIN", 10);
universal.put("ZOGLIN", 10);
universal.put("CHICKEN", 10);
universal.put("PIG", 10);
universal.put("SHEEP", 10);
universal.put("COW", 10);
universal.put("MUSHROOM_COW", 10);
universal.put("WOLF", 10);
universal.put("DONKEY", 10);
universal.put("HORSE", 10);
universal.put("MULE", 10);
universal.put("SKELETON_HORSE", 10);
universal.put("ZOMBIE_HORSE", 10);
universal.put("GOAT", 10);
universal.put("LLAMA", 10);
universal.put("TRADER_LLAMA", 10);
universal.put("BAT", 3);
universal.put("CAT", 10);
universal.put("OCELOT", 3);
universal.put("DOLPHIN", 4);
universal.put("ENDERMITE", 3);
universal.put("FOX", 10);
universal.put("PANDA", 5);
universal.put("PARROT", 10);
universal.put("POLAR_BEAR", 5);
universal.put("RABBIT", 5);
universal.put("SILVERFISH", 3);
universal.put("STRIDER", 3);
universal.put("EVOKER", 15);
universal.put("VEX", 15);
universal.put("PILLAGER", 15);
universal.put("VINDICATOR", 15);
universal.put("WITCH", 15);
universal.put("RAVAGER", 15);
universal.put("AXOLOTL", 10);
universal.put("COD", 6);
universal.put("SALMON", 6);
universal.put("TROPICAL_FISH", 6);
universal.put("PUFFERFISH", 3);
universal.put("SQUID", 20);
universal.put("GLOW_SQUID", 20);
universal.put("FROG", 20);
universal.put("TADPOLE", 20);
universal.put("ALLAY", 20);
universal.put("BEE", 15);
universal.put("TURTLE", 20);
universal.put("GUARDIAN", 20);
universal.put("PIGLIN", 25);
universal.put("IRON_GOLEM", 15);
universal.put("ZOMBIE_VILLAGER", 25);
universal.put("WANDERING_TRADER", 10);

Map<String, Object> compatible = new HashMap<>();
for (Map.Entry<String, Object> entry : defaults.entrySet()) {
for (Map.Entry<String, Integer> entry : universal.entrySet()) {
try {
EntityType entityType = EntityType.valueOf(entry.getKey());
compatible.put(entityType.name(), entry.getValue());
} catch (IllegalArgumentException e) {}
} catch (IllegalArgumentException ignored) {}
}

ConfigSection section = config.getConfigSection("chunk-limits.entity-limits.custom-limit.limited-types", compatible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public FallingBlockLimit() {
this.logIsEnabled = config.getBoolean("chunk-limits.falling-block-limit.log", false);
this.maxFallingGravityBlockPerChunk = config.getInt("chunk-limits.falling-block-limit.max-falling-gravitiy-blocks-per-chunk", 60,
"Removes any falling block if there is more than x blocks (actively) falling in a chunk.");
final long chunkCheckDelay = Math.max(config.getInt("chunk-limits.falling-block-limit.chunk-check-delay-in-ticks", 20,
this.checkedChunks = new ExpiringSet<>(Duration.ofMillis(
Math.max(1, config.getInt("chunk-limits.falling-block-limit.chunk-check-delay-in-ticks", 20,
"Delay in ticks until the same chunk can be checked again.\n" +
"Prevents overchecking because a physics event can be called multiple times for the same chunk."), 1) * 50L;
this.checkedChunks = new ExpiringSet<>(Duration.ofMillis(chunkCheckDelay));
"Prevents overchecking because a physics event can be called multiple times for the same chunk.")) * 50L
));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public MinecartLimit() {
"Limit the amount of minecarts to prevent lag.");
this.logIsEnabled = config.getBoolean("chunk-limits.minecart-limit.log-removals", false);
this.maxMinecartsPerChunk = config.getInt("chunk-limits.minecart-limit.max-minecarts-per-chunk", 25);
this.checkPeriod = Math.max(config.getInt("chunk-limits.minecart-limit.check-period-in-ticks", 400,
"200 ticks = 10 seconds."), 1);
this.checkPeriod = Math.max(1, config.getInt("chunk-limits.minecart-limit.check-period-in-ticks", 400,
"200 ticks = 10 seconds."));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public NonLivingEntityLimit() {
"Limit the amount of non living entities in a chunk to prevent lag (does not affect items).");
this.logIsEnabled = config.getBoolean("chunk-limits.entity-limits.non-living-limit.log-removals", true);
this.maxNonLivingEntities = config.getInt("chunk-limits.entity-limits.non-living-limit.max-non-living-per-chunk", 100);
this.checkPeriod = config.getInt("chunk-limits.entity-limits.non-living-limit.check-period-in-ticks", 20,
"20 ticks = 1 second");
this.checkPeriod = Math.max(1, config.getInt("chunk-limits.entity-limits.non-living-limit.check-period-in-ticks", 20,
"20 ticks = 1 second"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public VehicleLimit() {
"Limit the amount of vehicles to prevent some lag machines involving boats and a dispenser.");
this.logIsEnabled = config.getBoolean("chunk-limits.vehicle-limit.log-removals", false);
this.maxVehiclesPerChunk = config.getInt("chunk-limits.vehicle-limit.max-vehicles-per-chunk", 25);
this.checkPeriod = config.getInt("chunk-limits.vehicle-limit.check-period-in-ticks", 400, "200 ticks = 10 seconds.");
this.checkPeriod = Math.max(1, config.getInt("chunk-limits.vehicle-limit.check-period-in-ticks", 400,
"200 ticks = 10 seconds."));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Objects;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class VillagerLimit implements AnarchyExploitFixesModule, Runnable, Listener {

Expand All @@ -35,11 +36,19 @@ public VillagerLimit() {
Config config = AnarchyExploitFixes.getConfiguration();
this.maxVillagersPerChunk = Math.max(config.getInt("chunk-limits.entity-limits.villager-limit.max-villagers-per-chunk", 25), 1);
this.logIsEnabled = config.getBoolean("chunk-limits.entity-limits.villager-limit.log-removals", false);
this.checkPeriod = Math.max(config.getInt("chunk-limits.entity-limits.villager-limit.check-period-in-ticks", 600,
"check all chunks every x ticks."), 1);
this.removalPriority = config.getList("chunk-limits.entity-limits.villager-limit.removal-priority", Arrays.asList(
"NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER", "LEATHERWORKER", "FLETCHER",
"MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN"),
this.checkPeriod = Math.max(1, config.getInt("chunk-limits.entity-limits.villager-limit.check-period-in-ticks", 600,
"check all chunks every x ticks."));
final List<String> universal = Stream.of("NONE", "NITWIT", "SHEPHERD", "FISHERMAN", "BUTCHER", "CARTOGRAPHER",
"LEATHERWORKER", "FLETCHER", "MASON", "FARMER", "ARMORER", "TOOLSMITH", "WEAPONSMITH", "CLERIC", "LIBRARIAN")
.filter(prof -> {
try {
Villager.Profession.valueOf(prof);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}).collect(Collectors.toList());
this.removalPriority = config.getList("chunk-limits.entity-limits.villager-limit.removal-priority", universal,
"Professions that are in the top of the list are going to be scheduled for removal first.")
.stream()
.map(configuredProfession -> {
Expand Down

0 comments on commit c78fb9b

Please sign in to comment.