mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Apply world rewrites on-top of the real world name, and apply recursively (#255)
This commit is contained in:
parent
6817945e12
commit
e835b31277
@ -27,8 +27,6 @@ package me.lucko.luckperms.bukkit;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
import me.lucko.luckperms.api.context.MutableContextSet;
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
@ -44,11 +42,10 @@ public class WorldCalculator implements ContextCalculator<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(Player subject, MutableContextSet accumulator) {
|
||||||
String world = subject.getWorld().getName();
|
String world = subject.getWorld().getName().toLowerCase();
|
||||||
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world);
|
while (!accumulator.has(WORLD_KEY, world)) {
|
||||||
|
accumulator.add(WORLD_KEY, world);
|
||||||
if (world != null) {
|
world = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world).toLowerCase();
|
||||||
accumulator.add(Maps.immutableEntry(WORLD_KEY, world.toLowerCase()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return accumulator;
|
return accumulator;
|
||||||
|
@ -25,13 +25,16 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bungee;
|
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.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
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;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
|
public class BackendServerCalculator implements ContextCalculator<ProxiedPlayer> {
|
||||||
private static final String WORLD_KEY = "world";
|
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());
|
return player.getServer() == null ? null : (player.getServer().getInfo() == null ? null : player.getServer().getInfo().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(ProxiedPlayer subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(ProxiedPlayer subject, MutableContextSet accumulator) {
|
||||||
String server = getServer(subject);
|
String server = getServer(subject);
|
||||||
|
while (server != null && !accumulator.has(WORLD_KEY, server)) {
|
||||||
if (server != null) {
|
accumulator.add(WORLD_KEY, server);
|
||||||
accumulator.add(Maps.immutableEntry(WORLD_KEY, server.toLowerCase()));
|
server = plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(server, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
return accumulator;
|
return accumulator;
|
||||||
|
@ -218,7 +218,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
cachedStateManager = new CachedStateManager(this);
|
cachedStateManager = new CachedStateManager(this);
|
||||||
|
|
||||||
contextManager = new ContextManager<>();
|
contextManager = new ContextManager<>();
|
||||||
BackendServerCalculator serverCalculator = new BackendServerCalculator();
|
BackendServerCalculator serverCalculator = new BackendServerCalculator(this);
|
||||||
contextManager.registerCalculator(serverCalculator);
|
contextManager.registerCalculator(serverCalculator);
|
||||||
|
|
||||||
StaticCalculator<ProxiedPlayer> staticCalculator = new StaticCalculator<>(getConfiguration());
|
StaticCalculator<ProxiedPlayer> staticCalculator = new StaticCalculator<>(getConfiguration());
|
||||||
|
@ -267,7 +267,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
cachedStateManager = new CachedStateManager(this);
|
cachedStateManager = new CachedStateManager(this);
|
||||||
|
|
||||||
contextManager = new ContextManager<>();
|
contextManager = new ContextManager<>();
|
||||||
contextManager.registerCalculator(new WorldCalculator());
|
contextManager.registerCalculator(new WorldCalculator(this));
|
||||||
|
|
||||||
StaticCalculator<Subject> staticCalculator = new StaticCalculator<>(getConfiguration());
|
StaticCalculator<Subject> staticCalculator = new StaticCalculator<>(getConfiguration());
|
||||||
contextManager.registerCalculator(staticCalculator);
|
contextManager.registerCalculator(staticCalculator);
|
||||||
|
@ -29,14 +29,18 @@ import lombok.RequiredArgsConstructor;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.context.ContextCalculator;
|
import me.lucko.luckperms.api.context.ContextCalculator;
|
||||||
import me.lucko.luckperms.api.context.MutableContextSet;
|
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.command.CommandSource;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
import org.spongepowered.api.service.context.Context;
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class WorldCalculator implements ContextCalculator<Subject> {
|
public class WorldCalculator implements ContextCalculator<Subject> {
|
||||||
|
private static final String WORLD_KEY = "world";
|
||||||
|
|
||||||
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
public MutableContextSet giveApplicableContext(Subject subject, MutableContextSet accumulator) {
|
||||||
@ -46,7 +50,12 @@ public class WorldCalculator implements ContextCalculator<Subject> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player p = ((Player) source);
|
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;
|
return accumulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user