diff --git a/api/src/main/java/me/lucko/luckperms/api/Storage.java b/api/src/main/java/me/lucko/luckperms/api/Storage.java
index f9e4713a..a2b6d7fc 100644
--- a/api/src/main/java/me/lucko/luckperms/api/Storage.java
+++ b/api/src/main/java/me/lucko/luckperms/api/Storage.java
@@ -93,13 +93,23 @@ public interface Storage {
* Loads a user's data from the main storage into the plugins local storage.
*
* @param uuid the uuid of the user to load
- * @param username the users username. (if you want to specify null
here, just input "null" as a
- * string.)
+ * @param username the users username, or null if it is not known.
* @return if the operation completed successfully
- * @throws NullPointerException if uuid or username is null
+ * @throws NullPointerException if uuid is null
*/
CompletableFuture loadUser(UUID uuid, String username);
+ /**
+ * Loads a user's data from the main storage into the plugins local storage.
+ *
+ * @param uuid the uuid of the user to load
+ * @return if the operation completed successfully
+ * @throws NullPointerException if uuid is null
+ */
+ default CompletableFuture loadUser(UUID uuid) {
+ return loadUser(uuid, null);
+ }
+
/**
* Saves a user object back to storage. You should call this after you make any changes to a user.
*
diff --git a/api/src/main/java/me/lucko/luckperms/api/User.java b/api/src/main/java/me/lucko/luckperms/api/User.java
index 41ccaafc..cb4eea2d 100644
--- a/api/src/main/java/me/lucko/luckperms/api/User.java
+++ b/api/src/main/java/me/lucko/luckperms/api/User.java
@@ -43,7 +43,7 @@ public interface User extends PermissionHolder {
UUID getUuid();
/**
- * Gets the users username
+ * Gets the users username, or null if no username is associated with this user
*
* @return the Users Username
*/
diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java
index 3913f6e9..9995466b 100644
--- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java
+++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java
@@ -69,6 +69,6 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
}
processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider()));
- return registerCalculator(new PermissionCalculator(plugin, user.getName(), processors.build()));
+ return registerCalculator(new PermissionCalculator(plugin, user.getFriendlyName(), processors.build()));
}
}
diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java
index 793bc3d2..fbd19279 100644
--- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java
+++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultChatHook.java
@@ -124,7 +124,7 @@ public class VaultChatHook extends Chat {
world = perms.isIgnoreWorld() ? null : world;
node = escapeCharacters(node);
- perms.log("Getting meta: '" + node + "' for user " + user.getName() + " on world " + world + ", server " + perms.getServer());
+ perms.log("Getting meta: '" + node + "' for user " + user.getFriendlyName() + " on world " + world + ", server " + perms.getServer());
if (user.getUserData() == null) {
return defaultValue;
@@ -142,7 +142,7 @@ public class VaultChatHook extends Chat {
if (user == null) return "";
world = perms.isIgnoreWorld() ? null : world;
- perms.log("Getting " + (prefix ? "prefix" : "suffix") + " for user " + user.getName() + " on world " + world + ", server " + perms.getServer());
+ perms.log("Getting " + (prefix ? "prefix" : "suffix") + " for user " + user.getFriendlyName() + " on world " + world + ", server " + perms.getServer());
if (user.getUserData() == null) {
return "";
diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java
index c2eb9270..c8da7ab2 100644
--- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java
+++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java
@@ -54,6 +54,6 @@ public class BungeeCalculatorFactory extends AbstractCalculatorFactory {
processors.add(new WildcardProcessor());
}
- return registerCalculator(new PermissionCalculator(plugin, user.getName(), processors.build()));
+ return registerCalculator(new PermissionCalculator(plugin, user.getFriendlyName(), processors.build()));
}
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/StorageDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/StorageDelegate.java
index 0d3cc4f7..f2d6500b 100644
--- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/StorageDelegate.java
+++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/StorageDelegate.java
@@ -88,12 +88,12 @@ public class StorageDelegate implements Storage {
}
@Override
- public CompletableFuture loadUser(UUID uuid, String username) {
- return handle.force().loadUser(uuid, checkUsername(username));
+ public CompletableFuture loadUser(@NonNull UUID uuid, String username) {
+ return handle.force().loadUser(uuid, username == null ? null : checkUsername(username));
}
@Override
- public CompletableFuture saveUser(User user) {
+ public CompletableFuture saveUser(@NonNull User user) {
return handle.force().saveUser(UserDelegate.cast(user));
}
@@ -113,12 +113,12 @@ public class StorageDelegate implements Storage {
}
@Override
- public CompletableFuture createAndLoadGroup(String name) {
+ public CompletableFuture createAndLoadGroup(@NonNull String name) {
return handle.force().createAndLoadGroup(checkName(name), CreationCause.API);
}
@Override
- public CompletableFuture loadGroup(String name) {
+ public CompletableFuture loadGroup(@NonNull String name) {
return handle.force().loadGroup(checkName(name));
}
@@ -128,12 +128,12 @@ public class StorageDelegate implements Storage {
}
@Override
- public CompletableFuture saveGroup(Group group) {
+ public CompletableFuture saveGroup(@NonNull Group group) {
return handle.force().saveGroup(GroupDelegate.cast(group));
}
@Override
- public CompletableFuture deleteGroup(Group group) {
+ public CompletableFuture deleteGroup(@NonNull Group group) {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
@@ -146,12 +146,12 @@ public class StorageDelegate implements Storage {
}
@Override
- public CompletableFuture createAndLoadTrack(String name) {
+ public CompletableFuture createAndLoadTrack(@NonNull String name) {
return handle.force().createAndLoadTrack(checkName(name), CreationCause.API);
}
@Override
- public CompletableFuture loadTrack(String name) {
+ public CompletableFuture loadTrack(@NonNull String name) {
return handle.force().loadTrack(checkName(name));
}
@@ -161,22 +161,22 @@ public class StorageDelegate implements Storage {
}
@Override
- public CompletableFuture saveTrack(Track track) {
+ public CompletableFuture saveTrack(@NonNull Track track) {
return handle.force().saveTrack(TrackDelegate.cast(track));
}
@Override
- public CompletableFuture deleteTrack(Track track) {
+ public CompletableFuture deleteTrack(@NonNull Track track) {
return handle.force().deleteTrack(TrackDelegate.cast(track), DeletionCause.API);
}
@Override
- public CompletableFuture saveUUIDData(String username, UUID uuid) {
+ public CompletableFuture saveUUIDData(@NonNull String username, @NonNull UUID uuid) {
return handle.force().saveUUIDData(checkUsername(username), uuid);
}
@Override
- public CompletableFuture getUUID(String username) {
+ public CompletableFuture getUUID(@NonNull String username) {
return handle.force().getUUID(checkUsername(username));
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/UserDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/UserDelegate.java
index a8ab8c34..ebbecc13 100644
--- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/UserDelegate.java
+++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/UserDelegate.java
@@ -49,9 +49,9 @@ import static me.lucko.luckperms.common.api.ApiUtils.checkTime;
* Provides a link between {@link User} and {@link me.lucko.luckperms.common.core.model.User}
*/
public final class UserDelegate extends PermissionHolderDelegate implements User {
- public static me.lucko.luckperms.common.core.model.User cast(User g) {
- Preconditions.checkState(g instanceof UserDelegate, "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
- return ((UserDelegate) g).getHandle();
+ public static me.lucko.luckperms.common.core.model.User cast(User u) {
+ Preconditions.checkState(u instanceof UserDelegate, "Illegal instance " + u.getClass() + " cannot be handled by this implementation.");
+ return ((UserDelegate) u).getHandle();
}
@Getter
@@ -69,7 +69,7 @@ public final class UserDelegate extends PermissionHolderDelegate implements User
@Override
public String getName() {
- return handle.getName();
+ return handle.getName().orElse(null);
}
@Override
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java
index 86dfbefa..008f9550 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/CheckCommand.java
@@ -73,12 +73,12 @@ public class CheckCommand extends SingleCommand {
UserCache data = user.getUserData();
if (data == null) {
- Message.USER_NO_DATA.send(sender, user.getName());
+ Message.USER_NO_DATA.send(sender, user.getFriendlyName());
return CommandResult.STATE_ERROR;
}
Tristate tristate = data.getPermissionData(plugin.getContextForUser(user)).getPermissionValue(permission);
- Message.CHECK_RESULT.send(sender, user.getName(), permission, Util.formatTristate(tristate));
+ Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, Util.formatTristate(tristate));
return CommandResult.SUCCESS;
}
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/TreeCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/TreeCommand.java
index 6f5d752a..f37692b6 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/TreeCommand.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/misc/TreeCommand.java
@@ -92,7 +92,7 @@ public class TreeCommand extends SingleCommand {
UserCache data = user.getUserData();
if (data == null) {
- Message.USER_NO_DATA.send(sender, user.getName());
+ Message.USER_NO_DATA.send(sender, user.getFriendlyName());
return CommandResult.STATE_ERROR;
}
@@ -106,7 +106,7 @@ public class TreeCommand extends SingleCommand {
Message.TREE_UPLOAD_START.send(sender);
- String url = view.uploadPasteData(plugin.getVersion(), user.getName(), permissionData);
+ String url = view.uploadPasteData(plugin.getVersion(), user.getFriendlyName(), permissionData);
if (url == null) {
url = "null";
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java
index 59a7d8f9..89b1b50b 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserDemote.java
@@ -125,7 +125,7 @@ public class UserDemote extends SubCommand {
user.unsetPermission(oldNode);
- Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), user.getName(), old);
+ Message.USER_DEMOTE_ENDOFTRACK.send(sender, track.getName(), user.getFriendlyName(), old);
LogEntry.build().actor(sender).acted(user)
.action("demote " + args.stream().collect(Collectors.joining(" ")))
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserInfo.java
index cf65ae47..b9be7a15 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserInfo.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserInfo.java
@@ -54,7 +54,7 @@ public class UserInfo extends SubCommand {
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List args, String label) throws CommandException {
Message.USER_INFO_GENERAL.send(sender,
- user.getName(),
+ user.getName().orElse("Unknown"),
user.getUuid(),
plugin.getPlayerStatus(user.getUuid()),
user.getPrimaryGroup().getValue(),
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java
index b2e84f81..83f5746b 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserPromote.java
@@ -106,13 +106,13 @@ public class UserPromote extends SubCommand {
Group nextGroup = plugin.getGroupManager().getIfLoaded(first);
if (nextGroup == null) {
- Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, false);
+ Message.USER_PROMOTE_ERROR_MALFORMED.send(sender, first);
return CommandResult.LOADING_ERROR;
}
user.setPermission(NodeFactory.newBuilder("group." + first).withExtraContext(context).build());
- Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getName(), first, Util.contextSetToString(context));
+ Message.USER_TRACK_ADDED_TO_FIRST.send(sender, user.getFriendlyName(), first, Util.contextSetToString(context));
LogEntry.build().actor(sender).acted(user)
.action("promote " + args.stream().collect(Collectors.joining(" ")))
.build().submit(plugin, sender);
diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserSwitchPrimaryGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserSwitchPrimaryGroup.java
index 297c8c30..1648f972 100644
--- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserSwitchPrimaryGroup.java
+++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/user/UserSwitchPrimaryGroup.java
@@ -68,12 +68,12 @@ public class UserSwitchPrimaryGroup extends SubCommand {
}
if (!user.inheritsGroup(group)) {
- Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getName(), group.getName());
+ Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getFriendlyName(), group.getName());
user.setInheritGroup(group, ContextSet.empty());
}
user.getPrimaryGroup().setStoredValue(group.getName());
- Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getName(), group.getDisplayName());
+ Message.USER_PRIMARYGROUP_SUCCESS.send(sender, user.getFriendlyName(), group.getDisplayName());
LogEntry.build().actor(sender).acted(user)
.action("setprimarygroup " + group.getName())
.build().submit(plugin, sender);
diff --git a/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java b/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java
index 718d2c4f..2991091c 100644
--- a/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java
+++ b/common/src/main/java/me/lucko/luckperms/common/core/UserIdentifier.java
@@ -33,20 +33,29 @@ import lombok.ToString;
import me.lucko.luckperms.common.utils.Identifiable;
+import java.util.Optional;
import java.util.UUID;
-@Getter
@ToString
@EqualsAndHashCode(of = "uuid")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public final class UserIdentifier implements Identifiable {
public static UserIdentifier of(UUID uuid, String username) {
+ if (username == null || username.equalsIgnoreCase("null") || username.isEmpty()) {
+ username = null;
+ }
+
return new UserIdentifier(uuid, username);
}
+ @Getter
private final UUID uuid;
private final String username;
+ public Optional getUsername() {
+ return Optional.ofNullable(username);
+ }
+
@Override
public UUID getId() {
return getUuid();
diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/User.java b/common/src/main/java/me/lucko/luckperms/common/core/model/User.java
index fbd505d3..d6e6e2f3 100644
--- a/common/src/main/java/me/lucko/luckperms/common/core/model/User.java
+++ b/common/src/main/java/me/lucko/luckperms/common/core/model/User.java
@@ -27,7 +27,6 @@ package me.lucko.luckperms.common.core.model;
import lombok.EqualsAndHashCode;
import lombok.Getter;
-import lombok.Setter;
import lombok.ToString;
import me.lucko.luckperms.api.caching.UserData;
@@ -42,6 +41,7 @@ import me.lucko.luckperms.common.primarygroup.PrimaryGroupHolder;
import me.lucko.luckperms.common.utils.BufferedRequest;
import me.lucko.luckperms.common.utils.Identifiable;
+import java.util.Optional;
import java.util.UUID;
@ToString(of = {"uuid"})
@@ -57,9 +57,7 @@ public class User extends PermissionHolder implements Identifiable getName() {
+ return Optional.ofNullable(name);
+ }
+
+ public boolean setName(String name, boolean force) {
+ // if the value being set is null
+ if (name == null || name.equalsIgnoreCase("null") || name.isEmpty()) {
+ // only apply the change if it is being forced
+ if (force) {
+ // if the name is already null, return false
+ if (this.name == null) {
+ return false;
+ } else {
+ // set the new null value
+ this.name = null;
+ return true;
+ }
+ } else {
+ // we already have a non-null value, so return false
+ return false;
+ }
+ } else {
+ // the name being set is not null
+ if (this.name == null) {
+ this.name = name;
+ return true;
+ }
+
+ // update the capitalisation, but still return false
+ if (this.name.equalsIgnoreCase(name)) {
+ this.name = name;
+ return false;
+ }
+
+ // completely new value, just set & return true
+ this.name = name;
+ return true;
+ }
+ }
+
@Override
public String getFriendlyName() {
- return name;
+ return name != null ? name : uuid.toString();
}
@Override
diff --git a/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java b/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java
index 6a270cd8..77187192 100644
--- a/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java
+++ b/common/src/main/java/me/lucko/luckperms/common/data/Exporter.java
@@ -217,7 +217,7 @@ public class Exporter implements Runnable {
plugin.getStorage().loadUser(uuid, "null").join();
User user = plugin.getUserManager().get(uuid);
- output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName());
+ output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
boolean inDefault = false;
for (Node node : user.getNodes().values()) {
diff --git a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java
index e1edad66..be56f6bf 100644
--- a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java
+++ b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java
@@ -116,7 +116,7 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry {
public LogEntryBuilder acted(PermissionHolder acted) {
if (acted instanceof User) {
- super.actedName(((User) acted).getName());
+ super.actedName(((User) acted).getName().orElse("null"));
super.acted(((User) acted).getUuid());
super.type('U');
} else if (acted instanceof Group) {
diff --git a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java
index e2dc8465..92a45d7b 100644
--- a/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java
+++ b/common/src/main/java/me/lucko/luckperms/common/managers/impl/GenericUserManager.java
@@ -35,6 +35,7 @@ import me.lucko.luckperms.common.managers.AbstractManager;
import me.lucko.luckperms.common.managers.UserManager;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -105,15 +106,16 @@ public class GenericUserManager extends AbstractManager im
@Override
public User apply(UserIdentifier id) {
- return id.getUsername() == null ?
+ return !id.getUsername().isPresent() ?
new User(id.getUuid(), plugin) :
- new User(id.getUuid(), id.getUsername(), plugin);
+ new User(id.getUuid(), id.getUsername().get(), plugin);
}
@Override
public User getByUsername(String name) {
for (User user : getAll().values()) {
- if (user.getName().equalsIgnoreCase(name)) {
+ Optional n = user.getName();
+ if (n.isPresent() && n.get().equalsIgnoreCase(name)) {
return user;
}
}
diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java
index a6a30348..574a0e12 100644
--- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java
+++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/FlatfileBacking.java
@@ -180,7 +180,7 @@ public abstract class FlatfileBacking extends AbstractBacking {
User u = plugin.getUserManager().get(uuid);
if (u != null) {
- plugin.getLog().info("[FileWatcher] Refreshing user " + u.getName());
+ plugin.getLog().info("[FileWatcher] Refreshing user " + u.getFriendlyName());
plugin.getStorage().loadUser(uuid, "null");
}
});
diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java
index 07e735b5..a6f78bdb 100644
--- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java
+++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/JSONBacking.java
@@ -176,12 +176,8 @@ public class JSONBacking extends FlatfileBacking {
boolean save = plugin.getUserManager().giveDefaultIfNeeded(user, false);
- if (user.getName() == null || user.getName().equalsIgnoreCase("null")) {
- user.setName(name);
- } else {
- if (!name.equalsIgnoreCase(user.getName())) {
- save = true;
- }
+ if (user.setName(name, false)) {
+ save = true;
}
if (save) {
@@ -230,7 +226,7 @@ public class JSONBacking extends FlatfileBacking {
JsonObject data = new JsonObject();
data.addProperty("uuid", user.getUuid().toString());
- data.addProperty("name", user.getName());
+ data.addProperty("name", user.getName().orElse("null"));
data.addProperty("primaryGroup", user.getPrimaryGroup().getStoredValue());
Set nodes = user.getNodes().values().stream().map(NodeModel::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java
index 11c09d62..d56bb471 100644
--- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java
+++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/MongoDBBacking.java
@@ -98,7 +98,7 @@ public class MongoDBBacking extends AbstractBacking {
private static Document fromUser(User user) {
Document main = new Document("_id", user.getUuid())
- .append("name", user.getName())
+ .append("name", user.getName().orElse("null"))
.append("primaryGroup", user.getPrimaryGroup().getStoredValue());
Document perms = new Document();
@@ -325,12 +325,8 @@ public class MongoDBBacking extends AbstractBacking {
boolean save = plugin.getUserManager().giveDefaultIfNeeded(user, false);
- if (user.getName() == null || user.getName().equalsIgnoreCase("null")) {
- user.setName(d.getString("name"));
- } else {
- if (!d.getString("name").equalsIgnoreCase(user.getName())) {
- save = true;
- }
+ if (user.setName(name, false)) {
+ save = true;
}
if (save) {
diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java
index c88da5bf..cf3f0f43 100644
--- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java
+++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/SQLBacking.java
@@ -349,9 +349,7 @@ public class SQLBacking extends AbstractBacking {
}
// Update their username to what was in the storage if the one in the local instance is null
- if (user.getName() == null || user.getName().equalsIgnoreCase("null")) {
- user.setName(name);
- }
+ user.setName(name, false);
// If the user has any data in storage
if (!data.isEmpty()) {
diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java
index 67e49a4f..ad57eed5 100644
--- a/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java
+++ b/common/src/main/java/me/lucko/luckperms/common/storage/backing/YAMLBacking.java
@@ -179,12 +179,8 @@ public class YAMLBacking extends FlatfileBacking {
boolean save = plugin.getUserManager().giveDefaultIfNeeded(user, false);
- if (user.getName() == null || user.getName().equalsIgnoreCase("null")) {
- user.setName(name);
- } else {
- if (!name.equalsIgnoreCase(user.getName())) {
- save = true;
- }
+ if (user.setName(name, false)) {
+ save = true;
}
if (save) {
@@ -231,7 +227,7 @@ public class YAMLBacking extends FlatfileBacking {
Map values = new LinkedHashMap<>();
values.put("uuid", user.getUuid().toString());
- values.put("name", user.getName());
+ values.put("name", user.getName().orElse("null"));
values.put("primary-group", user.getPrimaryGroup().getStoredValue());
Set data = user.getNodes().values().stream().map(NodeModel::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java
index 94b9a255..ae24e22f 100644
--- a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java
+++ b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/BufferedOutputStorage.java
@@ -76,7 +76,7 @@ public class BufferedOutputStorage implements Storage, Runnable {
private final Buffer uuidDataOutputBuffer = new Buffer() {
@Override
protected Boolean dequeue(UserIdentifier userIdentifier) {
- return backing.saveUUIDData(userIdentifier.getUsername(), userIdentifier.getUuid()).join();
+ return backing.saveUUIDData(userIdentifier.getUsername().get(), userIdentifier.getUuid()).join();
}
};
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java
index de1fa767..42eb873f 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java
@@ -58,6 +58,6 @@ public class SpongeCalculatorFactory extends AbstractCalculatorFactory {
}
processors.add(new DefaultsProcessor(plugin.getService(), contexts.getContexts()));
- return registerCalculator(new PermissionCalculator(plugin, user.getName(), processors.build()));
+ return registerCalculator(new PermissionCalculator(plugin, user.getFriendlyName(), processors.build()));
}
}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java
index 6c6d167d..c2817e8a 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/managers/SpongeUserManager.java
@@ -56,6 +56,7 @@ import co.aikar.timings.Timing;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -115,9 +116,9 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
@Override
public SpongeUser apply(UserIdentifier id) {
- return id.getUsername() == null ?
+ return !id.getUsername().isPresent() ?
new SpongeUser(id.getUuid(), plugin) :
- new SpongeUser(id.getUuid(), id.getUsername(), plugin);
+ new SpongeUser(id.getUuid(), id.getUsername().get(), plugin);
}
public void performCleanup() {
@@ -182,7 +183,8 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
@Override
public SpongeUser getByUsername(String name) {
for (SpongeUser user : getAll().values()) {
- if (user.getName().equalsIgnoreCase(name)) {
+ Optional n = user.getName();
+ if (n.isPresent() && n.get().equalsIgnoreCase(name)) {
return user;
}
}
diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java
index 82f1dbed..686228b0 100644
--- a/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java
+++ b/sponge/src/main/java/me/lucko/luckperms/sponge/model/SpongeUser.java
@@ -98,7 +98,7 @@ public class SpongeUser extends User {
private synchronized void checkData() {
if (parent.getUserData() == null) {
- plugin.getLog().warn("User " + parent.getName() + " - " + parent.getUuid() + " does not have any data loaded.");
+ plugin.getLog().warn("User " + parent.getName().orElse("unknown") + " - " + parent.getUuid() + " does not have any data loaded.");
parent.setupData(false);
}
}