Small fixes to context system

This commit is contained in:
Luck 2016-09-25 16:55:14 +01:00
parent c53623dd67
commit 4da7fe4ff9
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 14 additions and 12 deletions

View File

@ -177,8 +177,7 @@ public class CommandManager {
}
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()
.filter(c -> c.isAuthorized(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&e-> &d" + String.format(c.getUsage(), label)));

View File

@ -39,6 +39,6 @@ public class ServerCalculator<T> extends ContextCalculator<T> {
@Override
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());
}
}

View File

@ -39,6 +39,7 @@ import org.spongepowered.api.util.Tristate;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
public class LuckPermsUserSubject extends LuckPermsSubject {
@ -62,7 +63,7 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
@Override
public Tristate getPermissionValue(@NonNull Set<Context> contexts, @NonNull String permission) {
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);
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(
new Contexts(
context,
@ -88,7 +89,9 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
ContextData existing = contextData.get(context);
if (existing == null) {
existing = new ContextData(this, context, service);
contextData.put(context, existing);
if (apply) {
contextData.put(context, existing);
}
}
boolean different = false;
@ -113,13 +116,13 @@ public class LuckPermsUserSubject extends LuckPermsSubject {
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));
calculatePermissions(context);
calculatePermissions(context, apply);
}
public void calculateActivePermissions() {
calculatePermissions(getActiveContexts());
public void calculateActivePermissions(boolean apply) {
calculatePermissions(getActiveContexts(), apply);
}

View File

@ -38,7 +38,7 @@ public class ContextUpdateTask implements Runnable {
public void run() {
for (LuckPermsUserSubject subject : userCollection.getUsers().values()) {
Set<Map<String, String>> contexts = new HashSet<>(subject.getContextData().keySet());
contexts.forEach(subject::calculatePermissions);
contexts.forEach(map -> subject.calculatePermissions(map, true));
}
}

View File

@ -49,6 +49,6 @@ class SpongeUser extends User {
}
LuckPermsUserSubject us = uc.getUsers().get(getUuid());
us.calculateActivePermissions();
us.calculateActivePermissions(true);
}
}