Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: Should we sanitize enum names? #3656

Merged
merged 1 commit into from
May 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private void loadEnumRegistries() {
this.knownName(RegistryTypes.BANNER_PATTERN_SHAPE, BannerPattern.values(), b -> ((BannerPatternAccessor) (Object) b).accessor$filename());
this.automaticName(RegistryTypes.TROPICAL_FISH_SHAPE, TropicalFish.Pattern.values());
this.automaticName(RegistryTypes.HEIGHT_TYPE, Heightmap.Types.values());
this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), MobCategory::getName);
this.knownName(RegistryTypes.ENTITY_CATEGORY, MobCategory.values(), VanillaRegistryLoader.sanitizedName(MobCategory::getName));
}

private static RegistryLoader<Criterion> criterion() {
Expand Down Expand Up @@ -293,7 +293,7 @@ private static RegistryLoader<Trigger<?>> trigger() {

@SuppressWarnings("UnusedReturnValue")
private <A, I extends Enum<I>> Registry<A> automaticName(final RegistryType<A> type, final I[] values) {
return this.naming(type, values, value -> value.name().toLowerCase(Locale.ROOT));
return this.naming(type, values, VanillaRegistryLoader.sanitizedName(Enum::name));
}

@SuppressWarnings("UnusedReturnValue")
Expand Down Expand Up @@ -363,4 +363,8 @@ private <A, I> Registry<A> naming(final RegistryType<A> type, final int values,
private interface Manual<A, I> {
void put(final I value, final String key);
}

private static <I> Function<I, String> sanitizedName(final Function<I, String> original) {
return original.andThen(s -> s.toLowerCase(Locale.ROOT));
}
}