mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-03-12 06:44:14 +01:00
Improve Util#matchEntityType to check for an exact match first
This commit is contained in:
parent
5df6499dae
commit
5a3f616fe1
@ -107,18 +107,19 @@ public class Util {
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> T matchEnum(T[] values, String toMatch) {
|
||||
T type = null;
|
||||
toMatch = toMatch.toLowerCase();
|
||||
toMatch = toMatch.toLowerCase().replace('-', '_').replace(' ', '_');
|
||||
for (T check : values) {
|
||||
if (toMatch.equals(check.name().toLowerCase())) {
|
||||
return check; // check for an exact match first
|
||||
}
|
||||
}
|
||||
for (T check : values) {
|
||||
String name = check.name().toLowerCase();
|
||||
if (name.matches(toMatch) || name.equals(toMatch) || name.replace("_", "").equals(toMatch)
|
||||
|| name.replace('_', ' ').equals(toMatch) || name.replace('_', '-').equals(toMatch)
|
||||
|| name.replace('_', ' ').equals(toMatch) || name.startsWith(toMatch)) {
|
||||
type = check;
|
||||
break;
|
||||
if (name.replace("_", "").equals(toMatch) || name.matches(toMatch) || name.startsWith(toMatch)) {
|
||||
return check;
|
||||
}
|
||||
}
|
||||
return type;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean matchesItemInHand(Player player, String setting) {
|
||||
|
Loading…
Reference in New Issue
Block a user