Remove subjects from cache when they leave the server

This commit is contained in:
Luck 2016-08-29 13:32:21 +01:00
parent 9fdb4fa25f
commit d4cf6a5ad7
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 17 additions and 1 deletions

View File

@ -93,6 +93,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
private me.lucko.luckperms.api.Logger log; private me.lucko.luckperms.api.Logger log;
private Importer importer; private Importer importer;
private ConsecutiveExecutor consecutiveExecutor; private ConsecutiveExecutor consecutiveExecutor;
private LuckPermsService service;
@Listener @Listener
public void onEnable(GamePreInitializationEvent event) { public void onEnable(GamePreInitializationEvent event) {
@ -121,7 +122,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
consecutiveExecutor = new ConsecutiveExecutor(commandManager); consecutiveExecutor = new ConsecutiveExecutor(commandManager);
getLog().info("Registering PermissionService..."); getLog().info("Registering PermissionService...");
Sponge.getServiceManager().setProvider(this, PermissionService.class, new LuckPermsService(this)); Sponge.getServiceManager().setProvider(this, PermissionService.class, (service = new LuckPermsService(this)));
getLog().info("Registering API..."); getLog().info("Registering API...");
apiProvider = new ApiProvider(this); apiProvider = new ApiProvider(this);

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms; package me.lucko.luckperms;
import me.lucko.luckperms.api.sponge.LuckPermsSubject;
import me.lucko.luckperms.constants.Message; import me.lucko.luckperms.constants.Message;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import me.lucko.luckperms.utils.AbstractListener; import me.lucko.luckperms.utils.AbstractListener;
@ -30,6 +31,8 @@ import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.profile.GameProfile; import org.spongepowered.api.profile.GameProfile;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import java.util.Iterator;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public class SpongeListener extends AbstractListener { public class SpongeListener extends AbstractListener {
private final LPSpongePlugin plugin; private final LPSpongePlugin plugin;
@ -75,5 +78,12 @@ public class SpongeListener extends AbstractListener {
@Listener @Listener
public void onClientLeave(ClientConnectionEvent.Disconnect e) { public void onClientLeave(ClientConnectionEvent.Disconnect e) {
onLeave(e.getTargetEntity().getUniqueId()); onLeave(e.getTargetEntity().getUniqueId());
Iterator<LuckPermsSubject> iterator = plugin.getService().getUserSubjects().getCache().iterator();
while (iterator.hasNext()) {
LuckPermsSubject subject = iterator.next();
if (subject.getIdentifier().equalsIgnoreCase(e.getTargetEntity().getUniqueId().toString())) {
iterator.remove();
}
}
} }
} }

View File

@ -23,6 +23,7 @@
package me.lucko.luckperms.api.sponge.collections; package me.lucko.luckperms.api.sponge.collections;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import me.lucko.luckperms.api.sponge.LuckPermsService; import me.lucko.luckperms.api.sponge.LuckPermsService;
import me.lucko.luckperms.api.sponge.LuckPermsSubject; import me.lucko.luckperms.api.sponge.LuckPermsSubject;
@ -47,6 +48,8 @@ import java.util.stream.Collectors;
public class UserCollection implements SubjectCollection { public class UserCollection implements SubjectCollection {
private final LuckPermsService service; private final LuckPermsService service;
private final UserManager manager; private final UserManager manager;
@Getter
private final Set<LuckPermsSubject> cache = ConcurrentHashMap.newKeySet(); private final Set<LuckPermsSubject> cache = ConcurrentHashMap.newKeySet();
@Override @Override
@ -82,6 +85,8 @@ public class UserCollection implements SubjectCollection {
return subject; return subject;
} }
service.getPlugin().getLog().warn("Couldn't get subject for: " + id);
// What am I meant to do here? What if no user is loaded? Load it? Create it? // What am I meant to do here? What if no user is loaded? Load it? Create it?
// If I do load/create it, this method should always be called async??.... errr. // If I do load/create it, this method should always be called async??.... errr.
return new SimpleSubject(id, service, this); return new SimpleSubject(id, service, this);