Always load user data caches alongside user instances

This commit is contained in:
Luck 2017-05-02 16:55:08 +01:00
parent f56bb251e9
commit 163e6e0f2a
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
18 changed files with 59 additions and 162 deletions

View File

@ -214,7 +214,7 @@ user-info-general: >
{PREFIX}&f- &3Meta: &a{8} {PREFIX}&f- &3Meta: &a{8}
user-info-data: > user-info-data: >
{PREFIX}&f- &aCached Data:\n {PREFIX}&f- &aCached Data:\n
{PREFIX}&f- &3Is Loaded: {0}\n {PREFIX}&f- &3Has contextual data: {0}\n
{PREFIX}&f- &3Current Contexts: {1}\n {PREFIX}&f- &3Current Contexts: {1}\n
{PREFIX}&f- &3Current Prefix: {2}\n {PREFIX}&f- &3Current Prefix: {2}\n
{PREFIX}&f- &3Current Suffix: {3} {PREFIX}&f- &3Current Suffix: {3}

View File

@ -29,7 +29,6 @@ import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.bukkit.model.Injector; import me.lucko.luckperms.bukkit.model.Injector;
import me.lucko.luckperms.bukkit.model.LPPermissible; import me.lucko.luckperms.bukkit.model.LPPermissible;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
@ -182,14 +181,7 @@ public class BukkitListener implements Listener {
// We assume all users are not op, but those who are need extra calculation. // We assume all users are not op, but those who are need extra calculation.
if (player.isOp()) { if (player.isOp()) {
plugin.doAsync(() -> { plugin.doAsync(() -> user.getUserData().preCalculate(plugin.getPreProcessContexts(true)));
UserCache userData = user.getUserData();
if (userData == null) {
return;
}
userData.preCalculate(plugin.getPreProcessContexts(true));
});
} }
} }

View File

@ -42,7 +42,6 @@ import me.lucko.luckperms.bukkit.model.LPPermissible;
import me.lucko.luckperms.bukkit.vault.VaultHook; import me.lucko.luckperms.bukkit.vault.VaultHook;
import me.lucko.luckperms.common.api.ApiHandler; import me.lucko.luckperms.common.api.ApiHandler;
import me.lucko.luckperms.common.api.ApiProvider; import me.lucko.luckperms.common.api.ApiProvider;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.caching.handlers.CachedStateManager; import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
import me.lucko.luckperms.common.calculators.CalculatorFactory; import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.commands.sender.Sender; import me.lucko.luckperms.common.commands.sender.Sender;
@ -474,12 +473,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
return; return;
} }
UserCache userData = user.getUserData(); Map<String, Boolean> backing = user.getUserData().getPermissionData(permissible.calculateContexts()).getImmutableBacking();
if (userData == null) {
return;
}
Map<String, Boolean> backing = userData.getPermissionData(permissible.calculateContexts()).getImmutableBacking();
boolean op = Optional.ofNullable(backing.get("luckperms.autoop")).orElse(false); boolean op = Optional.ofNullable(backing.get("luckperms.autoop")).orElse(false);
player.setOp(op); player.setOp(op);
} catch (Exception ignored) {} } catch (Exception ignored) {}

View File

@ -76,7 +76,7 @@ public class LPPermissible extends PermissibleBase {
private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new ConcurrentHashMap<>(); private final Map<String, PermissionAttachmentInfo> attachmentPermissions = new ConcurrentHashMap<>();
private final List<PermissionAttachment> attachments = Collections.synchronizedList(new LinkedList<>()); private final List<PermissionAttachment> attachments = Collections.synchronizedList(new LinkedList<>());
public LPPermissible(@NonNull Player parent, User user, LPBukkitPlugin plugin) { public LPPermissible(@NonNull Player parent, @NonNull User user, @NonNull LPBukkitPlugin plugin) {
super(parent); super(parent);
this.user = user; this.user = user;
this.parent = parent; this.parent = parent;
@ -139,10 +139,6 @@ public class LPPermissible extends PermissibleBase {
); );
} }
private boolean hasData() {
return user != null && user.getUserData() != null;
}
@Override @Override
public void setOp(boolean value) { public void setOp(boolean value) {
parent.setOp(value); parent.setOp(value);
@ -150,7 +146,7 @@ public class LPPermissible extends PermissibleBase {
@Override @Override
public boolean isPermissionSet(@NonNull String name) { public boolean isPermissionSet(@NonNull String name) {
return hasData() && user.getUserData().getPermissionData(calculateContexts()).getPermissionValue(name) != Tristate.UNDEFINED; return user.getUserData().getPermissionData(calculateContexts()).getPermissionValue(name) != Tristate.UNDEFINED;
} }
@Override @Override
@ -160,11 +156,9 @@ public class LPPermissible extends PermissibleBase {
@Override @Override
public boolean hasPermission(@NonNull String name) { public boolean hasPermission(@NonNull String name) {
if (hasData()) { Tristate ts = user.getUserData().getPermissionData(calculateContexts()).getPermissionValue(name);
Tristate ts = user.getUserData().getPermissionData(calculateContexts()).getPermissionValue(name); if (ts != Tristate.UNDEFINED) {
if (ts != Tristate.UNDEFINED) { return ts.asBoolean();
return ts.asBoolean();
}
} }
return Permission.DEFAULT_PERMISSION.getValue(isOp()); return Permission.DEFAULT_PERMISSION.getValue(isOp());
@ -172,11 +166,9 @@ public class LPPermissible extends PermissibleBase {
@Override @Override
public boolean hasPermission(@NonNull Permission perm) { public boolean hasPermission(@NonNull Permission perm) {
if (hasData()) { Tristate ts = user.getUserData().getPermissionData(calculateContexts()).getPermissionValue(perm.getName());
Tristate ts = user.getUserData().getPermissionData(calculateContexts()).getPermissionValue(perm.getName()); if (ts != Tristate.UNDEFINED) {
if (ts != Tristate.UNDEFINED) { return ts.asBoolean();
return ts.asBoolean();
}
} }
return perm.getDefault().getValue(isOp()); return perm.getDefault().getValue(isOp());
@ -187,13 +179,11 @@ public class LPPermissible extends PermissibleBase {
Set<PermissionAttachmentInfo> perms = new HashSet<>(); Set<PermissionAttachmentInfo> perms = new HashSet<>();
perms.addAll(attachmentPermissions.values()); perms.addAll(attachmentPermissions.values());
if (hasData()) { perms.addAll(
perms.addAll( user.getUserData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet().stream()
user.getUserData().getPermissionData(calculateContexts()).getImmutableBacking().entrySet().stream() .map(e -> new PermissionAttachmentInfo(parent, e.getKey(), null, e.getValue()))
.map(e -> new PermissionAttachmentInfo(parent, e.getKey(), null, e.getValue())) .collect(Collectors.toList())
.collect(Collectors.toList()) );
);
}
return perms; return perms;
} }
@ -288,7 +278,7 @@ public class LPPermissible extends PermissibleBase {
calculateChildPermissions(attachment.getPermissions(), false, attachment); calculateChildPermissions(attachment.getPermissions(), false, attachment);
} }
if (hasData() && invalidate) { if (invalidate) {
user.getUserData().invalidatePermissionCalculators(); user.getUserData().invalidatePermissionCalculators();
} }
} }

View File

@ -126,10 +126,6 @@ public class VaultChatHook extends Chat {
perms.log("Getting meta: '" + node + "' for user " + user.getFriendlyName() + " 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;
}
String ret = user.getUserData().getMetaData(perms.createContextForWorld(world)).getMeta().get(node); String ret = user.getUserData().getMetaData(perms.createContextForWorld(world)).getMeta().get(node);
if (ret == null) { if (ret == null) {
return defaultValue; return defaultValue;
@ -144,10 +140,6 @@ public class VaultChatHook extends Chat {
perms.log("Getting " + (prefix ? "prefix" : "suffix") + " for user " + user.getFriendlyName() + " 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 "";
}
MetaData data = user.getUserData().getMetaData(perms.createContextForWorld(world)); MetaData data = user.getUserData().getMetaData(perms.createContextForWorld(world));
String v = prefix ? data.getPrefix() : data.getSuffix(); String v = prefix ? data.getPrefix() : data.getSuffix();
return v == null ? "" : unescapeCharacters(v); return v == null ? "" : unescapeCharacters(v);

View File

@ -164,10 +164,6 @@ public class VaultPermissionHook extends Permission {
User user = plugin.getUserManager().getByUsername(player); User user = plugin.getUserManager().getByUsername(player);
if (user == null) return false; if (user == null) return false;
if (user.getUserData() == null) {
return false;
}
// Effectively fallback to the standard Bukkit #hasPermission check. // Effectively fallback to the standard Bukkit #hasPermission check.
return user.getUserData().getPermissionData(createContextForWorld(world)).getPermissionValue(permission).asBoolean(); return user.getUserData().getPermissionData(createContextForWorld(world)).getPermissionValue(permission).asBoolean();
} }

View File

@ -29,7 +29,6 @@ import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.api.context.MutableContextSet; import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
@ -166,14 +165,6 @@ public class BungeeListener implements Listener {
return; return;
} }
UserData userData = user.getUserData();
if (userData == null) {
plugin.getLog().warn("Player " + player.getName() + " does not have any user data setup.");
plugin.doAsync(() -> user.setupData(false));
e.setHasPermission(false);
return;
}
Contexts contexts = new Contexts( Contexts contexts = new Contexts(
plugin.getContextManager().getApplicableContext(player), plugin.getContextManager().getApplicableContext(player),
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS), plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
@ -184,7 +175,7 @@ public class BungeeListener implements Listener {
false false
); );
Tristate result = userData.getPermissionData(contexts).getPermissionValue(e.getPermission()); Tristate result = user.getUserData().getPermissionData(contexts).getPermissionValue(e.getPermission());
if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) { if (result == Tristate.UNDEFINED && plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
return; // just use the result provided by the proxy when the event was created return; // just use the result provided by the proxy when the event was created
} }
@ -207,10 +198,6 @@ public class BungeeListener implements Listener {
if (user == null) { if (user == null) {
return; return;
} }
UserData userData = user.getUserData();
if (userData == null) {
return;
}
Contexts contexts = new Contexts( Contexts contexts = new Contexts(
set.makeImmutable(), set.makeImmutable(),
@ -222,7 +209,7 @@ public class BungeeListener implements Listener {
false false
); );
userData.preCalculate(contexts); user.getUserData().preCalculate(contexts);
}); });
} }
} }

View File

@ -97,12 +97,13 @@ public final class UserDelegate extends PermissionHolderDelegate implements User
@Override @Override
public Optional<UserData> getUserDataCache() { public Optional<UserData> getUserDataCache() {
return Optional.ofNullable(handle.getUserData()); // TODO Deprecate this and return a nonnull instance
return Optional.of(handle.getUserData());
} }
@Override @Override
public void setupDataCache() { public void setupDataCache() {
handle.setupData(false); handle.preCalculateData(false);
} }
@Override @Override

View File

@ -37,7 +37,6 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.caching.MetaData; import me.lucko.luckperms.api.caching.MetaData;
import me.lucko.luckperms.api.caching.PermissionData; import me.lucko.luckperms.api.caching.PermissionData;
import me.lucko.luckperms.api.caching.UserData; import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.common.calculators.CalculatorFactory;
import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.utils.ExtractedContexts; import me.lucko.luckperms.common.utils.ExtractedContexts;
@ -50,17 +49,11 @@ import java.util.concurrent.TimeUnit;
@RequiredArgsConstructor @RequiredArgsConstructor
public class UserCache implements UserData { public class UserCache implements UserData {
/** /**
* The user whom this data instance is representing * The user whom this data instance is representing
*/ */
private final User user; private final User user;
/**
* A provider of {@link me.lucko.luckperms.common.calculators.PermissionCalculator}s for the instance
*/
private final CalculatorFactory calculatorFactory;
private final LoadingCache<Contexts, PermissionCache> permission = Caffeine.newBuilder() private final LoadingCache<Contexts, PermissionCache> permission = Caffeine.newBuilder()
.expireAfterAccess(10, TimeUnit.MINUTES) .expireAfterAccess(10, TimeUnit.MINUTES)
.build(new CacheLoader<Contexts, PermissionCache>() { .build(new CacheLoader<Contexts, PermissionCache>() {
@ -103,7 +96,7 @@ public class UserCache implements UserData {
@Override @Override
public PermissionCache calculatePermissions(@NonNull Contexts contexts) { public PermissionCache calculatePermissions(@NonNull Contexts contexts) {
PermissionCache data = new PermissionCache(contexts, user, calculatorFactory); PermissionCache data = new PermissionCache(contexts, user, user.getPlugin().getCalculatorFactory());
data.setPermissions(user.exportNodes(ExtractedContexts.generate(contexts), true)); data.setPermissions(user.exportNodes(ExtractedContexts.generate(contexts), true));
return data; return data;
} }
@ -163,4 +156,9 @@ public class UserCache implements UserData {
meta.cleanUp(); meta.cleanUp();
} }
public void clear() {
permission.invalidateAll();
meta.invalidateAll();
}
} }

View File

@ -26,7 +26,6 @@
package me.lucko.luckperms.common.commands.impl.misc; package me.lucko.luckperms.common.commands.impl.misc;
import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.Tristate;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
@ -71,13 +70,7 @@ public class CheckCommand extends SingleCommand {
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
} }
UserCache data = user.getUserData(); Tristate tristate = user.getUserData().getPermissionData(plugin.getContextForUser(user)).getPermissionValue(permission);
if (data == null) {
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.getFriendlyName(), permission, Util.formatTristate(tristate)); Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, Util.formatTristate(tristate));
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }

View File

@ -26,7 +26,6 @@
package me.lucko.luckperms.common.commands.impl.misc; package me.lucko.luckperms.common.commands.impl.misc;
import me.lucko.luckperms.api.caching.PermissionData; import me.lucko.luckperms.api.caching.PermissionData;
import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.commands.Arg; import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
@ -90,13 +89,7 @@ public class TreeCommand extends SingleCommand {
return CommandResult.STATE_ERROR; return CommandResult.STATE_ERROR;
} }
UserCache data = user.getUserData(); PermissionData permissionData = user.getUserData().getPermissionData(plugin.getContextForUser(user));
if (data == null) {
Message.USER_NO_DATA.send(sender, user.getFriendlyName());
return CommandResult.STATE_ERROR;
}
PermissionData permissionData = data.getPermissionData(plugin.getContextForUser(user));
TreeView view = TreeViewBuilder.newBuilder().rootPosition(selection).maxLevels(maxLevel).build(plugin.getPermissionVault()); TreeView view = TreeViewBuilder.newBuilder().rootPosition(selection).maxLevels(maxLevel).build(plugin.getPermissionVault());
if (!view.hasData()) { if (!view.hasData()) {

View File

@ -28,7 +28,6 @@ package me.lucko.luckperms.common.commands.impl.user;
import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.caching.MetaData; import me.lucko.luckperms.api.caching.MetaData;
import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.common.commands.CommandException; import me.lucko.luckperms.common.commands.CommandException;
import me.lucko.luckperms.common.commands.CommandResult; import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.abstraction.SubCommand; import me.lucko.luckperms.common.commands.abstraction.SubCommand;
@ -90,28 +89,25 @@ public class UserInfo extends SubCommand<User> {
} }
} }
UserData data = user.getUserData();
String context = "&bNone"; String context = "&bNone";
String prefix = "&bNone"; String prefix = "&bNone";
String suffix = "&bNone"; String suffix = "&bNone";
if (data != null) { Contexts contexts = plugin.getContextForUser(user);
Contexts contexts = plugin.getContextForUser(user); if (contexts != null) {
if (contexts != null) { context = contexts.getContexts().toSet().stream()
context = contexts.getContexts().toSet().stream() .map(e -> Util.contextToString(e.getKey(), e.getValue()))
.map(e -> Util.contextToString(e.getKey(), e.getValue())) .collect(Collectors.joining(" "));
.collect(Collectors.joining(" "));
MetaData meta = data.getMetaData(contexts); MetaData meta = user.getUserData().getMetaData(contexts);
if (meta.getPrefix() != null) { if (meta.getPrefix() != null) {
prefix = "&f\"" + meta.getPrefix() + "&f\""; prefix = "&f\"" + meta.getPrefix() + "&f\"";
} }
if (meta.getSuffix() != null) { if (meta.getSuffix() != null) {
suffix = "&f\"" + meta.getSuffix() + "&f\""; suffix = "&f\"" + meta.getSuffix() + "&f\"";
}
} }
} }
Message.USER_INFO_DATA.send(sender, Util.formatBoolean(data != null), context, prefix, suffix); Message.USER_INFO_DATA.send(sender, Util.formatBoolean(contexts != null), context, prefix, suffix);
return CommandResult.SUCCESS; return CommandResult.SUCCESS;
} }
} }

View File

@ -294,7 +294,7 @@ public enum Message {
USER_INFO_DATA( USER_INFO_DATA(
"{PREFIX}&f- &aCached Data:" + "\n" + "{PREFIX}&f- &aCached Data:" + "\n" +
"{PREFIX}&f- &3Is Loaded: {0}" + "\n" + "{PREFIX}&f- &3Has contextual data: {0}" + "\n" +
"{PREFIX}&f- &3Current Contexts: {1}" + "\n" + "{PREFIX}&f- &3Current Contexts: {1}" + "\n" +
"{PREFIX}&f- &3Current Prefix: {2}" + "\n" + "{PREFIX}&f- &3Current Prefix: {2}" + "\n" +
"{PREFIX}&f- &3Current Suffix: {3}", "{PREFIX}&f- &3Current Suffix: {3}",

View File

@ -29,7 +29,6 @@ import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
import me.lucko.luckperms.api.caching.UserData;
import me.lucko.luckperms.common.api.delegates.UserDelegate; import me.lucko.luckperms.common.api.delegates.UserDelegate;
import me.lucko.luckperms.common.caching.UserCache; import me.lucko.luckperms.common.caching.UserCache;
import me.lucko.luckperms.common.caching.handlers.HolderReference; import me.lucko.luckperms.common.caching.handlers.HolderReference;
@ -69,7 +68,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
* The users data cache instance, if present. * The users data cache instance, if present.
*/ */
@Getter @Getter
private UserCache userData = null; private final UserCache userData;
@Getter @Getter
private BufferedRequest<Void> refreshBuffer = new BufferedRequest<Void>(1000L, r -> getPlugin().doAsync(r)) { private BufferedRequest<Void> refreshBuffer = new BufferedRequest<Void>(1000L, r -> getPlugin().doAsync(r)) {
@ -86,15 +85,20 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
public User(UUID uuid, LuckPermsPlugin plugin) { public User(UUID uuid, LuckPermsPlugin plugin) {
super(uuid.toString(), plugin); super(uuid.toString(), plugin);
this.uuid = uuid; this.uuid = uuid;
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this); this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
this.userData = new UserCache(this);
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, userData);
} }
public User(UUID uuid, String name, LuckPermsPlugin plugin) { public User(UUID uuid, String name, LuckPermsPlugin plugin) {
super(uuid.toString(), plugin); super(uuid.toString(), plugin);
this.uuid = uuid; this.uuid = uuid;
setName(name, true);
setName(name, true);
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this); this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
this.userData = new UserCache(this);
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, userData);
} }
@Override @Override
@ -156,15 +160,8 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
* Sets up the UserData cache * Sets up the UserData cache
* Blocking call. * Blocking call.
*/ */
public synchronized void setupData(boolean op) { public synchronized void preCalculateData(boolean op) {
if (userData != null) {
return;
}
userData = new UserCache(this, getPlugin().getCalculatorFactory());
userData.preCalculate(getPlugin().getPreProcessContexts(op)); userData.preCalculate(getPlugin().getPreProcessContexts(op));
getPlugin().getApiProvider().getEventFactory().handleUserCacheLoad(this, userData);
getPlugin().onUserRefresh(this); getPlugin().onUserRefresh(this);
} }
@ -172,7 +169,7 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
* Removes the UserData cache from this user * Removes the UserData cache from this user
*/ */
public void unregisterData() { public void unregisterData() {
userData = null; userData.clear();
} }
/** /**
@ -180,14 +177,9 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
* Blocking call. * Blocking call.
*/ */
private synchronized void refreshPermissions() { private synchronized void refreshPermissions() {
UserData ud = userData; userData.recalculatePermissions();
if (ud == null) { userData.recalculateMeta();
return; getPlugin().getApiProvider().getEventFactory().handleUserDataRecalculate(this, userData);
}
ud.recalculatePermissions();
ud.recalculateMeta();
getPlugin().getApiProvider().getEventFactory().handleUserDataRecalculate(this, ud);
getPlugin().onUserRefresh(this); getPlugin().onUserRefresh(this);
} }
@ -213,9 +205,6 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
} }
public void cleanup() { public void cleanup() {
UserCache cache = userData; userData.cleanup();
if (cache != null) {
cache.cleanup();
}
} }
} }

View File

@ -91,7 +91,7 @@ public class LoginHelper {
plugin.getStorage().force().saveUser(user).join(); plugin.getStorage().force().saveUser(user).join();
} }
user.setupData(false); // Pretty nasty calculation call. Sets up the caching system so data is ready when the user joins. user.preCalculateData(false); // Pretty nasty calculation call. Sets up the caching system so data is ready when the user joins.
} }
final long time = System.currentTimeMillis() - startTime; final long time = System.currentTimeMillis() - startTime;

View File

@ -83,12 +83,8 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
.expireAfterWrite(1, TimeUnit.MINUTES) .expireAfterWrite(1, TimeUnit.MINUTES)
.build(u -> { .build(u -> {
if (isLoaded(UserIdentifier.of(u, null))) { if (isLoaded(UserIdentifier.of(u, null))) {
SpongeUser user = get(u); SpongeUser user = get(u);
if (user.getUserData() == null) { user.preCalculateData(false);
user.setupData(false);
}
return get(u).getSpongeData(); return get(u).getSpongeData();
} }
@ -101,12 +97,7 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
throw new RuntimeException(); throw new RuntimeException();
} }
user.setupData(false); user.preCalculateData(false);
if (user.getUserData() == null) {
getPlugin().getLog().warn("User data not present for requested user id: " + u);
}
return user.getSpongeData(); return user.getSpongeData();
}); });

View File

@ -96,13 +96,6 @@ public class SpongeUser extends User {
return (now - lastUse) > 600000; return (now - lastUse) > 600000;
} }
private synchronized void checkData() {
if (parent.getUserData() == null) {
plugin.getLog().warn("User " + parent.getName().orElse("unknown") + " - " + parent.getUuid() + " does not have any data loaded.");
parent.setupData(false);
}
}
@Override @Override
public String getIdentifier() { public String getIdentifier() {
return plugin.getUuidCache().getExternalUUID(parent.getUuid()).toString(); return plugin.getUuidCache().getExternalUUID(parent.getUuid()).toString();
@ -134,7 +127,6 @@ public class SpongeUser extends User {
public Tristate getPermissionValue(ContextSet contexts, String permission) { public Tristate getPermissionValue(ContextSet contexts, String permission) {
logUsage(); logUsage();
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PERMISSION_VALUE)) { try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PERMISSION_VALUE)) {
checkData();
return parent.getUserData().getPermissionData(plugin.getService().calculateContexts(contexts)).getPermissionValue(permission); return parent.getUserData().getPermissionData(plugin.getService().calculateContexts(contexts)).getPermissionValue(permission);
} }
} }
@ -153,7 +145,6 @@ public class SpongeUser extends User {
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PARENTS)) { try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PARENTS)) {
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder(); ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
checkData();
for (String perm : parent.getUserData().getPermissionData(plugin.getService().calculateContexts(contexts)).getImmutableBacking().keySet()) { for (String perm : parent.getUserData().getPermissionData(plugin.getService().calculateContexts(contexts)).getImmutableBacking().keySet()) {
if (!perm.startsWith("group.")) { if (!perm.startsWith("group.")) {
continue; continue;
@ -176,8 +167,6 @@ public class SpongeUser extends User {
public Optional<String> getOption(ContextSet contexts, String s) { public Optional<String> getOption(ContextSet contexts, String s) {
logUsage(); logUsage();
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_OPTION)) { try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_OPTION)) {
checkData();
MetaData data = parent.getUserData().getMetaData(plugin.getService().calculateContexts(contexts)); MetaData data = parent.getUserData().getMetaData(plugin.getService().calculateContexts(contexts));
if (s.equalsIgnoreCase("prefix")) { if (s.equalsIgnoreCase("prefix")) {
if (data.getPrefix() != null) { if (data.getPrefix() != null) {

View File

@ -280,8 +280,6 @@ public class LuckPermsService implements PermissionService {
for (User user : plugin.getUserManager().getAll().values()) { for (User user : plugin.getUserManager().getAll().values()) {
UserCache userCache = user.getUserData(); UserCache userCache = user.getUserData();
if (userCache == null) continue;
userCache.invalidateCache(); userCache.invalidateCache();
} }
@ -305,8 +303,6 @@ public class LuckPermsService implements PermissionService {
for (User user : plugin.getUserManager().getAll().values()) { for (User user : plugin.getUserManager().getAll().values()) {
UserCache userCache = user.getUserData(); UserCache userCache = user.getUserData();
if (userCache == null) continue;
userCache.invalidateCache(); userCache.invalidateCache();
} }
} }