Small fixes to context system
This commit is contained in:
parent
c53623dd67
commit
4da7fe4ff9
@ -177,8 +177,7 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendCommandUsage(Sender sender, String label) {
|
private void sendCommandUsage(Sender sender, String label) {
|
||||||
sender.sendMessage(Util.color("&6Running &bLuckPerms v" + plugin.getVersion() + "&6."));
|
Util.sendPluginMessage(sender, "&6Running &bLuckPerms v" + plugin.getVersion() + "&6.");
|
||||||
|
|
||||||
mainCommands.stream()
|
mainCommands.stream()
|
||||||
.filter(c -> c.isAuthorized(sender))
|
.filter(c -> c.isAuthorized(sender))
|
||||||
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + String.format(c.getUsage(), label)));
|
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + String.format(c.getUsage(), label)));
|
||||||
|
@ -39,6 +39,6 @@ public class ServerCalculator<T> extends ContextCalculator<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isContextApplicable(T subject, Map.Entry<String, String> context) {
|
public boolean isContextApplicable(T subject, Map.Entry<String, String> context) {
|
||||||
return context.getKey().equals("server") && server.equals(context.getValue());
|
return context.getKey().equals("server") && server.equalsIgnoreCase(context.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import org.spongepowered.api.util.Tristate;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class LuckPermsUserSubject extends LuckPermsSubject {
|
public class LuckPermsUserSubject extends LuckPermsSubject {
|
||||||
@ -62,7 +63,7 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
@Override
|
@Override
|
||||||
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission) {
|
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission) {
|
||||||
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
ContextData cd = contextData.computeIfAbsent(context, this::calculatePermissions);
|
ContextData cd = contextData.computeIfAbsent(context, map -> calculatePermissions(map, false));
|
||||||
|
|
||||||
me.lucko.luckperms.api.Tristate t = cd.getPermissionValue(permission);
|
me.lucko.luckperms.api.Tristate t = cd.getPermissionValue(permission);
|
||||||
if (t != me.lucko.luckperms.api.Tristate.UNDEFINED) {
|
if (t != me.lucko.luckperms.api.Tristate.UNDEFINED) {
|
||||||
@ -72,7 +73,7 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContextData calculatePermissions(Map<String, String> context) {
|
public ContextData calculatePermissions(Map<String, String> context, boolean apply) {
|
||||||
Map<String, Boolean> toApply = user.exportNodes(
|
Map<String, Boolean> toApply = user.exportNodes(
|
||||||
new Contexts(
|
new Contexts(
|
||||||
context,
|
context,
|
||||||
@ -88,8 +89,10 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
ContextData existing = contextData.get(context);
|
ContextData existing = contextData.get(context);
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
existing = new ContextData(this, context, service);
|
existing = new ContextData(this, context, service);
|
||||||
|
if (apply) {
|
||||||
contextData.put(context, existing);
|
contextData.put(context, existing);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boolean different = false;
|
boolean different = false;
|
||||||
if (toApply.size() != existing.getPermissionCache().size()) {
|
if (toApply.size() != existing.getPermissionCache().size()) {
|
||||||
@ -113,13 +116,13 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
|
|||||||
return existing;
|
return existing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculatePermissions(Set<Context> contexts) {
|
public void calculatePermissions(Set<Context> contexts, boolean apply) {
|
||||||
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
Map<String, String> context = contexts.stream().collect(Collectors.toMap(Context::getKey, Context::getValue));
|
||||||
calculatePermissions(context);
|
calculatePermissions(context, apply);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateActivePermissions() {
|
public void calculateActivePermissions(boolean apply) {
|
||||||
calculatePermissions(getActiveContexts());
|
calculatePermissions(getActiveContexts(), apply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class ContextUpdateTask implements Runnable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
for (LuckPermsUserSubject subject : userCollection.getUsers().values()) {
|
for (LuckPermsUserSubject subject : userCollection.getUsers().values()) {
|
||||||
Set<Map<String, String>> contexts = new HashSet<>(subject.getContextData().keySet());
|
Set<Map<String, String>> contexts = new HashSet<>(subject.getContextData().keySet());
|
||||||
contexts.forEach(subject::calculatePermissions);
|
contexts.forEach(map -> subject.calculatePermissions(map, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,6 @@ class SpongeUser extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LuckPermsUserSubject us = uc.getUsers().get(getUuid());
|
LuckPermsUserSubject us = uc.getUsers().get(getUuid());
|
||||||
us.calculateActivePermissions();
|
us.calculateActivePermissions(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user