Add option to use the servers uuid cache/lookup facility (#354)
This commit is contained in:
+1
-1
@@ -83,7 +83,7 @@ public abstract class MainCommand<T> extends Command<Void, T> {
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
final String name = args.get(0).toLowerCase();
|
||||
final String name = args.get(0);
|
||||
T t = getTarget(name, plugin, sender);
|
||||
if (t != null) {
|
||||
CommandResult result;
|
||||
|
||||
+1
@@ -65,6 +65,7 @@ public class GroupMainCommand extends MainCommand<Group> {
|
||||
|
||||
@Override
|
||||
protected Group getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
target = target.toLowerCase();
|
||||
if (!plugin.getStorage().loadGroup(target).join()) {
|
||||
Message.GROUP_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
|
||||
+1
@@ -55,6 +55,7 @@ public class TrackMainCommand extends MainCommand<Track> {
|
||||
|
||||
@Override
|
||||
protected Track getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
target = target.toLowerCase();
|
||||
if (!plugin.getStorage().loadTrack(target).join()) {
|
||||
Message.TRACK_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
|
||||
+15
-8
@@ -37,6 +37,7 @@ import me.lucko.luckperms.common.commands.impl.generic.parent.CommandParent;
|
||||
import me.lucko.luckperms.common.commands.impl.generic.permission.CommandPermission;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.constants.DataConstraints;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||
@@ -66,26 +67,32 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
|
||||
@Override
|
||||
protected User getTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||
UUID u = Util.parseUuid(target);
|
||||
UUID u = Util.parseUuid(target.toLowerCase());
|
||||
if (u == null) {
|
||||
if (target.length() <= 16) {
|
||||
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
return null;
|
||||
}
|
||||
|
||||
u = plugin.getStorage().getUUID(target.toLowerCase()).join();
|
||||
if (u == null) {
|
||||
if (!plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUID_CACHE)) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
u = plugin.getStorage().getUUID(target).join();
|
||||
u = plugin.lookupUuid(target).orElse(null);
|
||||
if (u == null) {
|
||||
Message.USER_NOT_FOUND.send(sender);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Message.USER_INVALID_ENTRY.send(sender, target);
|
||||
}
|
||||
}
|
||||
|
||||
String name = plugin.getStorage().getName(u).join();
|
||||
if (name == null) name = "null";
|
||||
if (name == null) {
|
||||
name = "null";
|
||||
}
|
||||
|
||||
if (!plugin.getStorage().loadUser(u, name).join()) {
|
||||
Message.LOADING_ERROR.send(sender);
|
||||
|
||||
@@ -116,6 +116,11 @@ public class ConfigKeys {
|
||||
return c.contains("use-server-uuids") ? c.getBoolean("use-server-uuids", true) : c.getBoolean("online-mode", true);
|
||||
});
|
||||
|
||||
/**
|
||||
* # If the servers own UUID cache/lookup facility should be used when there is no record for a player in the LuckPerms cache.
|
||||
*/
|
||||
public static final ConfigKey<Boolean> USE_SERVER_UUID_CACHE = BooleanKey.of("use-server-uuid-cache", false);
|
||||
|
||||
/**
|
||||
* Controls how temporary add commands should behave
|
||||
*/
|
||||
|
||||
@@ -56,6 +56,7 @@ import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
@@ -285,6 +286,14 @@ public interface LuckPermsPlugin {
|
||||
*/
|
||||
Object getPlayer(User user);
|
||||
|
||||
/**
|
||||
* Lookup a uuid from a username, using the servers internal uuid cache.
|
||||
*
|
||||
* @param username the username to lookup
|
||||
* @return an optional uuid, if found
|
||||
*/
|
||||
Optional<UUID> lookupUuid(String username);
|
||||
|
||||
/**
|
||||
* Gets a calculated context instance for the user using the rules of the platform.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user