Skip to content

Commit

Permalink
Prevent EntityTypeListSetting suggesting and accepting filtered value…
Browse files Browse the repository at this point in the history
…s in commands
  • Loading branch information
Wide-Cat committed Aug 6, 2024
1 parent 7f74c25 commit 31e879e
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class EntityTypeListSetting extends Setting<Set<EntityType<?>>> {
public final Predicate<EntityType<?>> filter;
private static List<String> suggestions;
private List<String> suggestions;
private final static List<String> groups = List.of("animal", "wateranimal", "monster", "ambient", "misc");

public EntityTypeListSetting(String name, String description, Set<EntityType<?>> defaultValue, Consumer<Set<EntityType<?>>> onChanged, Consumer<Setting<Set<EntityType<?>>>> onModuleActivated, IVisible visible, Predicate<EntityType<?>> filter) {
Expand All @@ -51,7 +51,9 @@ protected Set<EntityType<?>> parseImpl(String str) {
String lowerValue = value.trim().toLowerCase();
if (!groups.contains(lowerValue)) continue;

Registries.ENTITY_TYPE.forEach(entityType -> {
for (EntityType<?> entityType : Registries.ENTITY_TYPE) {
if (filter != null && !filter.test(entityType)) continue;

switch (lowerValue) {
case "animal" -> {
if (entityType.getSpawnGroup() == SpawnGroup.CREATURE) entities.add(entityType);
Expand All @@ -72,7 +74,7 @@ protected Set<EntityType<?>> parseImpl(String str) {
if (entityType.getSpawnGroup() == SpawnGroup.MISC) entities.add(entityType);
}
}
});
}
}
}
} catch (Exception ignored) {}
Expand All @@ -89,7 +91,9 @@ protected boolean isValueValid(Set<EntityType<?>> value) {
public List<String> getSuggestions() {
if (suggestions == null) {
suggestions = new ArrayList<>(groups);
Registries.ENTITY_TYPE.getIds().forEach(id -> suggestions.add(id.toString()));
for (EntityType<?> entityType : Registries.ENTITY_TYPE) {
if (filter == null || filter.test(entityType)) suggestions.add(Registries.ENTITY_TYPE.getId(entityType).toString());
}
}

return suggestions;
Expand Down

0 comments on commit 31e879e

Please sign in to comment.