diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitBootstrap.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitBootstrap.java index ecd950c2..59128f80 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitBootstrap.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitBootstrap.java @@ -31,6 +31,7 @@ import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader; import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader; import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap; +import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -211,13 +212,13 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap @Override public Optional lookupUuid(String username) { - try { - //noinspection deprecation - return Optional.ofNullable(getServer().getOfflinePlayer(username)).flatMap(p -> Optional.ofNullable(p.getUniqueId())); - } catch (Exception e) { - e.printStackTrace(); - return Optional.empty(); - } + //noinspection deprecation + return Optional.ofNullable(getServer().getOfflinePlayer(username)).map(OfflinePlayer::getUniqueId); + } + + @Override + public Optional lookupUsername(UUID uuid) { + return Optional.ofNullable(getServer().getOfflinePlayer(uuid)).map(OfflinePlayer::getName); } @Override diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeBootstrap.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeBootstrap.java index e07adaf8..7c0fe1e0 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeBootstrap.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeeBootstrap.java @@ -182,6 +182,19 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap { return Optional.empty(); } + @Override + public Optional lookupUsername(UUID uuid) { + if (getProxy().getPluginManager().getPlugin("RedisBungee") != null) { + try { + return RedisBungeeUtil.lookupUsername(uuid); + } catch (Throwable t) { + t.printStackTrace(); + } + } + + return Optional.empty(); + } + @Override public int getPlayerCount() { return getProxy().getOnlineCount(); diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/util/RedisBungeeUtil.java b/bungee/src/main/java/me/lucko/luckperms/bungee/util/RedisBungeeUtil.java index 140f6fd5..fb9514cd 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/util/RedisBungeeUtil.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/util/RedisBungeeUtil.java @@ -39,7 +39,11 @@ public final class RedisBungeeUtil { * @return a uuid, if present */ public static Optional lookupUuid(String username) { - return Optional.ofNullable(RedisBungee.getApi()).flatMap(a -> Optional.ofNullable(a.getUuidFromName(username, true))); + return Optional.ofNullable(RedisBungee.getApi()).map(a -> a.getUuidFromName(username, true)); + } + + public static Optional lookupUsername(UUID uuid) { + return Optional.ofNullable(RedisBungee.getApi()).map(a -> a.getNameFromUuid(uuid, true)); } private RedisBungeeUtil() {} diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java index 4b66706c..b7abd8b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/GroupListMembers.java @@ -40,6 +40,7 @@ import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -96,10 +97,18 @@ public class GroupListMembers extends SubCommand { LoadingCache uuidLookups = Caffeine.newBuilder() .build(u -> { String s = plugin.getStorage().getPlayerName(u).join(); - if (s == null || s.isEmpty() || s.equals("null")) { - s = u.toString(); + if (s != null && !s.isEmpty() && !s.equals("null")) { + return s; } - return s; + + if (plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUID_CACHE)) { + s = plugin.getBootstrap().lookupUsername(u).orElse(null); + if (s != null) { + return s; + } + } + + return u.toString(); }); sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page); } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java index 16f3e600..64f7f8d0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/SearchCommand.java @@ -41,6 +41,7 @@ import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.command.utils.ArgumentParser; import me.lucko.luckperms.common.command.utils.MessageUtils; import me.lucko.luckperms.common.command.utils.TabCompletions; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; @@ -97,10 +98,18 @@ public class SearchCommand extends SingleCommand { LoadingCache uuidLookups = Caffeine.newBuilder() .build(u -> { String s = plugin.getStorage().getPlayerName(u).join(); - if (s == null || s.isEmpty() || s.equals("null")) { - s = u.toString(); + if (s != null && !s.isEmpty() && !s.equals("null")) { + return s; } - return s; + + if (plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUID_CACHE)) { + s = plugin.getBootstrap().lookupUsername(u).orElse(null); + if (s != null) { + return s; + } + } + + return u.toString(); }); sendResult(sender, matchedUsers, uuidLookups::get, Message.SEARCH_SHOWING_USERS, HolderType.USER, label, page, comparison); } diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/bootstrap/LuckPermsBootstrap.java b/common/src/main/java/me/lucko/luckperms/common/plugin/bootstrap/LuckPermsBootstrap.java index bdc0d49a..c354873a 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/bootstrap/LuckPermsBootstrap.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/bootstrap/LuckPermsBootstrap.java @@ -168,6 +168,14 @@ public interface LuckPermsBootstrap { */ Optional lookupUuid(String username); + /** + * Lookup a username from a uuid, using the servers internal uuid cache. + * + * @param uuid the uuid to lookup + * @return an optional username, if found + */ + Optional lookupUsername(UUID uuid); + /** * Gets the number of users online on the platform * diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitBootstrap.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitBootstrap.java index 7a0bb597..eced2a49 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitBootstrap.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/LPNukkitBootstrap.java @@ -177,6 +177,11 @@ public class LPNukkitBootstrap extends PluginBase implements LuckPermsBootstrap return Optional.empty(); } + @Override + public Optional lookupUsername(UUID uuid) { + return Optional.empty(); + } + @Override public int getPlayerCount() { return getServer().getOnlinePlayers().size(); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java index b36d2ae3..3f4b1ea0 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongeBootstrap.java @@ -47,6 +47,7 @@ import org.spongepowered.api.event.game.state.GamePreInitializationEvent; import org.spongepowered.api.event.game.state.GameStoppingServerEvent; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.profile.GameProfile; import org.spongepowered.api.scheduler.AsynchronousExecutor; import org.spongepowered.api.scheduler.Scheduler; import org.spongepowered.api.scheduler.SpongeExecutorService; @@ -280,6 +281,18 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap { .join(); } + @Override + public Optional lookupUsername(UUID uuid) { + if (!getGame().isServerAvailable()) { + return Optional.empty(); + } + + return getGame().getServer().getGameProfileManager().get(uuid) + .thenApply(GameProfile::getName) + .exceptionally(x -> Optional.empty()) + .join(); + } + @Override public int getPlayerCount() { return getGame().isServerAvailable() ? getGame().getServer().getOnlinePlayers().size() : 0;