Maybe fix sponge permissions not expiring

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

View File

@ -25,6 +25,7 @@ package me.lucko.luckperms.api.sponge;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import me.lucko.luckperms.api.Node; import me.lucko.luckperms.api.Node;
@ -49,13 +50,16 @@ import java.util.stream.Collectors;
import static me.lucko.luckperms.utils.ArgumentChecker.escapeCharacters; import static me.lucko.luckperms.utils.ArgumentChecker.escapeCharacters;
import static me.lucko.luckperms.utils.ArgumentChecker.unescapeCharacters; import static me.lucko.luckperms.utils.ArgumentChecker.unescapeCharacters;
@AllArgsConstructor @EqualsAndHashCode(of = {"holder"})
public class LuckPermsSubject implements Subject { public class LuckPermsSubject implements Subject {
@Getter
private final PermissionHolder holder;
private final EnduringData enduringData; private final EnduringData enduringData;
private final TransientData transientData; private final TransientData transientData;
private final LuckPermsService service; private final LuckPermsService service;
public LuckPermsSubject(PermissionHolder holder, LuckPermsService service) { public LuckPermsSubject(PermissionHolder holder, LuckPermsService service) {
this.holder = holder;
this.enduringData = new EnduringData(this, service, holder); this.enduringData = new EnduringData(this, service, holder);
this.transientData = new TransientData(service, holder); this.transientData = new TransientData(service, holder);
this.service = service; this.service = service;
@ -165,16 +169,16 @@ public class LuckPermsSubject implements Subject {
@Override @Override
public Optional<String> getOption(Set<Context> set, String s) { public Optional<String> getOption(Set<Context> set, String s) {
Map<String, String> enduringOptions = enduringData.getOptions(set);
if (enduringOptions.containsKey(s)) {
return Optional.of(enduringOptions.get(s));
}
Map<String, String> transientOptions = enduringData.getOptions(set); Map<String, String> transientOptions = enduringData.getOptions(set);
if (transientOptions.containsKey(s)) { if (transientOptions.containsKey(s)) {
return Optional.of(transientOptions.get(s)); return Optional.of(transientOptions.get(s));
} }
Map<String, String> enduringOptions = enduringData.getOptions(set);
if (enduringOptions.containsKey(s)) {
return Optional.of(enduringOptions.get(s));
}
return Optional.empty(); return Optional.empty();
} }

View File

@ -27,6 +27,7 @@ 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;
import me.lucko.luckperms.api.sponge.simple.SimpleSubject; import me.lucko.luckperms.api.sponge.simple.SimpleSubject;
import me.lucko.luckperms.core.PermissionHolder;
import me.lucko.luckperms.groups.GroupManager; import me.lucko.luckperms.groups.GroupManager;
import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.PermissionService; import org.spongepowered.api.service.permission.PermissionService;
@ -37,12 +38,14 @@ import org.spongepowered.api.service.permission.SubjectData;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
public class GroupCollection implements SubjectCollection { public class GroupCollection implements SubjectCollection {
private final LuckPermsService service; private final LuckPermsService service;
private final GroupManager manager; private final GroupManager manager;
private final Set<LuckPermsSubject> cache = ConcurrentHashMap.newKeySet();
@Override @Override
public String getIdentifier() { public String getIdentifier() {
@ -52,7 +55,16 @@ public class GroupCollection implements SubjectCollection {
@Override @Override
public Subject get(@NonNull String id) { public Subject get(@NonNull String id) {
if (manager.isLoaded(id)) { if (manager.isLoaded(id)) {
return new LuckPermsSubject(manager.get(id), service); PermissionHolder holder = manager.get(id);
for (LuckPermsSubject subject : cache) {
if (subject.getHolder().getObjectName().equalsIgnoreCase(holder.getObjectName())) {
return subject;
}
}
LuckPermsSubject subject = new LuckPermsSubject(manager.get(id), service);
cache.add(subject);
return subject;
} }
return new SimpleSubject(id, service, this); return new SimpleSubject(id, service, this);

View File

@ -27,6 +27,7 @@ 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;
import me.lucko.luckperms.api.sponge.simple.SimpleSubject; import me.lucko.luckperms.api.sponge.simple.SimpleSubject;
import me.lucko.luckperms.core.PermissionHolder;
import me.lucko.luckperms.users.User; import me.lucko.luckperms.users.User;
import me.lucko.luckperms.users.UserManager; import me.lucko.luckperms.users.UserManager;
import org.spongepowered.api.service.context.Context; import org.spongepowered.api.service.context.Context;
@ -39,12 +40,14 @@ import java.util.AbstractMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@AllArgsConstructor @AllArgsConstructor
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;
private final Set<LuckPermsSubject> cache = ConcurrentHashMap.newKeySet();
@Override @Override
public String getIdentifier() { public String getIdentifier() {
@ -53,19 +56,32 @@ public class UserCollection implements SubjectCollection {
@Override @Override
public Subject get(@NonNull String id) { public Subject get(@NonNull String id) {
PermissionHolder holder = null;
try { try {
UUID u = UUID.fromString(id); UUID u = UUID.fromString(id);
if (manager.isLoaded(u)) { if (manager.isLoaded(u)) {
return new LuckPermsSubject(manager.get(u), service); holder = manager.get(u);
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
User user = manager.get(id); User user = manager.get(id);
if (user != null) { if (user != null) {
return new LuckPermsSubject(user, service); holder = user;
} }
} }
if (holder != null) {
for (LuckPermsSubject subject : cache) {
if (subject.getHolder().getObjectName().equalsIgnoreCase(holder.getObjectName())) {
return subject;
}
}
LuckPermsSubject subject = new LuckPermsSubject(holder, service);
cache.add(subject);
return subject;
}
// 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);