Change user housekeeper to be more lenient towards API usage (#3143)

This commit is contained in:
Luck 2021-08-25 19:30:46 +01:00
parent 93683c3a2f
commit a182768cfa
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -63,17 +63,20 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
return internal == null ? null : internal.getApiProxy(); return internal == null ? null : internal.getApiProxy();
} }
private net.luckperms.api.model.user.User proxyAndRegisterUsage(User internal) {
if (internal != null) {
this.plugin.getUserManager().getHouseKeeper().registerApiUsage(internal.getUniqueId());
}
return proxy(internal);
}
@Override @Override
public @NonNull CompletableFuture<net.luckperms.api.model.user.User> loadUser(@NonNull UUID uniqueId, @Nullable String username) { public @NonNull CompletableFuture<net.luckperms.api.model.user.User> loadUser(@NonNull UUID uniqueId, @Nullable String username) {
Objects.requireNonNull(uniqueId, "uuid"); Objects.requireNonNull(uniqueId, "uuid");
ApiUtils.checkUsername(username, this.plugin); ApiUtils.checkUsername(username, this.plugin);
if (this.plugin.getUserManager().getIfLoaded(uniqueId) == null) {
this.plugin.getUserManager().getHouseKeeper().registerApiUsage(uniqueId);
}
return this.plugin.getStorage().loadUser(uniqueId, username) return this.plugin.getStorage().loadUser(uniqueId, username)
.thenApply(this::proxy); .thenApply(this::proxyAndRegisterUsage);
} }
@Override @Override
@ -154,13 +157,13 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
@Override @Override
public net.luckperms.api.model.user.User getUser(@NonNull UUID uniqueId) { public net.luckperms.api.model.user.User getUser(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uuid"); Objects.requireNonNull(uniqueId, "uuid");
return proxy(this.handle.getIfLoaded(uniqueId)); return proxyAndRegisterUsage(this.handle.getIfLoaded(uniqueId));
} }
@Override @Override
public net.luckperms.api.model.user.User getUser(@NonNull String username) { public net.luckperms.api.model.user.User getUser(@NonNull String username) {
Objects.requireNonNull(username, "name"); Objects.requireNonNull(username, "name");
return proxy(this.handle.getByUsername(username)); return proxyAndRegisterUsage(this.handle.getByUsername(username));
} }
@Override @Override