Refactor LP PermissionService to implement a modified API & add proxied classes
This commit is contained in:
@@ -123,7 +123,7 @@ public class ApiProvider implements LuckPermsApi {
|
||||
|
||||
@Override
|
||||
public User getUser(@NonNull UUID uuid) {
|
||||
final me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(uuid);
|
||||
final me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().getIfLoaded(uuid);
|
||||
return user == null ? null : user.getDelegate();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CheckCommand extends SingleCommand {
|
||||
User user;
|
||||
UUID u = Util.parseUuid(target);
|
||||
if (u != null) {
|
||||
user = plugin.getUserManager().get(u);
|
||||
user = plugin.getUserManager().getIfLoaded(u);
|
||||
} else {
|
||||
user = plugin.getUserManager().getByUsername(target);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class TreeCommand extends SingleCommand {
|
||||
User user;
|
||||
UUID u = Util.parseUuid(player);
|
||||
if (u != null) {
|
||||
user = plugin.getUserManager().get(u);
|
||||
user = plugin.getUserManager().getIfLoaded(u);
|
||||
} else {
|
||||
user = plugin.getUserManager().getByUsername(player);
|
||||
}
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class UserMainCommand extends MainCommand<User> {
|
||||
Message.LOADING_ERROR.send(sender);
|
||||
}
|
||||
|
||||
User user = plugin.getUserManager().get(u);
|
||||
User user = plugin.getUserManager().getIfLoaded(u);
|
||||
if (user == null) {
|
||||
Message.LOADING_ERROR.send(sender);
|
||||
return null;
|
||||
|
||||
@@ -30,7 +30,7 @@ import lombok.Getter;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.utils.ArgumentChecker;
|
||||
@@ -214,9 +214,9 @@ public class ArgumentUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static ContextSet handleContexts(int fromIndex, List<String> args) {
|
||||
public static ImmutableContextSet handleContexts(int fromIndex, List<String> args) {
|
||||
if (args.size() <= fromIndex) {
|
||||
return ContextSet.empty();
|
||||
return ImmutableContextSet.empty();
|
||||
}
|
||||
|
||||
MutableContextSet contextSet = MutableContextSet.create();
|
||||
|
||||
@@ -216,7 +216,7 @@ public class Exporter implements Runnable {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
plugin.getStorage().loadUser(uuid, "null").join();
|
||||
User user = plugin.getUserManager().get(uuid);
|
||||
User user = plugin.getUserManager().getIfLoaded(uuid);
|
||||
output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
|
||||
|
||||
boolean inDefault = false;
|
||||
|
||||
@@ -48,6 +48,8 @@ public interface Manager<I, T extends Identifiable<I>> extends Function<I, T> {
|
||||
/**
|
||||
* Gets or creates an object by id
|
||||
*
|
||||
* <p>Should only every be called by the storage implementation.</p>
|
||||
*
|
||||
* @param id The id to search by
|
||||
* @return a {@link T} object if the object is loaded or makes and returns a new object
|
||||
*/
|
||||
|
||||
@@ -47,7 +47,7 @@ public interface UserManager extends Manager<UserIdentifier, User> {
|
||||
* @param uuid The uuid to search by
|
||||
* @return a {@link User} object if the user is loaded, returns null if the user is not loaded
|
||||
*/
|
||||
User get(UUID uuid);
|
||||
User getIfLoaded(UUID uuid);
|
||||
|
||||
/**
|
||||
* Gives the user the default group if necessary.
|
||||
|
||||
+2
-2
@@ -123,7 +123,7 @@ public class GenericUserManager extends AbstractManager<UserIdentifier, User> im
|
||||
}
|
||||
|
||||
@Override
|
||||
public User get(UUID uuid) {
|
||||
public User getIfLoaded(UUID uuid) {
|
||||
return getIfLoaded(UserIdentifier.of(uuid, null));
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class GenericUserManager extends AbstractManager<UserIdentifier, User> im
|
||||
@Override
|
||||
public void scheduleUnload(UUID uuid) {
|
||||
plugin.getScheduler().doAsyncLater(() -> {
|
||||
User user = get(plugin.getUuidCache().getUUID(uuid));
|
||||
User user = getIfLoaded(plugin.getUuidCache().getUUID(uuid));
|
||||
if (user != null && !plugin.isPlayerOnline(uuid)) {
|
||||
user.unregisterData();
|
||||
unload(user);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class AbstractStorage implements Storage {
|
||||
public CompletableFuture<Boolean> loadUser(UUID uuid, String username) {
|
||||
return makeFuture(() -> {
|
||||
if (backing.loadUser(uuid, username)) {
|
||||
plugin.getApiProvider().getEventFactory().handleUserLoad(plugin.getUserManager().get(uuid));
|
||||
plugin.getApiProvider().getEventFactory().handleUserLoad(plugin.getUserManager().getIfLoaded(uuid));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -178,7 +178,7 @@ public abstract class FlatfileBacking extends AbstractBacking {
|
||||
return;
|
||||
}
|
||||
|
||||
User u = plugin.getUserManager().get(uuid);
|
||||
User u = plugin.getUserManager().getIfLoaded(uuid);
|
||||
if (u != null) {
|
||||
plugin.getLog().info("[FileWatcher] Refreshing user " + u.getFriendlyName());
|
||||
plugin.getStorage().loadUser(uuid, "null");
|
||||
|
||||
@@ -73,7 +73,7 @@ public class LoginHelper {
|
||||
}
|
||||
|
||||
plugin.getStorage().force().loadUser(cache.getUUID(u), username).join();
|
||||
User user = plugin.getUserManager().get(cache.getUUID(u));
|
||||
User user = plugin.getUserManager().getIfLoaded(cache.getUUID(u));
|
||||
if (user == null) {
|
||||
plugin.getLog().warn("Failed to load user: " + username);
|
||||
throw new RuntimeException("Failed to load user");
|
||||
@@ -101,7 +101,7 @@ public class LoginHelper {
|
||||
}
|
||||
|
||||
public static void refreshPlayer(LuckPermsPlugin plugin, UUID uuid) {
|
||||
final User user = plugin.getUserManager().get(plugin.getUuidCache().getUUID(uuid));
|
||||
final User user = plugin.getUserManager().getIfLoaded(plugin.getUuidCache().getUUID(uuid));
|
||||
if (user != null) {
|
||||
user.getRefreshBuffer().requestDirectly();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user