Implement accumulation of static contexts from a file

This commit is contained in:
Luck
2017-04-03 01:42:49 +01:00
Unverified
parent 2749563f5d
commit 0ec19a8fee
12 changed files with 93 additions and 75 deletions
@@ -47,7 +47,7 @@ import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LuckPermsConfiguration;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.contexts.ContextManager;
import me.lucko.luckperms.common.contexts.ServerCalculator;
import me.lucko.luckperms.common.contexts.StaticCalculator;
import me.lucko.luckperms.common.core.UuidCache;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.dependencies.Dependency;
@@ -273,7 +273,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
contextManager = new ContextManager<>();
worldCalculator = new WorldCalculator(this);
contextManager.registerCalculator(worldCalculator);
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration()));
contextManager.registerCalculator(new StaticCalculator<>(getConfiguration()));
// Provide vault support
tryVaultHook(false);
@@ -560,6 +560,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
MutableContextSet set = MutableContextSet.create();
set.add("server", getConfiguration().get(ConfigKeys.SERVER));
set.add("world", s);
set.addAll(configuration.getStaticContexts().getContextSet());
return set.makeImmutable();
})
.collect(Collectors.toList())
@@ -574,6 +575,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
MutableContextSet set = MutableContextSet.create();
set.add("server", getConfiguration().get(ConfigKeys.VAULT_SERVER));
set.add("world", s);
set.addAll(configuration.getStaticContexts().getContextSet());
return set.makeImmutable();
})
.collect(Collectors.toList())
@@ -33,8 +33,6 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import org.bukkit.entity.Player;
import java.util.Map;
@RequiredArgsConstructor
public class WorldCalculator implements ContextCalculator<Player> {
private static final String WORLD_KEY = "world";
@@ -43,7 +41,8 @@ public class WorldCalculator implements ContextCalculator<Player> {
@Override
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
String world = getWorld(subject);
String world = subject.getWorld().getName();
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world);
if (world != null) {
accumulator.add(Maps.immutableEntry(WORLD_KEY, world));
@@ -51,19 +50,4 @@ public class WorldCalculator implements ContextCalculator<Player> {
return accumulator;
}
@Override
public boolean isContextApplicable(Player subject, Map.Entry<String, String> context) {
if (!context.getKey().equals(WORLD_KEY)) {
return false;
}
String world = getWorld(subject);
return world != null && world.equals(context.getValue());
}
private String getWorld(Player player) {
String world = player.getWorld().getName();
return plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world);
}
}