diff --git a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java index d6697fa1d..c94ac6a4f 100644 --- a/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/core/PermissionHolder.java @@ -423,7 +423,7 @@ public abstract class PermissionHolder { * @throws ObjectLacksException if the holder doesn't have this node already */ public void unsetPermission(Node node) throws ObjectLacksException { - if (hasPermission(node, false) == Tristate.FALSE) { + if (hasPermission(node, false) != Tristate.TRUE) { throw new ObjectLacksException(); } diff --git a/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java b/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java index 160204c05..e267a1fae 100644 --- a/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/storage/methods/FlatfileDatastore.java @@ -228,6 +228,13 @@ public class FlatfileDatastore extends Datastore { @Override public boolean saveUser(User user) { File userFile = new File(usersDir, user.getUuid().toString() + ".json"); + if (!plugin.getUserManager().shouldSave(user)) { + if (userFile.exists()) { + userFile.delete(); + } + return true; + } + if (!userFile.exists()) { try { userFile.createNewFile(); diff --git a/common/src/main/java/me/lucko/luckperms/storage/methods/MongoDBDatastore.java b/common/src/main/java/me/lucko/luckperms/storage/methods/MongoDBDatastore.java index 031fa769a..688d924c2 100644 --- a/common/src/main/java/me/lucko/luckperms/storage/methods/MongoDBDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/storage/methods/MongoDBDatastore.java @@ -169,7 +169,11 @@ public class MongoDBDatastore extends Datastore { @Override public boolean saveUser(User user) { if (!plugin.getUserManager().shouldSave(user)) { - return true; + boolean success = call(() -> { + MongoCollection c = database.getCollection("users"); + return c.deleteOne(new Document("_id", user.getUuid())).wasAcknowledged(); + }, false); + return success; } boolean success = call(() -> { diff --git a/common/src/main/java/me/lucko/luckperms/storage/methods/SQLDatastore.java b/common/src/main/java/me/lucko/luckperms/storage/methods/SQLDatastore.java index f9592f8b4..9b60e0328 100644 --- a/common/src/main/java/me/lucko/luckperms/storage/methods/SQLDatastore.java +++ b/common/src/main/java/me/lucko/luckperms/storage/methods/SQLDatastore.java @@ -55,7 +55,8 @@ abstract class SQLDatastore extends Datastore { private static final String USER_SELECT = "SELECT * FROM lp_users WHERE uuid=?"; private static final String USER_SELECT_ALL = "SELECT uuid FROM lp_users"; private static final String USER_UPDATE = "UPDATE lp_users SET name=?, primary_group = ?, perms=? WHERE uuid=?"; - private static final String USER_DELETE = "DELETE FROM lp_users WHERE perms=?"; + private static final String USER_DELETE = "DELETE FROM lp_users WHERE uuid=?"; + private static final String USER_DELETE_ALL = "DELETE FROM lp_users WHERE perms=?"; private static final String GROUP_INSERT = "INSERT INTO lp_groups VALUES(?, ?)"; private static final String GROUP_SELECT = "SELECT perms FROM lp_groups WHERE name=?"; @@ -189,7 +190,13 @@ abstract class SQLDatastore extends Datastore { @Override public boolean saveUser(User user) { if (!plugin.getUserManager().shouldSave(user)) { - return true; + boolean success = runQuery(new QueryPS(USER_DELETE) { + @Override + void onRun(PreparedStatement preparedStatement) throws SQLException { + preparedStatement.setString(1, user.getUuid().toString()); + } + }); + return success; } boolean success = runQuery(new QueryRS(USER_SELECT) { @@ -234,7 +241,7 @@ abstract class SQLDatastore extends Datastore { @Override public boolean cleanupUsers() { - boolean success = runQuery(new QueryPS(USER_DELETE) { + boolean success = runQuery(new QueryPS(USER_DELETE_ALL) { @Override void onRun(PreparedStatement preparedStatement) throws SQLException { preparedStatement.setString(1, "{\"group.default\":true}"); diff --git a/common/src/main/java/me/lucko/luckperms/users/UserManager.java b/common/src/main/java/me/lucko/luckperms/users/UserManager.java index 3ab87e379..b91ec657c 100644 --- a/common/src/main/java/me/lucko/luckperms/users/UserManager.java +++ b/common/src/main/java/me/lucko/luckperms/users/UserManager.java @@ -61,10 +61,12 @@ public abstract class UserManager extends AbstractManager { @Override public void copy(User from, User to) { - to.setNodes(from.getNodes()); - to.setPrimaryGroup(from.getPrimaryGroup()); - giveDefaultIfNeeded(to, true); - to.refreshPermissions(); + if (from.getPrimaryGroup() != null) { + // This isn't just a black user. we shouldn't override in that case. + to.setNodes(from.getNodes()); + to.setPrimaryGroup(from.getPrimaryGroup()); + to.refreshPermissions(); + } } /**