Changed all #toLowerCase and #toUpperCase methods to use English Locale instead of default

This commit is contained in:
Artemis-the-gr8 2023-02-01 15:12:33 +01:00
parent 6678778e8f
commit 4e945ad0b5
6 changed files with 25 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public final class TabCompleter implements org.bukkit.command.TabCompleter {
@ -88,7 +89,7 @@ public final class TabCompleter implements org.bukkit.command.TabCompleter {
private List<String> getTabSuggestions(List<String> completeList, String currentArg) {
return completeList.stream()
.filter(item -> item.toLowerCase().contains(currentArg.toLowerCase()))
.filter(item -> item.toLowerCase(Locale.ENGLISH).contains(currentArg.toLowerCase(Locale.ENGLISH)))
.collect(Collectors.toList());
}

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.EntityType;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
public final class TabCompleteHelper {
@ -43,7 +44,7 @@ public final class TabCompleteHelper {
.filter(Material::isItem)
.filter(item -> item.getMaxDurability() != 0)
.map(Material::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
//the only statistics dealing with entities are killed_entity and entity_killed_by
@ -51,7 +52,7 @@ public final class TabCompleteHelper {
.parallel()
.filter(EntityType::isAlive)
.map(EntityType::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
}
}

View File

@ -3,6 +3,8 @@ package com.artemis.the.gr8.playerstats.enums;
import org.bukkit.Statistic;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
/**
* All the units PlayerStats can display statistics in, separated
* by {@link Unit.Type}.
@ -131,15 +133,6 @@ public enum Unit {
};
}
/**
* Gets the Unit corresponding to the given String. This String
* does not need to match exactly (it can be "day" or "days",
* for example), and is case-insensitive.
*
* @param unitName the name belonging to the desired Unit,
* case-insensitive
* @return the Unit
*/
/** Converts the current Unit into a short label (and returns a '?' if the current Unit is not of Type TIME)*/
public char getShortLabel(){
return switch (this) {
@ -155,7 +148,7 @@ public enum Unit {
match exactly (it can be "day" or "days", for example), and is case-insensitive.
@param unitName an approximation of the name belonging to the desired Unit, case-insensitive */
public static @NotNull Unit fromString(@NotNull String unitName) {
return switch (unitName.toLowerCase()) {
return switch (unitName.toLowerCase(Locale.ENGLISH)) {
case "cm" -> Unit.CM;
case "m", "block", "blocks" -> Unit.BLOCK;
case "mile", "miles" -> Unit.MILE;
@ -179,7 +172,7 @@ public enum Unit {
* @return the Type of this Unit
*/
public static @NotNull Type getTypeFromStatistic(Statistic statistic) {
String name = statistic.toString().toLowerCase();
String name = statistic.toString().toLowerCase(Locale.ENGLISH);
if (name.contains("one_cm")) {
return Type.DISTANCE;
} else if (name.contains("damage")) {

View File

@ -16,6 +16,7 @@ import org.jetbrains.annotations.ApiStatus.Internal;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
/**
*
@ -239,8 +240,8 @@ public final class LanguageKeyHandler {
*/
public @Nullable String getBlockKey(Material block) {
if (block == null) return null;
else if (block.toString().toLowerCase().contains("wall_banner")) { //replace wall_banner with regular banner, since there is no key for wall banners
String blockName = block.toString().toLowerCase().replace("wall_", "");
else if (block.toString().toLowerCase(Locale.ENGLISH).contains("wall_banner")) { //replace wall_banner with regular banner, since there is no key for wall banners
String blockName = block.toString().toLowerCase(Locale.ENGLISH).replace("wall_", "");
Material newBlock = EnumHandler.getBlockEnum(blockName);
return (newBlock != null) ? "block.minecraft." + newBlock.getKey().getKey() : null;
}
@ -264,7 +265,7 @@ public final class LanguageKeyHandler {
private @NotNull HashMap<Statistic, String> generateStatNameKeys() {
//get the enum names for all statistics first
HashMap<Statistic, String> statNames = new HashMap<>(Statistic.values().length);
Arrays.stream(Statistic.values()).forEach(statistic -> statNames.put(statistic, statistic.toString().toLowerCase()));
Arrays.stream(Statistic.values()).forEach(statistic -> statNames.put(statistic, statistic.toString().toLowerCase(Locale.ENGLISH)));
//replace the ones for which the language key is different from the enum name
statNames.put(Statistic.ARMOR_CLEANED, "clean_armor");

View File

@ -2,6 +2,8 @@ package com.artemis.the.gr8.playerstats.msg.msgutils;
import com.artemis.the.gr8.playerstats.utils.MyLogger;
import java.util.Locale;
/**
* A small utility class that helps make enum constant
* names prettier for output in stat-messages.
@ -18,7 +20,7 @@ public final class StringUtils {
*/
public static String prettify(String input) {
if (input == null) return null;
StringBuilder capitals = new StringBuilder(input.toLowerCase());
StringBuilder capitals = new StringBuilder(input.toLowerCase(Locale.ENGLISH));
capitals.setCharAt(0, Character.toUpperCase(capitals.charAt(0)));
while (capitals.indexOf("_") != -1) {
MyLogger.logHighLevelMsg("Replacing underscores and capitalizing names...");

View File

@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -80,7 +81,7 @@ public final class EnumHandler {
*/
public static @Nullable EntityType getEntityEnum(String entityName) {
try {
return EntityType.valueOf(entityName.toUpperCase());
return EntityType.valueOf(entityName.toUpperCase(Locale.ENGLISH));
}
catch (IllegalArgumentException | NullPointerException e) {
return null;
@ -109,7 +110,7 @@ public final class EnumHandler {
*/
public static @Nullable Statistic getStatEnum(@NotNull String statName) {
try {
return Statistic.valueOf(statName.toUpperCase());
return Statistic.valueOf(statName.toUpperCase(Locale.ENGLISH));
}
catch (IllegalArgumentException e) {
return null;
@ -123,7 +124,7 @@ public final class EnumHandler {
* @return true if this String is a valid Statistic
*/
public boolean isStatistic(@NotNull String statName) {
return statNames.contains(statName.toLowerCase());
return statNames.contains(statName.toLowerCase(Locale.ENGLISH));
}
/**
@ -147,7 +148,7 @@ public final class EnumHandler {
* of Type.Untyped
*/
public boolean isSubStatEntry(@NotNull String statName) {
return subStatNames.contains(statName.toLowerCase());
return subStatNames.contains(statName.toLowerCase(Locale.ENGLISH));
}
/**
@ -171,20 +172,20 @@ public final class EnumHandler {
private void prepareLists() {
List<String> entityNames = Arrays.stream(EntityType.values())
.map(EntityType::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.filter(entityName -> !entityName.equalsIgnoreCase("unknown"))
.collect(Collectors.toList());
blockNames = Arrays.stream(Material.values())
.filter(Material::isBlock)
.map(Material::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
itemNames = Arrays.stream(Material.values())
.filter(Material::isItem)
.map(Material::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
subStatNames = Stream.of(blockNames, entityNames, itemNames)
@ -194,7 +195,7 @@ public final class EnumHandler {
statNames = Arrays.stream(Statistic.values())
.map(Statistic::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
}
}