Apply world rewrites on-top of the real world name, and apply recursively (#255)

This commit is contained in:
Luck 2017-05-09 13:07:39 +01:00
parent 6817945e12
commit e835b31277
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 26 additions and 15 deletions

View File

@ -27,8 +27,6 @@ package me.lucko.luckperms.bukkit;
import lombok.RequiredArgsConstructor;
import com.google.common.collect.Maps;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.config.ConfigKeys;
@ -44,11 +42,10 @@ public class WorldCalculator implements ContextCalculator<Player> {
@Override
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
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.toLowerCase()));
String world = subject.getWorld().getName().toLowerCase();
while (!accumulator.has(WORLD_KEY, world)) {
accumulator.add(WORLD_KEY, world);
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
}
return accumulator;

View File

@ -25,13 +25,16 @@
package me.lucko.luckperms.bungee;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@RequiredArgsConstructor
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
private static final String WORLD_KEY = "world";
@ -39,12 +42,14 @@ public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer>
return player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
}
private final LuckPermsPlugin plugin;
@Override
public MutableContextSet giveApplicableContext(ProxiedPlayer subject, MutableContextSet accumulator) {
String server = getServer(subject);
if (server != null) {
accumulator.add(Maps.immutableEntry(WORLD_KEY, server.toLowerCase()));
while (server != null && !accumulator.has(WORLD_KEY, server)) {
accumulator.add(WORLD_KEY, server);
server = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(server, server);
}
return accumulator;

View File

@ -218,7 +218,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
cachedStateManager = new CachedStateManager(this);
contextManager = new ContextManager<>();
BackendServerCalculator serverCalculator = new BackendServerCalculator();
BackendServerCalculator serverCalculator = new BackendServerCalculator(this);
contextManager.registerCalculator(serverCalculator);
StaticCalculator<ProxiedPlayer> staticCalculator = new StaticCalculator<>(getConfiguration());

View File

@ -267,7 +267,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
cachedStateManager = new CachedStateManager(this);
contextManager = new ContextManager<>();
contextManager.registerCalculator(new WorldCalculator());
contextManager.registerCalculator(new WorldCalculator(this));
StaticCalculator<Subject> staticCalculator = new StaticCalculator<>(getConfiguration());
contextManager.registerCalculator(staticCalculator);

View File

@ -29,14 +29,18 @@ import lombok.RequiredArgsConstructor;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.service.context.Context;
import org.spongepowered.api.service.permission.Subject;
@RequiredArgsConstructor
public class WorldCalculator implements ContextCalculator<Subject> {
private static final String WORLD_KEY = "world";
private final LuckPermsPlugin plugin;
@Override
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
@ -46,7 +50,12 @@ public class WorldCalculator implements ContextCalculator<Subject> {
}
Player p = ((Player) source);
accumulator.add(Context.WORLD_KEY, p.getWorld().getName().toLowerCase());
String world = p.getWorld().getName().toLowerCase();
while (!accumulator.has(WORLD_KEY, world)) {
accumulator.add(WORLD_KEY, world);
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
}
return accumulator;
}