Skip to content

Commit

Permalink
add ability to toggle whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 1, 2024
1 parent 4e71c62 commit 42555c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class VillagerLimit extends AEFModule implements Consumer<ScheduledTask>,
private final Set<Villager.Profession> professionWhitelist;
private final long checkPeriod;
private final int maxVillagersPerChunk;
private final boolean logIsEnabled;
private final boolean logIsEnabled, whitelistEnabled;

public VillagerLimit() {
super("chunk-limits.entity-limits.villager-limit");
Expand Down Expand Up @@ -75,7 +75,8 @@ public VillagerLimit() {
}
})
.collect(Collectors.toList());
this.professionWhitelist = config.getList(configPath + ".removal-whitelist", defWhitelist)
this.whitelistEnabled = config.getBoolean(configPath + ".whitelist.enable", false);
this.professionWhitelist = config.getList(configPath + ".whitelist.professions", defWhitelist)
.stream()
.map(configuredProfession -> {
try {
Expand Down Expand Up @@ -135,7 +136,7 @@ private void checkVillagersInChunk(Chunk chunk) {
final List<Villager> villagers_in_chunk = new ArrayList<>();
for (Entity entity : entities) {
Villager villager = (Villager) entity;
if (!professionWhitelist.contains(villager.getProfession())) {
if (whitelistEnabled && !professionWhitelist.contains(villager.getProfession())) {
villagers_in_chunk.add(villager);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class VillagerLimit extends AEFModule implements Runnable, Listener {
private final Set<Villager.Profession> professionWhitelist;
private final long checkPeriod;
private final int maxVillagersPerChunk;
private final boolean logIsEnabled;
private final boolean logIsEnabled, whitelistEnabled;
private BukkitTask bukkitTask;

public VillagerLimit() {
Expand Down Expand Up @@ -61,7 +61,9 @@ public VillagerLimit() {
}
})
.collect(Collectors.toList());
this.professionWhitelist = config.getList(configPath + ".removal-whitelist", defWhitelist)
this.removalPriority = config.getList(configPath + ".removal-priority", defPriority,
"Professions that are in the top of the list are going to be scheduled\n" +
"for removal first.")
.stream()
.map(configuredProfession -> {
try {
Expand All @@ -72,10 +74,9 @@ public VillagerLimit() {
}
})
.filter(Objects::nonNull)
.collect(Collectors.toCollection(HashSet::new));
this.removalPriority = config.getList(configPath + ".removal-priority", defPriority,
"Professions that are in the top of the list are going to be scheduled\n" +
"for removal first.")
.collect(Collectors.toList());
this.whitelistEnabled = config.getBoolean(configPath + ".whitelist.enable", false);
this.professionWhitelist = config.getList(configPath + ".whitelist.professions", defWhitelist)
.stream()
.map(configuredProfession -> {
try {
Expand All @@ -86,7 +87,7 @@ public VillagerLimit() {
}
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
.collect(Collectors.toCollection(HashSet::new));
}

@Override
Expand Down Expand Up @@ -133,7 +134,7 @@ private void checkVillagersInChunk(Chunk chunk) {
for (Entity entity : entities) {
if (entity.getType() == EntityType.VILLAGER) {
Villager villager = (Villager) entity;
if (!professionWhitelist.contains(villager.getProfession())) {
if (whitelistEnabled && !professionWhitelist.contains(villager.getProfession())) {
villagers_in_chunk.add(villager);
}
}
Expand Down

0 comments on commit 42555c9

Please sign in to comment.