Skip to content

Commit

Permalink
Changed all #toLowerCase and #toUpperCase methods to use English Loca…
Browse files Browse the repository at this point in the history
…le instead of default
  • Loading branch information
Artemis-the-gr8 committed Feb 1, 2023
1 parent 6678778 commit 4e945ad
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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 {
Expand Down Expand Up @@ -88,7 +89,7 @@ private List<String> getFirstArgSuggestions(String currentArg) {

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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

public final class TabCompleteHelper {
Expand Down Expand Up @@ -43,15 +44,15 @@ private static void prepareLists() {
.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
entitySuggestions = Arrays.stream(EntityType.values())
.parallel()
.filter(EntityType::isAlive)
.map(EntityType::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
}
}
15 changes: 4 additions & 11 deletions src/main/java/com/artemis/the/gr8/playerstats/enums/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
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}.
Expand Down Expand Up @@ -131,15 +133,6 @@ public double getSeconds() {
};
}

/**
* 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) {
Expand All @@ -155,7 +148,7 @@ public char getShortLabel(){
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;
Expand All @@ -179,7 +172,7 @@ match exactly (it can be "day" or "days", for example), and is case-insensitive.
* @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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;

/**
*
Expand Down Expand Up @@ -239,8 +240,8 @@ else if (item.isBlock()) {
*/
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;
}
Expand All @@ -264,7 +265,7 @@ else if (block.toString().toLowerCase().contains("wall_banner")) { //replace wa
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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.
Expand All @@ -18,7 +20,7 @@ private 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...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;

Expand Down Expand Up @@ -80,7 +81,7 @@ public List<String> getStatNames() {
*/
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;
Expand Down Expand Up @@ -109,7 +110,7 @@ public List<String> getStatNames() {
*/
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;
Expand All @@ -123,7 +124,7 @@ public List<String> getStatNames() {
* @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));
}

/**
Expand All @@ -147,7 +148,7 @@ public boolean isEntityStatistic(String statName) {
* of Type.Untyped
*/
public boolean isSubStatEntry(@NotNull String statName) {
return subStatNames.contains(statName.toLowerCase());
return subStatNames.contains(statName.toLowerCase(Locale.ENGLISH));
}

/**
Expand All @@ -171,20 +172,20 @@ public static String getSubStatTypeName(Statistic.Type statType) {
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)
Expand All @@ -194,7 +195,7 @@ private void prepareLists() {

statNames = Arrays.stream(Statistic.values())
.map(Statistic::toString)
.map(String::toLowerCase)
.map(string -> string.toLowerCase(Locale.ENGLISH))
.collect(Collectors.toList());
}
}

0 comments on commit 4e945ad

Please sign in to comment.