Skip to content

Commit

Permalink
Localize access type and source type (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
rymiel authored Feb 12, 2024
1 parent 5bec292 commit 431cb46
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions bukkit/src/main/java/org/popcraft/bolt/util/Protections.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ public static Component protectionType(final Protection protection, final Comman
return BoltComponents.resolveTranslation(translationKey, sender);
}

public static Component sourceType(final Source source, final CommandSender sender) {
final String sourceType = source.getType();
final String translationKey = "source_type_%s".formatted(sourceType);
if (!isTranslatable(translationKey, getLocaleOf(sender))) {
return Component.text(Strings.toTitleCase(sourceType));
}
return BoltComponents.resolveTranslation(translationKey, sender);
}

public static Component accessType(final String accessType, final CommandSender sender) {
final String translationKey = "access_type_%s".formatted(accessType);
if (!isTranslatable(translationKey, getLocaleOf(sender))) {
return Component.text(Strings.toTitleCase(accessType));
}
return BoltComponents.resolveTranslation(translationKey, sender);
}

public static Component displayType(final Protection protection, final CommandSender sender) {
if (protection instanceof final BlockProtection blockProtection) {
final World world = Bukkit.getWorld(blockProtection.getWorld());
Expand Down Expand Up @@ -172,16 +189,16 @@ public static Component accessList(final Map<String, String> accessMap, final Co
Translation.ACCESS_LIST_ENTRY_DEFAULT,
sender,
Placeholder.component(Translation.Placeholder.SOURCE_IDENTIFIER, Component.text(subject)),
Placeholder.component(Translation.Placeholder.SOURCE_TYPE, Component.text(Strings.toTitleCase(source.getType()))),
Placeholder.component(Translation.Placeholder.ACCESS_TYPE, Component.text(Strings.toTitleCase(access)))
Placeholder.component(Translation.Placeholder.SOURCE_TYPE, sourceType(source, sender)),
Placeholder.component(Translation.Placeholder.ACCESS_TYPE, accessType(access, sender))
));
} else {
list.add(resolveTranslation(
Translation.ACCESS_LIST_ENTRY,
sender,
Placeholder.component(Translation.Placeholder.SOURCE_IDENTIFIER, Component.text(subject)),
Placeholder.component(Translation.Placeholder.SOURCE_TYPE, Component.text(Strings.toTitleCase(source.getType()))),
Placeholder.component(Translation.Placeholder.ACCESS_TYPE, Component.text(Strings.toTitleCase(access)))
Placeholder.component(Translation.Placeholder.SOURCE_TYPE, sourceType(source, sender)),
Placeholder.component(Translation.Placeholder.ACCESS_TYPE, accessType(access, sender))
));
}
}
Expand Down

0 comments on commit 431cb46

Please sign in to comment.