mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-19 22:04:44 +02:00
@ -1,5 +1,6 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -260,6 +261,49 @@ public final class Misc {
|
||||
return ((Furnace) furnaceState).getInventory().getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to match any player names with the given name, and returns a list of all possibly matches.
|
||||
*
|
||||
* This list is not sorted in any particular order.
|
||||
* If an exact match is found, the returned list will only contain a single result.
|
||||
*
|
||||
* @param partialName Name to match
|
||||
* @return List of all possible names
|
||||
*/
|
||||
public static List<String> matchPlayer(String partialName) {
|
||||
List<String> matchedPlayers = new ArrayList<String>();
|
||||
|
||||
for (String iterPlayerName : mcMMO.getDatabaseManager().getStoredUsers()) {
|
||||
if (partialName.equalsIgnoreCase(iterPlayerName)) {
|
||||
// Exact match
|
||||
matchedPlayers.clear();
|
||||
matchedPlayers.add(iterPlayerName);
|
||||
break;
|
||||
}
|
||||
if (iterPlayerName.toLowerCase().contains(partialName.toLowerCase())) {
|
||||
// Partial match
|
||||
matchedPlayers.add(iterPlayerName);
|
||||
}
|
||||
}
|
||||
|
||||
return matchedPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a matched player name if one was found in the database.
|
||||
*
|
||||
* @param partialName Name to match
|
||||
* @return Matched name or {@code partialName} if no match was found
|
||||
*/
|
||||
public static String getMatchedPlayerName(String partialName) {
|
||||
List<String> matches = matchPlayer(partialName);
|
||||
|
||||
if (matches.size() == 1) {
|
||||
partialName = matches.get(0);
|
||||
}
|
||||
return partialName;
|
||||
}
|
||||
|
||||
public static boolean noErrorsInConfig(List<String> issues) {
|
||||
for (String issue : issues) {
|
||||
mcMMO.p.getLogger().warning(issue);
|
||||
|
Reference in New Issue
Block a user