Fallback to uuid in the search command if the username is unknown

This commit is contained in:
Luck 2017-03-07 22:17:49 +00:00
parent 00895fc7ab
commit 0b6f326c18
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 7 additions and 5 deletions

View File

@ -72,8 +72,8 @@ public class SearchCommand extends SingleCommand {
Map<UUID, String> uuidLookups = new HashMap<>(); Map<UUID, String> uuidLookups = new HashMap<>();
Function<UUID, String> lookupFunc = uuid -> uuidLookups.computeIfAbsent(uuid, u -> { Function<UUID, String> lookupFunc = uuid -> uuidLookups.computeIfAbsent(uuid, u -> {
String s = plugin.getStorage().getName(u).join(); String s = plugin.getStorage().getName(u).join();
if (s == null) { if (s == null || s.isEmpty() || s.equals("null")) {
s = "null"; s = u.toString();
} }
return s; return s;
}); });

View File

@ -281,13 +281,15 @@ public class Util {
int index = pageNumber - 1; int index = pageNumber - 1;
List<List<HeldPermission<UUID>>> pages = divideList(sorted, 15); List<List<HeldPermission<UUID>>> pages = divideList(sorted, 15);
if ((index < 0 || index >= pages.size())) { if (index < 0 || index >= pages.size()) {
pageNumber = 1; pageNumber = 1;
index = 0; index = 0;
} }
List<HeldPermission<UUID>> page = pages.get(index); List<HeldPermission<UUID>> page = pages.get(index);
List<Map.Entry<String, HeldPermission<UUID>>> uuidMappedPage = page.stream().map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp)).collect(Collectors.toList()); List<Map.Entry<String, HeldPermission<UUID>>> uuidMappedPage = page.stream()
.map(hp -> Maps.immutableEntry(uuidLookup.apply(hp.getHolder()), hp))
.collect(Collectors.toList());
FancyMessage message = new FancyMessage(""); FancyMessage message = new FancyMessage("");
String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)"; String title = "&7(page &f" + pageNumber + "&7 of &f" + pages.size() + "&7 - &f" + sorted.size() + "&7 entries)";
@ -316,7 +318,7 @@ public class Util {
int index = pageNumber - 1; int index = pageNumber - 1;
List<List<HeldPermission<String>>> pages = divideList(sorted, 15); List<List<HeldPermission<String>>> pages = divideList(sorted, 15);
if ((index < 0 || index >= pages.size())) { if (index < 0 || index >= pages.size()) {
pageNumber = 1; pageNumber = 1;
index = 0; index = 0;
} }