Fix clear command not resetting primary group

This commit is contained in:
Luck 2016-06-28 17:21:41 +01:00
parent e5e1333769
commit d4c335e33e
6 changed files with 28 additions and 16 deletions

View File

@ -10,6 +10,7 @@ public class BukkitUserManager extends UserManager {
private final LPBukkitPlugin plugin;
public BukkitUserManager(LPBukkitPlugin plugin) {
super(plugin);
this.plugin = plugin;
}

View File

@ -9,6 +9,7 @@ public class BungeeUserManager extends UserManager {
private final LPBungeePlugin plugin;
public BungeeUserManager(LPBungeePlugin plugin) {
super(plugin);
this.plugin = plugin;
}

View File

@ -17,7 +17,7 @@ public class UserClearCommand extends UserSubCommand {
@Override
protected void execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args) {
user.clearNodes();
user.getNodes().put(plugin.getConfiguration().getDefaultGroupNode(), true);
plugin.getUserManager().giveDefaults(user);
Util.sendPluginMessage(sender, "&b" + user.getName() + "&a's permissions were cleared.");
saveUser(user, sender, plugin);

View File

@ -4,7 +4,6 @@ import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.data.Datastore;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.users.User;
@ -130,11 +129,7 @@ public class FlatfileDatastore extends Datastore {
return false;
}
// Setup the new user with default values
try {
user.setPermission(plugin.getConfiguration().getDefaultGroupNode(), true);
} catch (ObjectAlreadyHasException ignored) {}
user.setPrimaryGroup(plugin.getConfiguration().getDefaultGroupName());
plugin.getUserManager().giveDefaults(user);
boolean success = doWrite(userFile, writer -> {
writer.beginObject();

View File

@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.data.Datastore;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import me.lucko.luckperms.groups.Group;
import me.lucko.luckperms.groups.GroupManager;
import me.lucko.luckperms.users.User;
@ -165,12 +164,7 @@ abstract class SQLDatastore extends Datastore {
boolean onResult(ResultSet resultSet) throws SQLException {
boolean success = true;
if (!resultSet.next()) {
// Setup the new user with default values
try {
user.setPermission(plugin.getConfiguration().getDefaultGroupNode(), true);
} catch (ObjectAlreadyHasException ignored) {}
user.setPrimaryGroup(plugin.getConfiguration().getDefaultGroupName());
plugin.getUserManager().giveDefaults(user);
success = runQuery(new QueryPS(USER_INSERT) {
@Override

View File

@ -1,14 +1,14 @@
package me.lucko.luckperms.users;
import lombok.Getter;
import lombok.NoArgsConstructor;
import me.lucko.luckperms.LuckPermsPlugin;
import me.lucko.luckperms.data.Datastore;
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@NoArgsConstructor
public abstract class UserManager {
/**
@ -17,6 +17,15 @@ public abstract class UserManager {
@Getter
private final Map<UUID, User> users = new ConcurrentHashMap<>();
/**
* Reference to main plugin instance
*/
private final LuckPermsPlugin plugin;
public UserManager(LuckPermsPlugin plugin) {
this.plugin = plugin;
}
/**
* Get a user object by UUID
* @param uuid The uuid to search by
@ -80,6 +89,18 @@ public abstract class UserManager {
datastore.saveUser(user, success -> {});
}
/**
* Set a user to the default group
* @param user the user to give to
*/
public void giveDefaults(User user) {
// Setup the new user with default values
try {
user.setPermission(plugin.getConfiguration().getDefaultGroupNode(), true);
} catch (ObjectAlreadyHasException ignored) {}
user.setPrimaryGroup(plugin.getConfiguration().getDefaultGroupName());
}
/**
* Check to see if a user is loaded or not
* @param uuid the UUID of the user