mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Use the servers uuid cache in the output to /lp search if LP doesn't have data (#974)
This commit is contained in:
parent
d3dded8791
commit
91b7af52ac
@ -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<UUID> 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<String> lookupUsername(UUID uuid) {
|
||||
return Optional.ofNullable(getServer().getOfflinePlayer(uuid)).map(OfflinePlayer::getName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -182,6 +182,19 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> 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();
|
||||
|
@ -39,7 +39,11 @@ public final class RedisBungeeUtil {
|
||||
* @return a uuid, if present
|
||||
*/
|
||||
public static Optional<UUID> 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<String> lookupUsername(UUID uuid) {
|
||||
return Optional.ofNullable(RedisBungee.getApi()).map(a -> a.getNameFromUuid(uuid, true));
|
||||
}
|
||||
|
||||
private RedisBungeeUtil() {}
|
||||
|
@ -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<Group> {
|
||||
LoadingCache<UUID, String> 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);
|
||||
}
|
||||
|
@ -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<UUID, String> 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);
|
||||
}
|
||||
|
@ -168,6 +168,14 @@ public interface LuckPermsBootstrap {
|
||||
*/
|
||||
Optional<UUID> 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<String> lookupUsername(UUID uuid);
|
||||
|
||||
/**
|
||||
* Gets the number of users online on the platform
|
||||
*
|
||||
|
@ -177,6 +177,11 @@ public class LPNukkitBootstrap extends PluginBase implements LuckPermsBootstrap
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> lookupUsername(UUID uuid) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerCount() {
|
||||
return getServer().getOnlinePlayers().size();
|
||||
|
@ -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<String> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user