commit
ba757104a6
|
@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class TabCompleter implements org.bukkit.command.TabCompleter {
|
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) {
|
private List<String> getTabSuggestions(List<String> completeList, String currentArg) {
|
||||||
return completeList.stream()
|
return completeList.stream()
|
||||||
.filter(item -> item.toLowerCase().contains(currentArg.toLowerCase()))
|
.filter(item -> item.toLowerCase(Locale.ENGLISH).contains(currentArg.toLowerCase(Locale.ENGLISH)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class TabCompleteHelper {
|
public final class TabCompleteHelper {
|
||||||
|
@ -43,7 +44,7 @@ public final class TabCompleteHelper {
|
||||||
.filter(Material::isItem)
|
.filter(Material::isItem)
|
||||||
.filter(item -> item.getMaxDurability() != 0)
|
.filter(item -> item.getMaxDurability() != 0)
|
||||||
.map(Material::toString)
|
.map(Material::toString)
|
||||||
.map(String::toLowerCase)
|
.map(string -> string.toLowerCase(Locale.ENGLISH))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
//the only statistics dealing with entities are killed_entity and entity_killed_by
|
//the only statistics dealing with entities are killed_entity and entity_killed_by
|
||||||
|
@ -51,7 +52,7 @@ public final class TabCompleteHelper {
|
||||||
.parallel()
|
.parallel()
|
||||||
.filter(EntityType::isAlive)
|
.filter(EntityType::isAlive)
|
||||||
.map(EntityType::toString)
|
.map(EntityType::toString)
|
||||||
.map(String::toLowerCase)
|
.map(string -> string.toLowerCase(Locale.ENGLISH))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,8 @@ package com.artemis.the.gr8.playerstats.enums;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the units PlayerStats can display statistics in, separated
|
* All the units PlayerStats can display statistics in, separated
|
||||||
* by {@link Unit.Type}.
|
* 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)*/
|
/** Converts the current Unit into a short label (and returns a '?' if the current Unit is not of Type TIME)*/
|
||||||
public char getShortLabel(){
|
public char getShortLabel(){
|
||||||
return switch (this) {
|
return switch (this) {
|
||||||
|
@ -155,7 +148,7 @@ public enum Unit {
|
||||||
match exactly (it can be "day" or "days", for example), and is case-insensitive.
|
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 */
|
@param unitName an approximation of the name belonging to the desired Unit, case-insensitive */
|
||||||
public static @NotNull Unit fromString(@NotNull String unitName) {
|
public static @NotNull Unit fromString(@NotNull String unitName) {
|
||||||
return switch (unitName.toLowerCase()) {
|
return switch (unitName.toLowerCase(Locale.ENGLISH)) {
|
||||||
case "cm" -> Unit.CM;
|
case "cm" -> Unit.CM;
|
||||||
case "m", "block", "blocks" -> Unit.BLOCK;
|
case "m", "block", "blocks" -> Unit.BLOCK;
|
||||||
case "mile", "miles" -> Unit.MILE;
|
case "mile", "miles" -> Unit.MILE;
|
||||||
|
@ -179,7 +172,7 @@ public enum Unit {
|
||||||
* @return the Type of this Unit
|
* @return the Type of this Unit
|
||||||
*/
|
*/
|
||||||
public static @NotNull Type getTypeFromStatistic(Statistic statistic) {
|
public static @NotNull Type getTypeFromStatistic(Statistic statistic) {
|
||||||
String name = statistic.toString().toLowerCase();
|
String name = statistic.toString().toLowerCase(Locale.ENGLISH);
|
||||||
if (name.contains("one_cm")) {
|
if (name.contains("one_cm")) {
|
||||||
return Type.DISTANCE;
|
return Type.DISTANCE;
|
||||||
} else if (name.contains("damage")) {
|
} else if (name.contains("damage")) {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.jetbrains.annotations.ApiStatus.Internal;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -239,8 +240,8 @@ public final class LanguageKeyHandler {
|
||||||
*/
|
*/
|
||||||
public @Nullable String getBlockKey(Material block) {
|
public @Nullable String getBlockKey(Material block) {
|
||||||
if (block == null) return null;
|
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
|
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().replace("wall_", "");
|
String blockName = block.toString().toLowerCase(Locale.ENGLISH).replace("wall_", "");
|
||||||
Material newBlock = EnumHandler.getBlockEnum(blockName);
|
Material newBlock = EnumHandler.getBlockEnum(blockName);
|
||||||
return (newBlock != null) ? "block.minecraft." + newBlock.getKey().getKey() : null;
|
return (newBlock != null) ? "block.minecraft." + newBlock.getKey().getKey() : null;
|
||||||
}
|
}
|
||||||
|
@ -264,7 +265,7 @@ public final class LanguageKeyHandler {
|
||||||
private @NotNull HashMap<Statistic, String> generateStatNameKeys() {
|
private @NotNull HashMap<Statistic, String> generateStatNameKeys() {
|
||||||
//get the enum names for all statistics first
|
//get the enum names for all statistics first
|
||||||
HashMap<Statistic, String> statNames = new HashMap<>(Statistic.values().length);
|
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
|
//replace the ones for which the language key is different from the enum name
|
||||||
statNames.put(Statistic.ARMOR_CLEANED, "clean_armor");
|
statNames.put(Statistic.ARMOR_CLEANED, "clean_armor");
|
||||||
|
|
|
@ -2,6 +2,8 @@ package com.artemis.the.gr8.playerstats.msg.msgutils;
|
||||||
|
|
||||||
import com.artemis.the.gr8.playerstats.utils.MyLogger;
|
import com.artemis.the.gr8.playerstats.utils.MyLogger;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A small utility class that helps make enum constant
|
* A small utility class that helps make enum constant
|
||||||
* names prettier for output in stat-messages.
|
* names prettier for output in stat-messages.
|
||||||
|
@ -18,7 +20,7 @@ public final class StringUtils {
|
||||||
*/
|
*/
|
||||||
public static String prettify(String input) {
|
public static String prettify(String input) {
|
||||||
if (input == null) return null;
|
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)));
|
capitals.setCharAt(0, Character.toUpperCase(capitals.charAt(0)));
|
||||||
while (capitals.indexOf("_") != -1) {
|
while (capitals.indexOf("_") != -1) {
|
||||||
MyLogger.logHighLevelMsg("Replacing underscores and capitalizing names...");
|
MyLogger.logHighLevelMsg("Replacing underscores and capitalizing names...");
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ public final class EnumHandler {
|
||||||
*/
|
*/
|
||||||
public static @Nullable EntityType getEntityEnum(String entityName) {
|
public static @Nullable EntityType getEntityEnum(String entityName) {
|
||||||
try {
|
try {
|
||||||
return EntityType.valueOf(entityName.toUpperCase());
|
return EntityType.valueOf(entityName.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException | NullPointerException e) {
|
catch (IllegalArgumentException | NullPointerException e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -109,7 +110,7 @@ public final class EnumHandler {
|
||||||
*/
|
*/
|
||||||
public static @Nullable Statistic getStatEnum(@NotNull String statName) {
|
public static @Nullable Statistic getStatEnum(@NotNull String statName) {
|
||||||
try {
|
try {
|
||||||
return Statistic.valueOf(statName.toUpperCase());
|
return Statistic.valueOf(statName.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -123,7 +124,7 @@ public final class EnumHandler {
|
||||||
* @return true if this String is a valid Statistic
|
* @return true if this String is a valid Statistic
|
||||||
*/
|
*/
|
||||||
public boolean isStatistic(@NotNull String statName) {
|
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
|
* of Type.Untyped
|
||||||
*/
|
*/
|
||||||
public boolean isSubStatEntry(@NotNull String statName) {
|
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() {
|
private void prepareLists() {
|
||||||
List<String> entityNames = Arrays.stream(EntityType.values())
|
List<String> entityNames = Arrays.stream(EntityType.values())
|
||||||
.map(EntityType::toString)
|
.map(EntityType::toString)
|
||||||
.map(String::toLowerCase)
|
.map(string -> string.toLowerCase(Locale.ENGLISH))
|
||||||
.filter(entityName -> !entityName.equalsIgnoreCase("unknown"))
|
.filter(entityName -> !entityName.equalsIgnoreCase("unknown"))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
blockNames = Arrays.stream(Material.values())
|
blockNames = Arrays.stream(Material.values())
|
||||||
.filter(Material::isBlock)
|
.filter(Material::isBlock)
|
||||||
.map(Material::toString)
|
.map(Material::toString)
|
||||||
.map(String::toLowerCase)
|
.map(string -> string.toLowerCase(Locale.ENGLISH))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
itemNames = Arrays.stream(Material.values())
|
itemNames = Arrays.stream(Material.values())
|
||||||
.filter(Material::isItem)
|
.filter(Material::isItem)
|
||||||
.map(Material::toString)
|
.map(Material::toString)
|
||||||
.map(String::toLowerCase)
|
.map(string -> string.toLowerCase(Locale.ENGLISH))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
subStatNames = Stream.of(blockNames, entityNames, itemNames)
|
subStatNames = Stream.of(blockNames, entityNames, itemNames)
|
||||||
|
@ -194,7 +195,7 @@ public final class EnumHandler {
|
||||||
|
|
||||||
statNames = Arrays.stream(Statistic.values())
|
statNames = Arrays.stream(Statistic.values())
|
||||||
.map(Statistic::toString)
|
.map(Statistic::toString)
|
||||||
.map(String::toLowerCase)
|
.map(string -> string.toLowerCase(Locale.ENGLISH))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue