mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-09-09 22:00:40 +02:00
Add config option to disable built-in contexts
This commit is contained in:
@@ -190,7 +190,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
protected void setupContextManager() {
|
protected void setupContextManager() {
|
||||||
this.contextManager = new BukkitContextManager(this);
|
this.contextManager = new BukkitContextManager(this);
|
||||||
|
|
||||||
BukkitPlayerCalculator playerCalculator = new BukkitPlayerCalculator(this);
|
BukkitPlayerCalculator playerCalculator = new BukkitPlayerCalculator(this, getConfiguration().get(ConfigKeys.DISABLED_CONTEXTS));
|
||||||
this.bootstrap.getServer().getPluginManager().registerEvents(playerCalculator, this.bootstrap.getLoader());
|
this.bootstrap.getServer().getPluginManager().registerEvents(playerCalculator, this.bootstrap.getLoader());
|
||||||
this.contextManager.registerCalculator(playerCalculator);
|
this.contextManager.registerCalculator(playerCalculator);
|
||||||
}
|
}
|
||||||
|
@@ -51,6 +51,8 @@ import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class BukkitPlayerCalculator implements ContextCalculator<Player>, Listener {
|
public class BukkitPlayerCalculator implements ContextCalculator<Player>, Listener {
|
||||||
private static final EnumNamer<GameMode> GAMEMODE_NAMER = new EnumNamer<>(
|
private static final EnumNamer<GameMode> GAMEMODE_NAMER = new EnumNamer<>(
|
||||||
GameMode.class,
|
GameMode.class,
|
||||||
@@ -69,41 +71,58 @@ public class BukkitPlayerCalculator implements ContextCalculator<Player>, Listen
|
|||||||
|
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
public BukkitPlayerCalculator(LPBukkitPlugin plugin) {
|
private final boolean gamemode;
|
||||||
|
private final boolean world;
|
||||||
|
private final boolean dimensionType;
|
||||||
|
|
||||||
|
public BukkitPlayerCalculator(LPBukkitPlugin plugin, Set<String> disabled) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.gamemode = !disabled.contains(DefaultContextKeys.GAMEMODE_KEY);
|
||||||
|
this.world = !disabled.contains(DefaultContextKeys.WORLD_KEY);
|
||||||
|
this.dimensionType = !disabled.contains(DefaultContextKeys.DIMENSION_TYPE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions") // bukkit lies
|
@SuppressWarnings("ConstantConditions") // bukkit lies
|
||||||
@Override
|
@Override
|
||||||
public void calculate(@NonNull Player subject, @NonNull ContextConsumer consumer) {
|
public void calculate(@NonNull Player subject, @NonNull ContextConsumer consumer) {
|
||||||
GameMode mode = subject.getGameMode();
|
if (this.gamemode) {
|
||||||
if (mode != null) {
|
GameMode mode = subject.getGameMode();
|
||||||
consumer.accept(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
if (mode != null) {
|
||||||
|
consumer.accept(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
World world = subject.getWorld();
|
World world = subject.getWorld();
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
Environment environment = world.getEnvironment();
|
Environment environment = world.getEnvironment();
|
||||||
if (environment != null) {
|
if (this.dimensionType && environment != null) {
|
||||||
consumer.accept(DefaultContextKeys.DIMENSION_TYPE_KEY, DIMENSION_TYPE_NAMER.name(environment));
|
consumer.accept(DefaultContextKeys.DIMENSION_TYPE_KEY, DIMENSION_TYPE_NAMER.name(environment));
|
||||||
}
|
}
|
||||||
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(world.getName(), consumer);
|
if (this.world) {
|
||||||
|
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(world.getName(), consumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContextSet estimatePotentialContexts() {
|
public ContextSet estimatePotentialContexts() {
|
||||||
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
||||||
for (GameMode mode : GameMode.values()) {
|
if (this.gamemode) {
|
||||||
builder.add(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
for (GameMode mode : GameMode.values()) {
|
||||||
|
builder.add(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (Environment env : Environment.values()) {
|
if (this.dimensionType) {
|
||||||
builder.add(DefaultContextKeys.DIMENSION_TYPE_KEY, DIMENSION_TYPE_NAMER.name(env));
|
for (Environment env : Environment.values()) {
|
||||||
|
builder.add(DefaultContextKeys.DIMENSION_TYPE_KEY, DIMENSION_TYPE_NAMER.name(env));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (World world : this.plugin.getBootstrap().getServer().getWorlds()) {
|
if (this.world) {
|
||||||
String worldName = world.getName();
|
for (World world : this.plugin.getBootstrap().getServer().getWorlds()) {
|
||||||
if (Context.isValidValue(worldName)) {
|
String worldName = world.getName();
|
||||||
builder.add(DefaultContextKeys.WORLD_KEY, worldName);
|
if (Context.isValidValue(worldName)) {
|
||||||
|
builder.add(DefaultContextKeys.WORLD_KEY, worldName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
@@ -111,16 +130,22 @@ public class BukkitPlayerCalculator implements ContextCalculator<Player>, Listen
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWorldChange(PlayerChangedWorldEvent e) {
|
public void onWorldChange(PlayerChangedWorldEvent e) {
|
||||||
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
if (this.world || this.dimensionType) {
|
||||||
|
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoinWorld(PlayerJoinEvent e) {
|
public void onPlayerJoinWorld(PlayerJoinEvent e) {
|
||||||
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
if (this.world || this.dimensionType) {
|
||||||
|
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onGameModeChange(PlayerGameModeChangeEvent e) {
|
public void onGameModeChange(PlayerGameModeChangeEvent e) {
|
||||||
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
if (this.gamemode) {
|
||||||
|
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -435,6 +435,11 @@ post-traversal-inheritance-sort: false
|
|||||||
# entries in A are also in B.
|
# entries in A are also in B.
|
||||||
context-satisfy-mode: at-least-one-value-per-key
|
context-satisfy-mode: at-least-one-value-per-key
|
||||||
|
|
||||||
|
# LuckPerms has a number of built-in contexts. These can be disabled by adding the context key to
|
||||||
|
# the list below.
|
||||||
|
disabled-contexts:
|
||||||
|
# - "world"
|
||||||
|
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
# | Permission resolution settings | #
|
# | Permission resolution settings | #
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
|
@@ -35,6 +35,7 @@ import me.lucko.luckperms.bungee.messaging.BungeeMessagingFactory;
|
|||||||
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
||||||
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
||||||
import me.lucko.luckperms.common.command.CommandManager;
|
import me.lucko.luckperms.common.command.CommandManager;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
||||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||||
@@ -50,6 +51,7 @@ import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
|||||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||||
|
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.context.DefaultContextKeys;
|
||||||
import net.luckperms.api.query.QueryOptions;
|
import net.luckperms.api.query.QueryOptions;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
@@ -141,11 +143,14 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
|
|||||||
protected void setupContextManager() {
|
protected void setupContextManager() {
|
||||||
this.contextManager = new BungeeContextManager(this);
|
this.contextManager = new BungeeContextManager(this);
|
||||||
|
|
||||||
BungeePlayerCalculator playerCalculator = new BungeePlayerCalculator(this);
|
Set<String> disabledContexts = getConfiguration().get(ConfigKeys.DISABLED_CONTEXTS);
|
||||||
this.bootstrap.getProxy().getPluginManager().registerListener(this.bootstrap.getLoader(), playerCalculator);
|
if (!disabledContexts.contains(DefaultContextKeys.WORLD_KEY)) {
|
||||||
this.contextManager.registerCalculator(playerCalculator);
|
BungeePlayerCalculator playerCalculator = new BungeePlayerCalculator(this);
|
||||||
|
this.bootstrap.getProxy().getPluginManager().registerListener(this.bootstrap.getLoader(), playerCalculator);
|
||||||
|
this.contextManager.registerCalculator(playerCalculator);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.bootstrap.getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
|
if (!disabledContexts.contains("proxy") && this.bootstrap.getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
|
||||||
this.contextManager.registerCalculator(new RedisBungeeCalculator());
|
this.contextManager.registerCalculator(new RedisBungeeCalculator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -443,6 +443,11 @@ post-traversal-inheritance-sort: false
|
|||||||
# entries in A are also in B.
|
# entries in A are also in B.
|
||||||
context-satisfy-mode: at-least-one-value-per-key
|
context-satisfy-mode: at-least-one-value-per-key
|
||||||
|
|
||||||
|
# LuckPerms has a number of built-in contexts. These can be disabled by adding the context key to
|
||||||
|
# the list below.
|
||||||
|
disabled-contexts:
|
||||||
|
# - "world"
|
||||||
|
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
# | Permission resolution settings | #
|
# | Permission resolution settings | #
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
|
@@ -130,6 +130,16 @@ public final class ConfigKeys {
|
|||||||
return ContextSatisfyMode.AT_LEAST_ONE_VALUE_PER_KEY;
|
return ContextSatisfyMode.AT_LEAST_ONE_VALUE_PER_KEY;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A set of disabled contexts
|
||||||
|
*/
|
||||||
|
public static final ConfigKey<Set<String>> DISABLED_CONTEXTS = notReloadable(key(c -> {
|
||||||
|
return c.getStringList("disabled-contexts", ImmutableList.of())
|
||||||
|
.stream()
|
||||||
|
.map(String::toLowerCase)
|
||||||
|
.collect(ImmutableCollectors.toSet());
|
||||||
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # If the servers own UUID cache/lookup facility should be used when there is no record for a player in the LuckPerms cache.
|
* # If the servers own UUID cache/lookup facility should be used when there is no record for a player in the LuckPerms cache.
|
||||||
*/
|
*/
|
||||||
|
@@ -27,6 +27,7 @@ package me.lucko.luckperms.fabric;
|
|||||||
|
|
||||||
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
||||||
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
||||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||||
@@ -141,7 +142,7 @@ public class LPFabricPlugin extends AbstractLuckPermsPlugin {
|
|||||||
protected void setupContextManager() {
|
protected void setupContextManager() {
|
||||||
this.contextManager = new FabricContextManager(this);
|
this.contextManager = new FabricContextManager(this);
|
||||||
|
|
||||||
FabricPlayerCalculator playerCalculator = new FabricPlayerCalculator(this);
|
FabricPlayerCalculator playerCalculator = new FabricPlayerCalculator(this, getConfiguration().get(ConfigKeys.DISABLED_CONTEXTS));
|
||||||
playerCalculator.registerListeners();
|
playerCalculator.registerListeners();
|
||||||
this.contextManager.registerCalculator(playerCalculator);
|
this.contextManager.registerCalculator(playerCalculator);
|
||||||
}
|
}
|
||||||
|
@@ -46,6 +46,7 @@ import net.minecraft.world.GameMode;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEntity> {
|
public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEntity> {
|
||||||
private static final EnumNamer<GameMode> GAMEMODE_NAMER = new EnumNamer<>(
|
private static final EnumNamer<GameMode> GAMEMODE_NAMER = new EnumNamer<>(
|
||||||
@@ -55,8 +56,15 @@ public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEnt
|
|||||||
|
|
||||||
private final LPFabricPlugin plugin;
|
private final LPFabricPlugin plugin;
|
||||||
|
|
||||||
public FabricPlayerCalculator(LPFabricPlugin plugin) {
|
private final boolean gamemode;
|
||||||
|
private final boolean world;
|
||||||
|
//private final boolean dimensionType;
|
||||||
|
|
||||||
|
public FabricPlayerCalculator(LPFabricPlugin plugin, Set<String> disabled) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.gamemode = !disabled.contains(DefaultContextKeys.GAMEMODE_KEY);
|
||||||
|
this.world = !disabled.contains(DefaultContextKeys.WORLD_KEY);
|
||||||
|
//this.dimensionType = !disabled.contains(DefaultContextKeys.DIMENSION_TYPE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerListeners() {
|
public void registerListeners() {
|
||||||
@@ -66,27 +74,31 @@ public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEnt
|
|||||||
@Override
|
@Override
|
||||||
public void calculate(@NonNull ServerPlayerEntity target, @NonNull ContextConsumer consumer) {
|
public void calculate(@NonNull ServerPlayerEntity target, @NonNull ContextConsumer consumer) {
|
||||||
GameMode mode = target.interactionManager.getGameMode();
|
GameMode mode = target.interactionManager.getGameMode();
|
||||||
if (mode != null && mode != GameMode.NOT_SET) {
|
if (this.gamemode && mode != null && mode != GameMode.NOT_SET) {
|
||||||
consumer.accept(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
consumer.accept(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: figure out dimension type context too
|
// TODO: figure out dimension type context too
|
||||||
ServerWorld world = target.getServerWorld();
|
ServerWorld world = target.getServerWorld();
|
||||||
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(getContextKey(world.getRegistryKey().getValue()), consumer);
|
if (this.world) {
|
||||||
|
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(getContextKey(world.getRegistryKey().getValue()), consumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContextSet estimatePotentialContexts() {
|
public ContextSet estimatePotentialContexts() {
|
||||||
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
||||||
|
|
||||||
for (GameMode mode : GameMode.values()) {
|
if (this.gamemode) {
|
||||||
builder.add(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
for (GameMode mode : GameMode.values()) {
|
||||||
|
builder.add(DefaultContextKeys.GAMEMODE_KEY, GAMEMODE_NAMER.name(mode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: dimension type
|
// TODO: dimension type
|
||||||
|
|
||||||
Optional<MinecraftServer> server = this.plugin.getBootstrap().getServer();
|
Optional<MinecraftServer> server = this.plugin.getBootstrap().getServer();
|
||||||
if (server.isPresent()) {
|
if (this.world && server.isPresent()) {
|
||||||
Iterable<ServerWorld> worlds = server.get().getWorlds();
|
Iterable<ServerWorld> worlds = server.get().getWorlds();
|
||||||
for (ServerWorld world : worlds) {
|
for (ServerWorld world : worlds) {
|
||||||
String worldName = getContextKey(world.getRegistryKey().getValue());
|
String worldName = getContextKey(world.getRegistryKey().getValue());
|
||||||
@@ -107,7 +119,9 @@ public class FabricPlayerCalculator implements ContextCalculator<ServerPlayerEnt
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onWorldChange(ServerWorld origin, ServerWorld destination, ServerPlayerEntity player) {
|
private void onWorldChange(ServerWorld origin, ServerWorld destination, ServerPlayerEntity player) {
|
||||||
this.plugin.getContextManager().invalidateCache(player);
|
if (this.world) {
|
||||||
|
this.plugin.getContextManager().invalidateCache(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -446,6 +446,12 @@ post-traversal-inheritance-sort = false
|
|||||||
# entries in A are also in B.
|
# entries in A are also in B.
|
||||||
context-satisfy-mode = "at-least-one-value-per-key"
|
context-satisfy-mode = "at-least-one-value-per-key"
|
||||||
|
|
||||||
|
# LuckPerms has a number of built-in contexts. These can be disabled by adding the context key to
|
||||||
|
# the list below.
|
||||||
|
disabled-contexts = [
|
||||||
|
# "world"
|
||||||
|
]
|
||||||
|
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
# | Permission resolution settings | #
|
# | Permission resolution settings | #
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
|
@@ -148,7 +148,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
protected void setupContextManager() {
|
protected void setupContextManager() {
|
||||||
this.contextManager = new NukkitContextManager(this);
|
this.contextManager = new NukkitContextManager(this);
|
||||||
|
|
||||||
NukkitPlayerCalculator playerCalculator = new NukkitPlayerCalculator(this);
|
NukkitPlayerCalculator playerCalculator = new NukkitPlayerCalculator(this, getConfiguration().get(ConfigKeys.DISABLED_CONTEXTS));
|
||||||
this.bootstrap.getServer().getPluginManager().registerEvents(playerCalculator, this.bootstrap.getLoader());
|
this.bootstrap.getServer().getPluginManager().registerEvents(playerCalculator, this.bootstrap.getLoader());
|
||||||
this.contextManager.registerCalculator(playerCalculator);
|
this.contextManager.registerCalculator(playerCalculator);
|
||||||
}
|
}
|
||||||
|
@@ -47,37 +47,59 @@ import cn.nukkit.event.entity.EntityLevelChangeEvent;
|
|||||||
import cn.nukkit.event.player.PlayerGameModeChangeEvent;
|
import cn.nukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import cn.nukkit.level.Level;
|
import cn.nukkit.level.Level;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class NukkitPlayerCalculator implements ContextCalculator<Player>, Listener {
|
public class NukkitPlayerCalculator implements ContextCalculator<Player>, Listener {
|
||||||
private static final int[] KNOWN_GAMEMODES = {Player.SURVIVAL, Player.CREATIVE, Player.ADVENTURE, Player.SPECTATOR};
|
private static final int[] KNOWN_GAMEMODES = {Player.SURVIVAL, Player.CREATIVE, Player.ADVENTURE, Player.SPECTATOR};
|
||||||
private static final int[] KNOWN_DIMENSION_TYPES = {Level.DIMENSION_OVERWORLD, Level.DIMENSION_NETHER};
|
private static final int[] KNOWN_DIMENSION_TYPES = {Level.DIMENSION_OVERWORLD, Level.DIMENSION_NETHER};
|
||||||
|
|
||||||
private final LPNukkitPlugin plugin;
|
private final LPNukkitPlugin plugin;
|
||||||
|
|
||||||
public NukkitPlayerCalculator(LPNukkitPlugin plugin) {
|
private final boolean gamemode;
|
||||||
|
private final boolean world;
|
||||||
|
private final boolean dimensionType;
|
||||||
|
|
||||||
|
public NukkitPlayerCalculator(LPNukkitPlugin plugin, Set<String> disabled) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.gamemode = !disabled.contains(DefaultContextKeys.GAMEMODE_KEY);
|
||||||
|
this.world = !disabled.contains(DefaultContextKeys.WORLD_KEY);
|
||||||
|
this.dimensionType = !disabled.contains(DefaultContextKeys.DIMENSION_TYPE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void calculate(@NonNull Player subject, @NonNull ContextConsumer consumer) {
|
public void calculate(@NonNull Player subject, @NonNull ContextConsumer consumer) {
|
||||||
|
if (this.gamemode) {
|
||||||
|
consumer.accept(DefaultContextKeys.GAMEMODE_KEY, getGamemodeName(subject.getGamemode()));
|
||||||
|
}
|
||||||
|
|
||||||
Level level = subject.getLevel();
|
Level level = subject.getLevel();
|
||||||
consumer.accept(DefaultContextKeys.GAMEMODE_KEY, getGamemodeName(subject.getGamemode()));
|
if (this.dimensionType) {
|
||||||
consumer.accept(DefaultContextKeys.DIMENSION_TYPE_KEY, getDimensionName(level.getDimension()));
|
consumer.accept(DefaultContextKeys.DIMENSION_TYPE_KEY, getDimensionName(level.getDimension()));
|
||||||
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(level.getName(), consumer);
|
}
|
||||||
|
if (this.world) {
|
||||||
|
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(level.getName(), consumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContextSet estimatePotentialContexts() {
|
public ContextSet estimatePotentialContexts() {
|
||||||
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
||||||
for (int mode : KNOWN_GAMEMODES) {
|
if (this.gamemode) {
|
||||||
builder.add(DefaultContextKeys.GAMEMODE_KEY, getGamemodeName(mode));
|
for (int mode : KNOWN_GAMEMODES) {
|
||||||
|
builder.add(DefaultContextKeys.GAMEMODE_KEY, getGamemodeName(mode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int dim : KNOWN_DIMENSION_TYPES) {
|
if (this.dimensionType) {
|
||||||
builder.add(DefaultContextKeys.DIMENSION_TYPE_KEY, getDimensionName(dim));
|
for (int dim : KNOWN_DIMENSION_TYPES) {
|
||||||
|
builder.add(DefaultContextKeys.DIMENSION_TYPE_KEY, getDimensionName(dim));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (Level world : this.plugin.getBootstrap().getServer().getLevels().values()) {
|
if (this.world) {
|
||||||
String worldName = world.getName();
|
for (Level world : this.plugin.getBootstrap().getServer().getLevels().values()) {
|
||||||
if (Context.isValidValue(worldName)) {
|
String worldName = world.getName();
|
||||||
builder.add(DefaultContextKeys.WORLD_KEY, worldName);
|
if (Context.isValidValue(worldName)) {
|
||||||
|
builder.add(DefaultContextKeys.WORLD_KEY, worldName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
@@ -104,7 +126,7 @@ public class NukkitPlayerCalculator implements ContextCalculator<Player>, Listen
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWorldChange(EntityLevelChangeEvent e) {
|
public void onWorldChange(EntityLevelChangeEvent e) {
|
||||||
if (e.getEntity() instanceof Player) {
|
if ((this.world || this.dimensionType) && e.getEntity() instanceof Player) {
|
||||||
Player player = (Player) e.getEntity();
|
Player player = (Player) e.getEntity();
|
||||||
this.plugin.getContextManager().signalContextUpdate(player);
|
this.plugin.getContextManager().signalContextUpdate(player);
|
||||||
}
|
}
|
||||||
@@ -112,6 +134,8 @@ public class NukkitPlayerCalculator implements ContextCalculator<Player>, Listen
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onGameModeChange(PlayerGameModeChangeEvent e) {
|
public void onGameModeChange(PlayerGameModeChangeEvent e) {
|
||||||
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
if (this.gamemode) {
|
||||||
|
this.plugin.getContextManager().signalContextUpdate(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -430,6 +430,11 @@ post-traversal-inheritance-sort: false
|
|||||||
# entries in A are also in B.
|
# entries in A are also in B.
|
||||||
context-satisfy-mode: at-least-one-value-per-key
|
context-satisfy-mode: at-least-one-value-per-key
|
||||||
|
|
||||||
|
# LuckPerms has a number of built-in contexts. These can be disabled by adding the context key to
|
||||||
|
# the list below.
|
||||||
|
disabled-contexts:
|
||||||
|
# - "world"
|
||||||
|
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
# | Permission resolution settings | #
|
# | Permission resolution settings | #
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
|
@@ -29,6 +29,7 @@ import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
|||||||
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
||||||
import me.lucko.luckperms.common.command.abstraction.Command;
|
import me.lucko.luckperms.common.command.abstraction.Command;
|
||||||
import me.lucko.luckperms.common.command.access.CommandPermission;
|
import me.lucko.luckperms.common.command.access.CommandPermission;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
||||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||||
@@ -155,7 +156,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin {
|
|||||||
protected void setupContextManager() {
|
protected void setupContextManager() {
|
||||||
this.contextManager = new SpongeContextManager(this);
|
this.contextManager = new SpongeContextManager(this);
|
||||||
|
|
||||||
SpongePlayerCalculator playerCalculator = new SpongePlayerCalculator(this);
|
SpongePlayerCalculator playerCalculator = new SpongePlayerCalculator(this, getConfiguration().get(ConfigKeys.DISABLED_CONTEXTS));
|
||||||
this.bootstrap.getGame().getEventManager().registerListeners(this.bootstrap, playerCalculator);
|
this.bootstrap.getGame().getEventManager().registerListeners(this.bootstrap, playerCalculator);
|
||||||
this.contextManager.registerCalculator(playerCalculator);
|
this.contextManager.registerCalculator(playerCalculator);
|
||||||
}
|
}
|
||||||
|
@@ -55,11 +55,20 @@ import org.spongepowered.api.world.DimensionType;
|
|||||||
import org.spongepowered.api.world.Locatable;
|
import org.spongepowered.api.world.Locatable;
|
||||||
import org.spongepowered.api.world.World;
|
import org.spongepowered.api.world.World;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class SpongePlayerCalculator implements ContextCalculator<Subject> {
|
public class SpongePlayerCalculator implements ContextCalculator<Subject> {
|
||||||
private final LPSpongePlugin plugin;
|
private final LPSpongePlugin plugin;
|
||||||
|
|
||||||
public SpongePlayerCalculator(LPSpongePlugin plugin) {
|
private final boolean gamemode;
|
||||||
|
private final boolean world;
|
||||||
|
private final boolean dimensionType;
|
||||||
|
|
||||||
|
public SpongePlayerCalculator(LPSpongePlugin plugin, Set<String> disabled) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
this.gamemode = !disabled.contains(DefaultContextKeys.GAMEMODE_KEY);
|
||||||
|
this.world = !disabled.contains(DefaultContextKeys.WORLD_KEY);
|
||||||
|
this.dimensionType = !disabled.contains(DefaultContextKeys.DIMENSION_TYPE_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,11 +80,15 @@ public class SpongePlayerCalculator implements ContextCalculator<Subject> {
|
|||||||
|
|
||||||
if (source instanceof Locatable) {
|
if (source instanceof Locatable) {
|
||||||
World world = ((Locatable) source).getWorld();
|
World world = ((Locatable) source).getWorld();
|
||||||
consumer.accept(DefaultContextKeys.DIMENSION_TYPE_KEY, getCatalogTypeName(world.getDimension().getType()));
|
if (this.dimensionType) {
|
||||||
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(world.getName(), consumer);
|
consumer.accept(DefaultContextKeys.DIMENSION_TYPE_KEY, getCatalogTypeName(world.getDimension().getType()));
|
||||||
|
}
|
||||||
|
if (this.world) {
|
||||||
|
this.plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).rewriteAndSubmit(world.getName(), consumer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source instanceof ValueContainer<?>) {
|
if (this.gamemode && source instanceof ValueContainer<?>) {
|
||||||
ValueContainer<?> valueContainer = (ValueContainer<?>) source;
|
ValueContainer<?> valueContainer = (ValueContainer<?>) source;
|
||||||
valueContainer.get(Keys.GAME_MODE).ifPresent(mode -> consumer.accept(DefaultContextKeys.GAMEMODE_KEY, getCatalogTypeName(mode)));
|
valueContainer.get(Keys.GAME_MODE).ifPresent(mode -> consumer.accept(DefaultContextKeys.GAMEMODE_KEY, getCatalogTypeName(mode)));
|
||||||
}
|
}
|
||||||
@@ -86,13 +99,17 @@ public class SpongePlayerCalculator implements ContextCalculator<Subject> {
|
|||||||
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl();
|
||||||
Game game = this.plugin.getBootstrap().getGame();
|
Game game = this.plugin.getBootstrap().getGame();
|
||||||
|
|
||||||
for (GameMode mode : game.getRegistry().getAllOf(CatalogTypes.GAME_MODE)) {
|
if (this.gamemode) {
|
||||||
builder.add(DefaultContextKeys.GAMEMODE_KEY, getCatalogTypeName(mode));
|
for (GameMode mode : game.getRegistry().getAllOf(CatalogTypes.GAME_MODE)) {
|
||||||
|
builder.add(DefaultContextKeys.GAMEMODE_KEY, getCatalogTypeName(mode));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (DimensionType dim : game.getRegistry().getAllOf(CatalogTypes.DIMENSION_TYPE)) {
|
if (this.dimensionType) {
|
||||||
builder.add(DefaultContextKeys.DIMENSION_TYPE_KEY, getCatalogTypeName(dim));
|
for (DimensionType dim : game.getRegistry().getAllOf(CatalogTypes.DIMENSION_TYPE)) {
|
||||||
|
builder.add(DefaultContextKeys.DIMENSION_TYPE_KEY, getCatalogTypeName(dim));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (game.isServerAvailable()) {
|
if (this.world && game.isServerAvailable()) {
|
||||||
for (World world : game.getServer().getWorlds()) {
|
for (World world : game.getServer().getWorlds()) {
|
||||||
String worldName = world.getName();
|
String worldName = world.getName();
|
||||||
if (Context.isValidValue(worldName)) {
|
if (Context.isValidValue(worldName)) {
|
||||||
@@ -114,6 +131,10 @@ public class SpongePlayerCalculator implements ContextCalculator<Subject> {
|
|||||||
|
|
||||||
@Listener(order = Order.LAST)
|
@Listener(order = Order.LAST)
|
||||||
public void onWorldChange(MoveEntityEvent.Teleport e) {
|
public void onWorldChange(MoveEntityEvent.Teleport e) {
|
||||||
|
if (!(this.world || this.dimensionType)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Entity targetEntity = e.getTargetEntity();
|
Entity targetEntity = e.getTargetEntity();
|
||||||
if (!(targetEntity instanceof Subject)) {
|
if (!(targetEntity instanceof Subject)) {
|
||||||
return;
|
return;
|
||||||
@@ -129,7 +150,7 @@ public class SpongePlayerCalculator implements ContextCalculator<Subject> {
|
|||||||
@Listener(order = Order.LAST)
|
@Listener(order = Order.LAST)
|
||||||
public void onGameModeChange(ChangeGameModeEvent e) {
|
public void onGameModeChange(ChangeGameModeEvent e) {
|
||||||
Humanoid targetEntity = e.getTargetEntity();
|
Humanoid targetEntity = e.getTargetEntity();
|
||||||
if (targetEntity instanceof Subject) {
|
if (this.gamemode && targetEntity instanceof Subject) {
|
||||||
this.plugin.getContextManager().signalContextUpdate((Subject) targetEntity);
|
this.plugin.getContextManager().signalContextUpdate((Subject) targetEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -446,6 +446,12 @@ post-traversal-inheritance-sort = false
|
|||||||
# entries in A are also in B.
|
# entries in A are also in B.
|
||||||
context-satisfy-mode = "at-least-one-value-per-key"
|
context-satisfy-mode = "at-least-one-value-per-key"
|
||||||
|
|
||||||
|
# LuckPerms has a number of built-in contexts. These can be disabled by adding the context key to
|
||||||
|
# the list below.
|
||||||
|
disabled-contexts = [
|
||||||
|
# "world"
|
||||||
|
]
|
||||||
|
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
# | Permission resolution settings | #
|
# | Permission resolution settings | #
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
|
@@ -28,6 +28,7 @@ package me.lucko.luckperms.velocity;
|
|||||||
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
import me.lucko.luckperms.common.api.LuckPermsApiProvider;
|
||||||
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
import me.lucko.luckperms.common.calculator.CalculatorFactory;
|
||||||
import me.lucko.luckperms.common.command.CommandManager;
|
import me.lucko.luckperms.common.command.CommandManager;
|
||||||
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
import me.lucko.luckperms.common.config.generic.adapter.ConfigurationAdapter;
|
||||||
import me.lucko.luckperms.common.dependencies.Dependency;
|
import me.lucko.luckperms.common.dependencies.Dependency;
|
||||||
import me.lucko.luckperms.common.event.AbstractEventBus;
|
import me.lucko.luckperms.common.event.AbstractEventBus;
|
||||||
@@ -49,6 +50,7 @@ import me.lucko.luckperms.velocity.listeners.VelocityConnectionListener;
|
|||||||
import me.lucko.luckperms.velocity.messaging.VelocityMessagingFactory;
|
import me.lucko.luckperms.velocity.messaging.VelocityMessagingFactory;
|
||||||
|
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.context.DefaultContextKeys;
|
||||||
import net.luckperms.api.query.QueryOptions;
|
import net.luckperms.api.query.QueryOptions;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -133,9 +135,12 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin {
|
|||||||
protected void setupContextManager() {
|
protected void setupContextManager() {
|
||||||
this.contextManager = new VelocityContextManager(this);
|
this.contextManager = new VelocityContextManager(this);
|
||||||
|
|
||||||
VelocityPlayerCalculator playerCalculator = new VelocityPlayerCalculator(this);
|
Set<String> disabledContexts = getConfiguration().get(ConfigKeys.DISABLED_CONTEXTS);
|
||||||
this.bootstrap.getProxy().getEventManager().register(this.bootstrap, playerCalculator);
|
if (!disabledContexts.contains(DefaultContextKeys.WORLD_KEY)) {
|
||||||
this.contextManager.registerCalculator(playerCalculator);
|
VelocityPlayerCalculator playerCalculator = new VelocityPlayerCalculator(this);
|
||||||
|
this.bootstrap.getProxy().getEventManager().register(this.bootstrap, playerCalculator);
|
||||||
|
this.contextManager.registerCalculator(playerCalculator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -434,6 +434,11 @@ post-traversal-inheritance-sort: false
|
|||||||
# entries in A are also in B.
|
# entries in A are also in B.
|
||||||
context-satisfy-mode: at-least-one-value-per-key
|
context-satisfy-mode: at-least-one-value-per-key
|
||||||
|
|
||||||
|
# LuckPerms has a number of built-in contexts. These can be disabled by adding the context key to
|
||||||
|
# the list below.
|
||||||
|
disabled-contexts:
|
||||||
|
# - "world"
|
||||||
|
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
# | Permission resolution settings | #
|
# | Permission resolution settings | #
|
||||||
# +----------------------------------------------------------------------------------------------+ #
|
# +----------------------------------------------------------------------------------------------+ #
|
||||||
|
Reference in New Issue
Block a user