Refactor config handling - towards #100
This commit is contained in:
@@ -38,6 +38,7 @@ import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
||||
import me.lucko.luckperms.common.calculators.processors.MapProcessor;
|
||||
import me.lucko.luckperms.common.calculators.processors.RegexProcessor;
|
||||
import me.lucko.luckperms.common.calculators.processors.WildcardProcessor;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -57,10 +58,10 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory {
|
||||
LPPermissible permissible = Injector.getPermissible(uuid);
|
||||
return permissible == null ? null : permissible.getAttachmentPermissions();
|
||||
}));
|
||||
if (plugin.getConfiguration().isApplyingWildcards()) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
processors.add(new WildcardProcessor());
|
||||
}
|
||||
if (plugin.getConfiguration().isApplyingRegex()) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
processors.add(new RegexProcessor());
|
||||
}
|
||||
processors.add(new DefaultsProcessor(contexts.isOp(), plugin.getDefaultsProvider()));
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import me.lucko.luckperms.common.config.AbstractConfiguration;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -34,48 +36,45 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class BukkitConfig extends AbstractConfiguration<LPBukkitPlugin> {
|
||||
@RequiredArgsConstructor
|
||||
public class BukkitConfig extends AbstractConfiguration {
|
||||
private final LPBukkitPlugin plugin;
|
||||
private YamlConfiguration configuration;
|
||||
|
||||
BukkitConfig(LPBukkitPlugin plugin) {
|
||||
super(plugin, "global", true, "sqlite");
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
@Override
|
||||
protected void init() {
|
||||
File configFile = new File(getPlugin().getDataFolder(), "config.yml");
|
||||
public void init() {
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
|
||||
if (!configFile.exists()) {
|
||||
configFile.getParentFile().mkdirs();
|
||||
getPlugin().saveResource("config.yml", false);
|
||||
plugin.saveResource("config.yml", false);
|
||||
}
|
||||
|
||||
configuration = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getString(String path, String def) {
|
||||
public String getString(String path, String def) {
|
||||
return configuration.getString(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInt(String path, int def) {
|
||||
public int getInt(String path, int def) {
|
||||
return configuration.getInt(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getBoolean(String path, boolean def) {
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return configuration.getBoolean(path, def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getList(String path, List<String> def) {
|
||||
public List<String> getList(String path, List<String> def) {
|
||||
return Optional.ofNullable(configuration.getStringList(path)).orElse(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjectList(String path, List<String> def) {
|
||||
public List<String> getObjectList(String path, List<String> def) {
|
||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
||||
if (section == null) {
|
||||
return def;
|
||||
@@ -84,9 +83,8 @@ class BukkitConfig extends AbstractConfiguration<LPBukkitPlugin> {
|
||||
return Optional.ofNullable(section.getKeys(false).stream().collect(Collectors.toList())).orElse(def);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
ConfigurationSection section = configuration.getConfigurationSection(path);
|
||||
if (section == null) {
|
||||
|
||||
@@ -24,6 +24,7 @@ package me.lucko.luckperms.bukkit;
|
||||
|
||||
import me.lucko.luckperms.bukkit.inject.Injector;
|
||||
import me.lucko.luckperms.bukkit.model.LPPermissible;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.constants.Message;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.utils.AbstractListener;
|
||||
@@ -149,7 +150,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
||||
Injector.unInject(player, true, true);
|
||||
|
||||
// Handle auto op
|
||||
if (plugin.getConfiguration().isAutoOp()) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
@@ -159,7 +160,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
|
||||
if (plugin.getConfiguration().isOpsEnabled()) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import me.lucko.luckperms.common.api.ApiProvider;
|
||||
import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
|
||||
import me.lucko.luckperms.common.calculators.CalculatorFactory;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LPConfiguration;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
@@ -153,6 +154,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new BukkitConfig(this);
|
||||
configuration.init();
|
||||
configuration.loadAll();
|
||||
|
||||
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
|
||||
DependencyManager.loadDependencies(this, storageTypes);
|
||||
@@ -195,11 +198,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
storage = StorageFactory.getInstance(this, StorageType.H2);
|
||||
|
||||
// initialise redis
|
||||
if (getConfiguration().isRedisEnabled()) {
|
||||
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
getLog().info("Loading redis...");
|
||||
redisMessaging = new RedisMessaging(this);
|
||||
try {
|
||||
redisMessaging.init(getConfiguration().getRedisAddress(), getConfiguration().getRedisPassword());
|
||||
redisMessaging.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
|
||||
getLog().info("Loaded redis successfully...");
|
||||
} catch (Exception e) {
|
||||
getLog().info("Couldn't load redis...");
|
||||
@@ -238,7 +241,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
// load internal managers
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(getConfiguration().isOnlineMode());
|
||||
uuidCache = new UuidCache(this);
|
||||
userManager = new GenericUserManager(this);
|
||||
groupManager = new GenericGroupManager(this);
|
||||
trackManager = new GenericTrackManager();
|
||||
@@ -250,7 +253,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
worldCalculator = new WorldCalculator(this);
|
||||
pm.registerEvents(worldCalculator, this);
|
||||
contextManager.registerCalculator(worldCalculator);
|
||||
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
||||
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration()));
|
||||
|
||||
// Provide vault support
|
||||
tryVaultHook(false);
|
||||
@@ -263,7 +266,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
|
||||
// schedule update tasks
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (mins > 0) {
|
||||
long ticks = mins * 60 * 20;
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> updateTaskBuffer.request(), 40L, ticks);
|
||||
@@ -277,8 +280,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new CacheHousekeepingTask(this), 2400L, 2400L);
|
||||
|
||||
// register permissions
|
||||
registerPermissions(getConfiguration().isCommandsAllowOp() ? PermissionDefault.OP : PermissionDefault.FALSE);
|
||||
if (!getConfiguration().isOpsEnabled()) {
|
||||
registerPermissions(getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE);
|
||||
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
|
||||
getServer().getScheduler().runTask(this, () -> getServer().getOperators().forEach(o -> o.setOp(false)));
|
||||
}
|
||||
|
||||
@@ -324,7 +327,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
|
||||
for (Player player : getServer().getOnlinePlayers()) {
|
||||
Injector.unInject(player, false, false);
|
||||
if (getConfiguration().isAutoOp()) {
|
||||
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
player.setOp(false);
|
||||
}
|
||||
|
||||
@@ -420,7 +423,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
|
||||
public void refreshAutoOp(Player player) {
|
||||
if (getConfiguration().isAutoOp()) {
|
||||
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
|
||||
try {
|
||||
LPPermissible permissible = Injector.getPermissible(player.getUniqueId());
|
||||
if (permissible == null) {
|
||||
@@ -492,11 +495,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
}
|
||||
return new Contexts(
|
||||
getContextManager().getApplicableContext(player),
|
||||
getConfiguration().isIncludingGlobalPerms(),
|
||||
getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
getConfiguration().isApplyingGlobalGroups(),
|
||||
getConfiguration().isApplyingGlobalWorldGroups(),
|
||||
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
player.isOp()
|
||||
);
|
||||
}
|
||||
@@ -537,14 +540,14 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
public Set<Contexts> getPreProcessContexts(boolean op) {
|
||||
Set<ContextSet> c = new HashSet<>();
|
||||
c.add(ContextSet.empty());
|
||||
c.add(ContextSet.singleton("server", getConfiguration().getServer()));
|
||||
c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.SERVER)));
|
||||
|
||||
// Pre process all worlds
|
||||
c.addAll(getServer().getWorlds().stream()
|
||||
.map(World::getName)
|
||||
.map(s -> {
|
||||
MutableContextSet set = MutableContextSet.create();
|
||||
set.add("server", getConfiguration().getServer());
|
||||
set.add("server", getConfiguration().get(ConfigKeys.SERVER));
|
||||
set.add("world", s);
|
||||
return set.makeImmutable();
|
||||
})
|
||||
@@ -552,13 +555,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
);
|
||||
|
||||
// Pre process the separate Vault server, if any
|
||||
if (!getConfiguration().getServer().equals(getConfiguration().getVaultServer())) {
|
||||
c.add(ContextSet.singleton("server", getConfiguration().getVaultServer()));
|
||||
if (!getConfiguration().get(ConfigKeys.SERVER).equals(getConfiguration().get(ConfigKeys.VAULT_SERVER))) {
|
||||
c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.VAULT_SERVER)));
|
||||
c.addAll(getServer().getWorlds().stream()
|
||||
.map(World::getName)
|
||||
.map(s -> {
|
||||
MutableContextSet set = MutableContextSet.create();
|
||||
set.add("server", getConfiguration().getVaultServer());
|
||||
set.add("server", getConfiguration().get(ConfigKeys.VAULT_SERVER));
|
||||
set.add("world", s);
|
||||
return set.makeImmutable();
|
||||
})
|
||||
@@ -572,25 +575,25 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
contexts.addAll(c.stream()
|
||||
.map(set -> new Contexts(
|
||||
set,
|
||||
getConfiguration().isIncludingGlobalPerms(),
|
||||
getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
getConfiguration().isApplyingGlobalGroups(),
|
||||
getConfiguration().isApplyingGlobalWorldGroups(),
|
||||
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
op
|
||||
))
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
|
||||
// Check for and include varying Vault config options
|
||||
boolean vaultDiff = getConfiguration().isVaultIncludingGlobal() != getConfiguration().isIncludingGlobalPerms() ||
|
||||
!getConfiguration().isIncludingGlobalWorldPerms() ||
|
||||
!getConfiguration().isApplyingGlobalGroups() ||
|
||||
!getConfiguration().isApplyingGlobalWorldGroups();
|
||||
boolean vaultDiff = getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL) != getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS) ||
|
||||
!getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS) ||
|
||||
!getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS) ||
|
||||
!getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
|
||||
|
||||
if (vaultDiff) {
|
||||
contexts.addAll(c.stream()
|
||||
.map(map -> new Contexts(map, getConfiguration().isVaultIncludingGlobal(), true, true, true, true, op))
|
||||
.map(map -> new Contexts(map, getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL), true, true, true, true, op))
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
}
|
||||
@@ -602,16 +605,16 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
||||
public LinkedHashMap<String, Object> getExtraInfo() {
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("Vault Enabled", vaultHook != null);
|
||||
map.put("Vault Server", configuration.getVaultServer());
|
||||
map.put("Vault Server", configuration.get(ConfigKeys.VAULT_SERVER));
|
||||
map.put("Bukkit Defaults count", defaultsProvider.size());
|
||||
map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size());
|
||||
map.put("Vault Including Global", configuration.isVaultIncludingGlobal());
|
||||
map.put("Vault Ignoring World", configuration.isVaultIgnoreWorld());
|
||||
map.put("Vault Primary Group Overrides", configuration.isVaultPrimaryGroupOverrides());
|
||||
map.put("Vault Debug", configuration.isVaultDebug());
|
||||
map.put("OPs Enabled", configuration.isOpsEnabled());
|
||||
map.put("Auto OP", configuration.isAutoOp());
|
||||
map.put("Commands Allow OPs", configuration.isCommandsAllowOp());
|
||||
map.put("Vault Including Global", configuration.get(ConfigKeys.VAULT_INCLUDING_GLOBAL));
|
||||
map.put("Vault Ignoring World", configuration.get(ConfigKeys.VAULT_IGNORE_WORLD));
|
||||
map.put("Vault Primary Group Overrides", configuration.get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES));
|
||||
map.put("Vault Debug", configuration.get(ConfigKeys.VAULT_DEBUG));
|
||||
map.put("OPs Enabled", configuration.get(ConfigKeys.OPS_ENABLED));
|
||||
map.put("Auto OP", configuration.get(ConfigKeys.AUTO_OP));
|
||||
map.put("Commands Allow OPs", configuration.get(ConfigKeys.COMMANDS_ALLOW_OP));
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ 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.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -64,6 +65,6 @@ public class WorldCalculator extends ContextCalculator<Player> implements Listen
|
||||
|
||||
private String getWorld(Player player) {
|
||||
String world = player.getWorld().getName();
|
||||
return plugin.getConfiguration().getWorldRewrites().getOrDefault(world, world);
|
||||
return plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import lombok.Setter;
|
||||
import me.lucko.luckperms.api.Contexts;
|
||||
import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -120,11 +121,11 @@ public class LPPermissible extends PermissibleBase {
|
||||
public Contexts calculateContexts() {
|
||||
return new Contexts(
|
||||
plugin.getContextManager().getApplicableContext(parent),
|
||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
plugin.getConfiguration().isApplyingGlobalGroups(),
|
||||
plugin.getConfiguration().isApplyingGlobalWorldGroups(),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
parent.isOp()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.caching.PermissionData;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
@@ -56,34 +57,17 @@ public class VaultPermissionHook extends Permission {
|
||||
|
||||
private final String name = "LuckPerms";
|
||||
|
||||
private String server = "global";
|
||||
private boolean includeGlobal = true;
|
||||
private boolean ignoreWorld = false;
|
||||
private boolean pgo = false;
|
||||
private boolean pgoCheckInherited = false;
|
||||
private boolean pgoCheckExists = true;
|
||||
private boolean pgoCheckMemberOf = true;
|
||||
|
||||
private Function<String, String> WORLD_CORRECTION_FUNCTION = s -> ignoreWorld ? null : s;
|
||||
private Function<String, String> WORLD_CORRECTION_FUNCTION = s -> isIgnoreWorld() ? null : s;
|
||||
|
||||
public VaultPermissionHook(LPBukkitPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.scheduler = new VaultScheduler(plugin);
|
||||
|
||||
super.plugin = plugin;
|
||||
|
||||
// Config options
|
||||
this.server = plugin.getConfiguration().getVaultServer();
|
||||
this.includeGlobal = plugin.getConfiguration().isVaultIncludingGlobal();
|
||||
this.ignoreWorld = plugin.getConfiguration().isVaultIgnoreWorld();
|
||||
this.pgo = plugin.getConfiguration().isVaultPrimaryGroupOverrides();
|
||||
this.pgoCheckInherited = plugin.getConfiguration().isVaultPrimaryGroupOverridesCheckInherited();
|
||||
this.pgoCheckExists = plugin.getConfiguration().isVaultPrimaryGroupOverridesCheckExists();
|
||||
this.pgoCheckMemberOf = plugin.getConfiguration().isVaultPrimaryGroupOverridesCheckMemberOf();
|
||||
}
|
||||
|
||||
public void log(String s) {
|
||||
if (plugin.getConfiguration().isVaultDebug()) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG)) {
|
||||
plugin.getLog().info("[VAULT] " + s);
|
||||
}
|
||||
}
|
||||
@@ -109,9 +93,9 @@ public class VaultPermissionHook extends Permission {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
|
||||
holder.setPermission(permission, true, server, world);
|
||||
holder.setPermission(permission, true, getServer(), world);
|
||||
} else {
|
||||
holder.setPermission(permission, true, server);
|
||||
holder.setPermission(permission, true, getServer());
|
||||
}
|
||||
|
||||
save(holder);
|
||||
@@ -130,9 +114,9 @@ public class VaultPermissionHook extends Permission {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) {
|
||||
holder.unsetPermission(permission, server, world);
|
||||
holder.unsetPermission(permission, getServer(), world);
|
||||
} else {
|
||||
holder.unsetPermission(permission, server);
|
||||
holder.unsetPermission(permission, getServer());
|
||||
}
|
||||
|
||||
save(holder);
|
||||
@@ -161,14 +145,14 @@ public class VaultPermissionHook extends Permission {
|
||||
if (world != null && !world.equals("")) {
|
||||
context.put("world", world);
|
||||
}
|
||||
context.put("server", server);
|
||||
context.put("server", getServer());
|
||||
return new Contexts(ContextSet.fromMap(context), isIncludeGlobal(), true, true, true, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerHas(String world, @NonNull String player, @NonNull String permission) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Checking if player " + player + " has permission: " + permission + " on world " + world + ", server " + server);
|
||||
log("Checking if player " + player + " has permission: " + permission + " on world " + world + ", server " + getServer());
|
||||
|
||||
User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return false;
|
||||
@@ -184,7 +168,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean playerAdd(String world, @NonNull String player, @NonNull String permission) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Adding permission to player " + player + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
log("Adding permission to player " + player + ": '" + permission + "' on world " + world + ", server " + getServer());
|
||||
|
||||
final User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return false;
|
||||
@@ -196,7 +180,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean playerRemove(String world, @NonNull String player, @NonNull String permission) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Removing permission from player " + player + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
log("Removing permission from player " + player + ": '" + permission + "' on world " + world + ", server " + getServer());
|
||||
|
||||
final User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return false;
|
||||
@@ -208,7 +192,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean groupHas(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Checking if group " + groupName + " has permission: " + permission + " on world " + world + ", server " + server);
|
||||
log("Checking if group " + groupName + " has permission: " + permission + " on world " + world + ", server " + getServer());
|
||||
|
||||
final Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
if (group == null) return false;
|
||||
@@ -221,7 +205,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean groupAdd(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Adding permission to group " + groupName + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
log("Adding permission to group " + groupName + ": '" + permission + "' on world " + world + ", server " + getServer());
|
||||
|
||||
final Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
if (group == null) return false;
|
||||
@@ -233,7 +217,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean groupRemove(String world, @NonNull String groupName, @NonNull String permission) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Removing permission from group " + groupName + ": '" + permission + "' on world " + world + ", server " + server);
|
||||
log("Removing permission from group " + groupName + ": '" + permission + "' on world " + world + ", server " + getServer());
|
||||
|
||||
final Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
if (group == null) return false;
|
||||
@@ -245,7 +229,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Checking if player " + player + " is in group: " + group + " on world " + world + ", server " + server);
|
||||
log("Checking if player " + player + " is in group: " + group + " on world " + world + ", server " + getServer());
|
||||
|
||||
final User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return false;
|
||||
@@ -253,7 +237,7 @@ public class VaultPermissionHook extends Permission {
|
||||
String w = world; // screw effectively final
|
||||
return user.getNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false))
|
||||
.filter(n -> n.shouldApplyOnServer(getServer(), isIncludeGlobal(), false))
|
||||
.filter(n -> n.shouldApplyOnWorld(w, true, false))
|
||||
.map(Node::getGroupName)
|
||||
.anyMatch(s -> s.equalsIgnoreCase(group));
|
||||
@@ -262,7 +246,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Adding player " + player + " to group: '" + groupName + "' on world " + world + ", server " + server);
|
||||
log("Adding player " + player + " to group: '" + groupName + "' on world " + world + ", server " + getServer());
|
||||
|
||||
final User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return false;
|
||||
@@ -274,9 +258,9 @@ public class VaultPermissionHook extends Permission {
|
||||
scheduler.execute(() -> {
|
||||
try {
|
||||
if (w != null && !w.equals("") && !w.equalsIgnoreCase("global")) {
|
||||
user.setInheritGroup(group, server, w);
|
||||
user.setInheritGroup(group, getServer(), w);
|
||||
} else {
|
||||
user.setInheritGroup(group, server);
|
||||
user.setInheritGroup(group, getServer());
|
||||
}
|
||||
|
||||
save(user);
|
||||
@@ -288,7 +272,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, @NonNull String player, @NonNull String groupName) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Removing player " + player + " from group: '" + groupName + "' on world " + world + ", server " + server);
|
||||
log("Removing player " + player + " from group: '" + groupName + "' on world " + world + ", server " + getServer());
|
||||
|
||||
final User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return false;
|
||||
@@ -300,9 +284,9 @@ public class VaultPermissionHook extends Permission {
|
||||
scheduler.execute(() -> {
|
||||
try {
|
||||
if (w != null && !w.equals("") && !w.equalsIgnoreCase("global")) {
|
||||
user.unsetInheritGroup(group, server, w);
|
||||
user.unsetInheritGroup(group, getServer(), w);
|
||||
} else {
|
||||
user.unsetInheritGroup(group, server);
|
||||
user.unsetInheritGroup(group, getServer());
|
||||
}
|
||||
|
||||
save(user);
|
||||
@@ -314,7 +298,7 @@ public class VaultPermissionHook extends Permission {
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, @NonNull String player) {
|
||||
world = WORLD_CORRECTION_FUNCTION.apply(world);
|
||||
log("Getting groups of player: " + player + ", on world " + world + ", server " + server);
|
||||
log("Getting groups of player: " + player + ", on world " + world + ", server " + getServer());
|
||||
|
||||
User user = plugin.getUserManager().getByUsername(player);
|
||||
if (user == null) return new String[0];
|
||||
@@ -322,7 +306,7 @@ public class VaultPermissionHook extends Permission {
|
||||
String w = world; // screw effectively final
|
||||
return user.getNodes().stream()
|
||||
.filter(Node::isGroupNode)
|
||||
.filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false))
|
||||
.filter(n -> n.shouldApplyOnServer(getServer(), isIncludeGlobal(), false))
|
||||
.filter(n -> n.shouldApplyOnWorld(w, true, false))
|
||||
.map(Node::getGroupName)
|
||||
.toArray(String[]::new);
|
||||
@@ -338,12 +322,12 @@ public class VaultPermissionHook extends Permission {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!pgo) {
|
||||
if (!isPgo()) {
|
||||
String g = user.getPrimaryGroup();
|
||||
return plugin.getConfiguration().getGroupNameRewrites().getOrDefault(g, g);
|
||||
return plugin.getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(g, g);
|
||||
}
|
||||
|
||||
if (pgoCheckInherited) {
|
||||
if (isPgoCheckInherited()) {
|
||||
PermissionData data = user.getUserData().getPermissionData(createContextForWorld(world));
|
||||
for (Map.Entry<String, Boolean> e : data.getImmutableBacking().entrySet()) {
|
||||
if (!e.getValue()) {
|
||||
@@ -355,13 +339,13 @@ public class VaultPermissionHook extends Permission {
|
||||
}
|
||||
|
||||
String group = e.getKey().substring("vault.primarygroup.".length());
|
||||
if (pgoCheckExists) {
|
||||
if (isPgoCheckExists()) {
|
||||
if (!plugin.getGroupManager().isLoaded(group)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (pgoCheckMemberOf) {
|
||||
if (isPgoCheckMemberOf()) {
|
||||
if (data.getPermissionValue("group." + group) != Tristate.TRUE) {
|
||||
continue;
|
||||
}
|
||||
@@ -379,7 +363,7 @@ public class VaultPermissionHook extends Permission {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!node.shouldApplyOnServer(server, isIncludeGlobal(), false)) {
|
||||
if (!node.shouldApplyOnServer(getServer(), isIncludeGlobal(), false)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -388,14 +372,14 @@ public class VaultPermissionHook extends Permission {
|
||||
}
|
||||
|
||||
String group = node.getPermission().substring("vault.primarygroup.".length());
|
||||
if (pgoCheckExists) {
|
||||
if (isPgoCheckExists()) {
|
||||
if (!plugin.getGroupManager().isLoaded(group)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (pgoCheckMemberOf) {
|
||||
if (!user.getLocalGroups(server, world, isIncludeGlobal()).contains(group.toLowerCase())) {
|
||||
if (isPgoCheckMemberOf()) {
|
||||
if (!user.getLocalGroups(getServer(), world, isIncludeGlobal()).contains(group.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -406,7 +390,7 @@ public class VaultPermissionHook extends Permission {
|
||||
|
||||
// Fallback
|
||||
String g = user.getPrimaryGroup();
|
||||
return plugin.getConfiguration().getGroupNameRewrites().getOrDefault(g, g);
|
||||
return plugin.getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(g, g);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -418,4 +402,32 @@ public class VaultPermissionHook extends Permission {
|
||||
public boolean hasGroupSupport() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER);
|
||||
}
|
||||
|
||||
public boolean isIncludeGlobal() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
|
||||
}
|
||||
|
||||
public boolean isIgnoreWorld() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD);
|
||||
}
|
||||
|
||||
public boolean isPgo() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES);
|
||||
}
|
||||
|
||||
public boolean isPgoCheckInherited() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_INHERITED);
|
||||
}
|
||||
|
||||
public boolean isPgoCheckExists() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_EXISTS);
|
||||
}
|
||||
|
||||
public boolean isPgoCheckMemberOf() {
|
||||
return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user