mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-09-03 18:00:25 +02:00
Maybe fix sponge permissions not expiring
This commit is contained in:
parent
d5bc1cdf5d
commit
9fdb4fa25f
|
@ -25,6 +25,7 @@ package me.lucko.luckperms.api.sponge;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
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.unescapeCharacters;
|
||||
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(of = {"holder"})
|
||||
public class LuckPermsSubject implements Subject {
|
||||
@Getter
|
||||
private final PermissionHolder holder;
|
||||
private final EnduringData enduringData;
|
||||
private final TransientData transientData;
|
||||
private final LuckPermsService service;
|
||||
|
||||
public LuckPermsSubject(PermissionHolder holder, LuckPermsService service) {
|
||||
this.holder = holder;
|
||||
this.enduringData = new EnduringData(this, service, holder);
|
||||
this.transientData = new TransientData(service, holder);
|
||||
this.service = service;
|
||||
|
@ -165,16 +169,16 @@ public class LuckPermsSubject implements Subject {
|
|||
|
||||
@Override
|
||||
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);
|
||||
if (transientOptions.containsKey(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();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import lombok.NonNull;
|
|||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||
import me.lucko.luckperms.api.sponge.LuckPermsSubject;
|
||||
import me.lucko.luckperms.api.sponge.simple.SimpleSubject;
|
||||
import me.lucko.luckperms.core.PermissionHolder;
|
||||
import me.lucko.luckperms.groups.GroupManager;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
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.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class GroupCollection implements SubjectCollection {
|
||||
private final LuckPermsService service;
|
||||
private final GroupManager manager;
|
||||
private final Set<LuckPermsSubject> cache = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
@ -52,7 +55,16 @@ public class GroupCollection implements SubjectCollection {
|
|||
@Override
|
||||
public Subject get(@NonNull String 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);
|
||||
|
|
|
@ -27,6 +27,7 @@ import lombok.NonNull;
|
|||
import me.lucko.luckperms.api.sponge.LuckPermsService;
|
||||
import me.lucko.luckperms.api.sponge.LuckPermsSubject;
|
||||
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.UserManager;
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
|
@ -39,12 +40,14 @@ import java.util.AbstractMap;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class UserCollection implements SubjectCollection {
|
||||
private final LuckPermsService service;
|
||||
private final UserManager manager;
|
||||
private final Set<LuckPermsSubject> cache = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
|
@ -53,19 +56,32 @@ public class UserCollection implements SubjectCollection {
|
|||
|
||||
@Override
|
||||
public Subject get(@NonNull String id) {
|
||||
PermissionHolder holder = null;
|
||||
try {
|
||||
UUID u = UUID.fromString(id);
|
||||
if (manager.isLoaded(u)) {
|
||||
return new LuckPermsSubject(manager.get(u), service);
|
||||
holder = manager.get(u);
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
User user = manager.get(id);
|
||||
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?
|
||||
// If I do load/create it, this method should always be called async??.... errr.
|
||||
return new SimpleSubject(id, service, this);
|
||||
|
|
Loading…
Reference in New Issue
Block a user