mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Fix usernames showing as "null" and NPE related to primaryGroup not copying correctly
This commit is contained in:
parent
2cc65160b4
commit
f5995c0afa
@ -84,7 +84,10 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getDatastore().loadUser(u, "null")) {
|
||||
String name = plugin.getDatastore().getName(u);
|
||||
if (name == null) name = "null";
|
||||
|
||||
if (!plugin.getDatastore().loadUser(u, name)) {
|
||||
Message.LOADING_ERROR.send(sender);
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,7 @@ public abstract class Datastore {
|
||||
public abstract boolean deleteTrack(Track track);
|
||||
public abstract boolean saveUUIDData(String username, UUID uuid);
|
||||
public abstract UUID getUUID(String username);
|
||||
public abstract String getName(UUID uuid);
|
||||
|
||||
|
||||
|
||||
@ -219,4 +220,11 @@ public abstract class Datastore {
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
|
||||
public void getName(UUID uuid, Callback<String> callback) {
|
||||
doAsync(() -> {
|
||||
String result = getName(uuid);
|
||||
doSync(() -> callback.onComplete(result));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -612,6 +612,16 @@ public class FlatfileDatastore extends Datastore {
|
||||
return UUID.fromString(uuidCache.get(username));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(UUID uuid) {
|
||||
for (Map.Entry<String, String> e : uuidCache.entrySet()) {
|
||||
if (e.getValue().equalsIgnoreCase(uuid.toString())) {
|
||||
return e.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
interface WriteOperation {
|
||||
boolean onRun(JsonWriter writer) throws IOException;
|
||||
}
|
||||
|
@ -413,6 +413,20 @@ public class MongoDBDatastore extends Datastore {
|
||||
}, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(UUID uuid) {
|
||||
return call(() -> {
|
||||
MongoCollection<Document> c = database.getCollection("uuid");
|
||||
|
||||
try (MongoCursor<Document> cursor = c.find(new Document("_id", uuid)).iterator()) {
|
||||
if (cursor.hasNext()) {
|
||||
return cursor.next().get("name", String.class);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}, null);
|
||||
}
|
||||
|
||||
private static <T> T call(Callable<T> c, T def) {
|
||||
try {
|
||||
return c.call();
|
||||
|
@ -71,6 +71,7 @@ abstract class SQLDatastore extends Datastore {
|
||||
|
||||
private static final String UUIDCACHE_INSERT = "INSERT INTO lp_uuid VALUES(?, ?)";
|
||||
private static final String UUIDCACHE_SELECT = "SELECT uuid FROM lp_uuid WHERE name=?";
|
||||
private static final String UUIDCACHE_SELECT_NAME = "SELECT name FROM lp_uuid WHERE uuid=?";
|
||||
private static final String UUIDCACHE_UPDATE = "UPDATE lp_uuid SET uuid=? WHERE name=?";
|
||||
|
||||
private static final String ACTION_INSERT = "INSERT INTO lp_actions(`time`, `actor_uuid`, `actor_name`, `type`, `acted_uuid`, `acted_name`, `action`) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
||||
@ -541,6 +542,30 @@ abstract class SQLDatastore extends Datastore {
|
||||
return success ? uuid[0] : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(UUID uuid) {
|
||||
final String u = uuid.toString();
|
||||
final String[] name = {null};
|
||||
|
||||
boolean success = runQuery(new QueryRS(UUIDCACHE_SELECT_NAME) {
|
||||
@Override
|
||||
void onRun(PreparedStatement preparedStatement) throws SQLException {
|
||||
preparedStatement.setString(1, u);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean onResult(ResultSet resultSet) throws SQLException {
|
||||
if (resultSet.next()) {
|
||||
name[0] = resultSet.getString("name");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return success ? name[0] : null;
|
||||
}
|
||||
|
||||
private class Query extends QueryPS {
|
||||
Query(String query) {
|
||||
super(query);
|
||||
|
@ -63,6 +63,7 @@ public abstract class UserManager extends AbstractManager<UUID, User> {
|
||||
public void copy(User from, User to) {
|
||||
to.setNodes(from.getNodes());
|
||||
to.setPrimaryGroup(from.getPrimaryGroup());
|
||||
giveDefaultIfNeeded(to, true);
|
||||
to.refreshPermissions();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user