mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Refactor some Sponge service details
This commit is contained in:
parent
39daed23c4
commit
9ceacdb739
@ -37,8 +37,9 @@ import me.lucko.luckperms.common.utils.TextUtils;
|
|||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import net.kyori.text.serializer.ComponentSerializers;
|
import net.kyori.text.serializer.ComponentSerializers;
|
||||||
|
|
||||||
import org.bukkit.command.BlockCommandSender;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.command.RemoteConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -71,13 +72,14 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void sendMessage(CommandSender sender, String s) {
|
protected void sendMessage(CommandSender sender, String s) {
|
||||||
// send sync if command block
|
// we can safely send async for players and the console
|
||||||
if (sender instanceof BlockCommandSender) {
|
if (sender instanceof Player || sender instanceof ConsoleCommandSender || sender instanceof RemoteConsoleCommandSender) {
|
||||||
getPlugin().getScheduler().doSync(new BlockMessengerAgent(((BlockCommandSender) sender), s));
|
sender.sendMessage(s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(s);
|
// otherwise, send the message sync
|
||||||
|
getPlugin().getScheduler().doSync(new SyncMessengerAgent(sender, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,18 +125,18 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class BlockMessengerAgent implements Runnable {
|
private static final class SyncMessengerAgent implements Runnable {
|
||||||
private final BlockCommandSender block;
|
private final CommandSender sender;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
private BlockMessengerAgent(BlockCommandSender block, String message) {
|
private SyncMessengerAgent(CommandSender sender, String message) {
|
||||||
this.block = block;
|
this.sender = sender;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
this.block.sendMessage(this.message);
|
this.sender.sendMessage(this.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.bukkit.migration;
|
package me.lucko.luckperms.bukkit.migration;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public final class BukkitMigrationUtils {
|
|||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static UUID lookupUuid(ProgressLogger log, String s) {
|
public static UUID lookupUuid(ProgressLogger log, String s) {
|
||||||
UUID uuid = CommandUtils.parseUuid(s);
|
UUID uuid = Uuids.parseNullable(s);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
try {
|
try {
|
||||||
uuid = Bukkit.getOfflinePlayer(s).getUniqueId();
|
uuid = Bukkit.getOfflinePlayer(s).getUniqueId();
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.commands.CommandPermission;
|
|||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
@ -40,6 +39,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||||
import me.lucko.luckperms.common.utils.DateUtil;
|
import me.lucko.luckperms.common.utils.DateUtil;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -72,7 +72,7 @@ public class LogRecent extends SubCommand<Log> {
|
|||||||
|
|
||||||
// User and possibly page
|
// User and possibly page
|
||||||
final String target = args.get(0);
|
final String target = args.get(0);
|
||||||
UUID uuid = CommandUtils.parseUuid(target.toLowerCase());
|
UUID uuid = Uuids.parseNullable(target);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
||||||
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.commands.CommandPermission;
|
|||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
@ -40,6 +39,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||||
import me.lucko.luckperms.common.utils.DateUtil;
|
import me.lucko.luckperms.common.utils.DateUtil;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -67,7 +67,7 @@ public class LogUserHistory extends SubCommand<Log> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID uuid = CommandUtils.parseUuid(target.toLowerCase());
|
UUID uuid = Uuids.parseNullable(target);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
||||||
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
||||||
|
@ -38,6 +38,7 @@ import me.lucko.luckperms.common.locale.Message;
|
|||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
import me.lucko.luckperms.common.verbose.CheckOrigin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -55,7 +56,7 @@ public class CheckCommand extends SingleCommand {
|
|||||||
String permission = args.get(1);
|
String permission = args.get(1);
|
||||||
|
|
||||||
User user;
|
User user;
|
||||||
UUID u = CommandUtils.parseUuid(target);
|
UUID u = Uuids.parseNullable(target);
|
||||||
if (u != null) {
|
if (u != null) {
|
||||||
user = plugin.getUserManager().getIfLoaded(u);
|
user = plugin.getUserManager().getIfLoaded(u);
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SingleCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
@ -40,6 +39,7 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|||||||
import me.lucko.luckperms.common.treeview.TreeView;
|
import me.lucko.luckperms.common.treeview.TreeView;
|
||||||
import me.lucko.luckperms.common.treeview.TreeViewBuilder;
|
import me.lucko.luckperms.common.treeview.TreeViewBuilder;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
@ -73,7 +73,7 @@ public class TreeCommand extends SingleCommand {
|
|||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
User user;
|
User user;
|
||||||
UUID u = CommandUtils.parseUuid(player);
|
UUID u = Uuids.parseNullable(player);
|
||||||
if (u != null) {
|
if (u != null) {
|
||||||
user = plugin.getUserManager().getIfLoaded(u);
|
user = plugin.getUserManager().getIfLoaded(u);
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.commands.CommandPermission;
|
|||||||
import me.lucko.luckperms.common.commands.CommandResult;
|
import me.lucko.luckperms.common.commands.CommandResult;
|
||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
@ -40,6 +39,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -58,7 +58,7 @@ public class UserClone extends SubCommand<User> {
|
|||||||
|
|
||||||
String target = args.get(0);
|
String target = args.get(0);
|
||||||
|
|
||||||
UUID uuid = CommandUtils.parseUuid(target.toLowerCase());
|
UUID uuid = Uuids.parseNullable(target);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
||||||
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
||||||
|
@ -38,7 +38,6 @@ import me.lucko.luckperms.common.commands.impl.generic.other.HolderShowTracks;
|
|||||||
import me.lucko.luckperms.common.commands.impl.generic.parent.CommandParent;
|
import me.lucko.luckperms.common.commands.impl.generic.parent.CommandParent;
|
||||||
import me.lucko.luckperms.common.commands.impl.generic.permission.CommandPermission;
|
import me.lucko.luckperms.common.commands.impl.generic.permission.CommandPermission;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
@ -47,6 +46,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||||
import me.lucko.luckperms.common.storage.DataConstraints;
|
import me.lucko.luckperms.common.storage.DataConstraints;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -83,7 +83,7 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected UserIdentifier parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
protected UserIdentifier parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
|
||||||
UUID uuid = CommandUtils.parseUuid(target.toLowerCase());
|
UUID uuid = Uuids.parseNullable(target);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
|
||||||
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
|
||||||
|
@ -37,7 +37,6 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -108,18 +107,6 @@ public final class CommandUtils {
|
|||||||
return lists;
|
return lists;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID parseUuid(String s) {
|
|
||||||
try {
|
|
||||||
return UUID.fromString(s);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
try {
|
|
||||||
return UUID.fromString(s.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
|
|
||||||
} catch (IllegalArgumentException e1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toCommaSep(Collection<String> strings) {
|
public static String toCommaSep(Collection<String> strings) {
|
||||||
if (strings.isEmpty()) {
|
if (strings.isEmpty()) {
|
||||||
return "&bNone";
|
return "&bNone";
|
||||||
|
@ -35,7 +35,6 @@ import me.lucko.luckperms.api.context.ImmutableContextSet;
|
|||||||
import me.lucko.luckperms.common.actionlog.Log;
|
import me.lucko.luckperms.common.actionlog.Log;
|
||||||
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
|
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
|
||||||
import me.lucko.luckperms.common.commands.CommandManager;
|
import me.lucko.luckperms.common.commands.CommandManager;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.contexts.ContextSetConfigurateSerializer;
|
import me.lucko.luckperms.common.contexts.ContextSetConfigurateSerializer;
|
||||||
import me.lucko.luckperms.common.managers.group.GroupManager;
|
import me.lucko.luckperms.common.managers.group.GroupManager;
|
||||||
import me.lucko.luckperms.common.managers.track.TrackManager;
|
import me.lucko.luckperms.common.managers.track.TrackManager;
|
||||||
@ -51,6 +50,7 @@ import me.lucko.luckperms.common.storage.dao.AbstractDao;
|
|||||||
import me.lucko.luckperms.common.storage.dao.legacy.LegacyJsonMigration;
|
import me.lucko.luckperms.common.storage.dao.legacy.LegacyJsonMigration;
|
||||||
import me.lucko.luckperms.common.storage.dao.legacy.LegacyYamlMigration;
|
import me.lucko.luckperms.common.storage.dao.legacy.LegacyYamlMigration;
|
||||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.SimpleConfigurationNode;
|
import ninja.leaping.configurate.SimpleConfigurationNode;
|
||||||
@ -266,7 +266,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String user = s.substring(0, s.length() - this.fileExtension.length());
|
String user = s.substring(0, s.length() - this.fileExtension.length());
|
||||||
UUID uuid = CommandUtils.parseUuid(user);
|
UUID uuid = Uuids.parseNullable(user);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.utils;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for working with {@link UUID}s.
|
||||||
|
*/
|
||||||
|
public final class Uuids {
|
||||||
|
private static final Pattern UUID_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");
|
||||||
|
|
||||||
|
public static final Predicate<String> PREDICATE = s -> parseNullable(s) != null;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static UUID fromString(String s) {
|
||||||
|
try {
|
||||||
|
return UUID.fromString(s);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static UUID parseNullable(String s) {
|
||||||
|
UUID uuid = fromString(s);
|
||||||
|
if (uuid == null) {
|
||||||
|
uuid = fromString(UUID_PATTERN.matcher(s).replaceAll("$1-$2-$3-$4-$5"));
|
||||||
|
}
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Optional<UUID> parse(String s) {
|
||||||
|
return Optional.ofNullable(parseNullable(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Uuids() {}
|
||||||
|
|
||||||
|
}
|
@ -33,7 +33,6 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.contexts.ContextSetJsonSerializer;
|
import me.lucko.luckperms.common.contexts.ContextSetJsonSerializer;
|
||||||
import me.lucko.luckperms.common.locale.Message;
|
import me.lucko.luckperms.common.locale.Message;
|
||||||
import me.lucko.luckperms.common.model.Group;
|
import me.lucko.luckperms.common.model.Group;
|
||||||
@ -41,6 +40,7 @@ import me.lucko.luckperms.common.model.PermissionHolder;
|
|||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.node.NodeModel;
|
import me.lucko.luckperms.common.node.NodeModel;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -86,7 +86,7 @@ public final class WebEditorUtils {
|
|||||||
return holder;
|
return holder;
|
||||||
} else if (who.startsWith(USER_ID_PATTERN)) {
|
} else if (who.startsWith(USER_ID_PATTERN)) {
|
||||||
String user = who.substring(USER_ID_PATTERN.length());
|
String user = who.substring(USER_ID_PATTERN.length());
|
||||||
UUID uuid = CommandUtils.parseUuid(user);
|
UUID uuid = Uuids.parseNullable(user);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
Message.APPLY_EDITS_TARGET_USER_NOT_UUID.send(sender, user);
|
Message.APPLY_EDITS_TARGET_USER_NOT_UUID.send(sender, user);
|
||||||
return null;
|
return null;
|
||||||
|
@ -42,15 +42,16 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class SimpleDescriptionBuilder implements PermissionDescription.Builder {
|
public final class LPDescriptionBuilder implements PermissionDescription.Builder {
|
||||||
@Nonnull private final LPPermissionService service;
|
@Nonnull private final LPPermissionService service;
|
||||||
@Nonnull private final PluginContainer container;
|
@Nonnull private final PluginContainer container;
|
||||||
@Nonnull private final Map<String, Tristate> roles = new HashMap<>();
|
@Nonnull private final Map<String, Tristate> roles = new HashMap<>();
|
||||||
private String id = null;
|
@Nullable private String id = null;
|
||||||
private Text description = null;
|
@Nullable private Text description = null;
|
||||||
|
|
||||||
public SimpleDescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
|
public LPDescriptionBuilder(@Nonnull LPPermissionService service, @Nonnull PluginContainer container) {
|
||||||
this.service = Objects.requireNonNull(service, "service");
|
this.service = Objects.requireNonNull(service, "service");
|
||||||
this.container = Objects.requireNonNull(container, "container");
|
this.container = Objects.requireNonNull(container, "container");
|
||||||
}
|
}
|
||||||
@ -84,7 +85,7 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
|||||||
throw new IllegalStateException("id cannot be null");
|
throw new IllegalStateException("id cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LPPermissionDescription d = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
||||||
|
|
||||||
// Set role-templates
|
// Set role-templates
|
||||||
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
||||||
@ -100,14 +101,14 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
|||||||
this.id = null;
|
this.id = null;
|
||||||
this.description = null;
|
this.description = null;
|
||||||
|
|
||||||
return d.sponge();
|
return description.sponge();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof SimpleDescriptionBuilder)) return false;
|
if (!(o instanceof LPDescriptionBuilder)) return false;
|
||||||
final SimpleDescriptionBuilder other = (SimpleDescriptionBuilder) o;
|
final LPDescriptionBuilder other = (LPDescriptionBuilder) o;
|
||||||
|
|
||||||
return this.container.equals(other.container) &&
|
return this.container.equals(other.container) &&
|
||||||
this.roles.equals(other.roles) &&
|
this.roles.equals(other.roles) &&
|
@ -91,7 +91,7 @@ public final class PermissionServiceProxy implements PermissionService {
|
|||||||
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(new SimpleDescriptionBuilder(this.handle, container.get()));
|
return Optional.of(new LPDescriptionBuilder(this.handle, container.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -30,7 +30,7 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
@ -30,8 +30,8 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
@ -48,17 +48,19 @@ import javax.annotation.Nonnull;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final class SubjectDataProxy implements SubjectData {
|
public final class SubjectDataProxy implements SubjectData {
|
||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final SubjectReference ref;
|
private final LPSubjectReference ref;
|
||||||
private final boolean enduring;
|
private final boolean enduring;
|
||||||
|
|
||||||
public SubjectDataProxy(LPPermissionService service, SubjectReference ref, boolean enduring) {
|
public SubjectDataProxy(LPPermissionService service, LPSubjectReference ref, boolean enduring) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
this.enduring = enduring;
|
this.enduring = enduring;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<LPSubjectData> handle() {
|
private CompletableFuture<LPSubjectData> handle() {
|
||||||
return this.enduring ? this.ref.resolveLp().thenApply(LPSubject::getSubjectData) : this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
return this.enduring ?
|
||||||
|
this.ref.resolveLp().thenApply(LPSubject::getSubjectData) :
|
||||||
|
this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -31,8 +31,8 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
@ -51,9 +51,9 @@ import javax.annotation.Nonnull;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final SubjectReference ref;
|
private final LPSubjectReference ref;
|
||||||
|
|
||||||
public SubjectProxy(LPPermissionService service, SubjectReference ref) {
|
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
}
|
}
|
||||||
@ -62,8 +62,9 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
return this.ref.resolveLp();
|
return this.ref.resolveLp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SubjectReference getReference() {
|
public LPSubjectReference asSubjectReference() {
|
||||||
return this.ref;
|
return this.ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +158,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Context> getActiveContexts() {
|
public Set<Context> getActiveContexts() {
|
||||||
return handle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
return CompatibilityUtil.convertContexts(this.service.getPlugin().getContextManager().getApplicableContext(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,15 +42,16 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class SimpleDescriptionBuilder implements PermissionDescription.Builder {
|
public final class LPDescriptionBuilder implements PermissionDescription.Builder {
|
||||||
@Nonnull private final LPPermissionService service;
|
@Nonnull private final LPPermissionService service;
|
||||||
@Nonnull private final PluginContainer container;
|
@Nonnull private final PluginContainer container;
|
||||||
@Nonnull private final Map<String, Tristate> roles = new HashMap<>();
|
@Nonnull private final Map<String, Tristate> roles = new HashMap<>();
|
||||||
private String id = null;
|
@Nullable private String id = null;
|
||||||
private Text description = null;
|
@Nullable private Text description = null;
|
||||||
|
|
||||||
public SimpleDescriptionBuilder(LPPermissionService service, PluginContainer container) {
|
public LPDescriptionBuilder(LPPermissionService service, PluginContainer container) {
|
||||||
this.service = Objects.requireNonNull(service, "service");
|
this.service = Objects.requireNonNull(service, "service");
|
||||||
this.container = Objects.requireNonNull(container, "container");
|
this.container = Objects.requireNonNull(container, "container");
|
||||||
}
|
}
|
||||||
@ -64,8 +65,8 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public PermissionDescription.Builder description(Text description) {
|
public PermissionDescription.Builder description(@Nullable Text description) {
|
||||||
this.description = Objects.requireNonNull(description, "description");
|
this.description = description;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
|||||||
throw new IllegalStateException("id cannot be null");
|
throw new IllegalStateException("id cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
LPPermissionDescription d = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
|
||||||
|
|
||||||
// Set role-templates
|
// Set role-templates
|
||||||
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
|
||||||
@ -100,14 +101,14 @@ public final class SimpleDescriptionBuilder implements PermissionDescription.Bui
|
|||||||
this.id = null;
|
this.id = null;
|
||||||
this.description = null;
|
this.description = null;
|
||||||
|
|
||||||
return d.sponge();
|
return description.sponge();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof SimpleDescriptionBuilder)) return false;
|
if (!(o instanceof LPDescriptionBuilder)) return false;
|
||||||
final SimpleDescriptionBuilder other = (SimpleDescriptionBuilder) o;
|
final LPDescriptionBuilder other = (LPDescriptionBuilder) o;
|
||||||
|
|
||||||
return this.container.equals(other.container) &&
|
return this.container.equals(other.container) &&
|
||||||
this.roles.equals(other.roles) &&
|
this.roles.equals(other.roles) &&
|
@ -31,7 +31,7 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
@ -44,6 +44,7 @@ import org.spongepowered.api.service.permission.SubjectReference;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@ -115,8 +116,20 @@ public final class PermissionServiceProxy implements PermissionService {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SubjectReference newSubjectReference(@Nonnull String s, @Nonnull String s1) {
|
public SubjectReference newSubjectReference(@Nonnull String collectionIdentifier, @Nonnull String subjectIdentifier) {
|
||||||
return SubjectReferenceFactory.obtain(this.handle, s, s1);
|
Objects.requireNonNull(collectionIdentifier, "collectionIdentifier");
|
||||||
|
Objects.requireNonNull(subjectIdentifier, "subjectIdentifier");
|
||||||
|
|
||||||
|
// test the identifiers
|
||||||
|
String collection = collectionIdentifier.toLowerCase();
|
||||||
|
if (collection.equals("user") && !this.handle.getUserSubjects().getIdentifierValidityPredicate().test(subjectIdentifier)) {
|
||||||
|
throw new IllegalArgumentException("Subject identifier '" + subjectIdentifier + "' does not pass the validity predicate for the user subject collection");
|
||||||
|
} else if (collection.equals("group") && !this.handle.getGroupSubjects().getIdentifierValidityPredicate().test(subjectIdentifier)) {
|
||||||
|
throw new IllegalArgumentException("Subject identifier '" + subjectIdentifier + "' does not pass the validity predicate for the group subject collection");
|
||||||
|
}
|
||||||
|
|
||||||
|
// obtain a reference
|
||||||
|
return SubjectReferenceFactory.obtain(this.handle, collectionIdentifier, subjectIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -126,7 +139,7 @@ public final class PermissionServiceProxy implements PermissionService {
|
|||||||
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
throw new IllegalArgumentException("Couldn't find a plugin container for " + o.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SimpleDescriptionBuilder(this.handle, container.get());
|
return new LPDescriptionBuilder(this.handle, container.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
|||||||
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
@ -38,6 +38,7 @@ import org.spongepowered.api.service.permission.SubjectReference;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@ -103,8 +104,13 @@ public final class SubjectCollectionProxy implements SubjectCollection {
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SubjectReference newSubjectReference(@Nonnull String s) {
|
public SubjectReference newSubjectReference(@Nonnull String subjectIdentifier) {
|
||||||
return SubjectReferenceFactory.obtain(this.handle.getService(), getIdentifier(), s);
|
Objects.requireNonNull(subjectIdentifier, "identifier");
|
||||||
|
if (!this.handle.getIdentifierValidityPredicate().test(subjectIdentifier)) {
|
||||||
|
throw new IllegalArgumentException("Subject identifier '" + subjectIdentifier + "' does not pass the validity predicate");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SubjectReferenceFactory.obtain(this.handle.getService(), getIdentifier(), subjectIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -30,8 +30,8 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
@ -48,17 +48,19 @@ import javax.annotation.Nullable;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final class SubjectDataProxy implements SubjectData {
|
public final class SubjectDataProxy implements SubjectData {
|
||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final SubjectReference ref;
|
private final LPSubjectReference ref;
|
||||||
private final boolean enduring;
|
private final boolean enduring;
|
||||||
|
|
||||||
public SubjectDataProxy(LPPermissionService service, SubjectReference ref, boolean enduring) {
|
public SubjectDataProxy(LPPermissionService service, LPSubjectReference ref, boolean enduring) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
this.enduring = enduring;
|
this.enduring = enduring;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<LPSubjectData> handle() {
|
private CompletableFuture<LPSubjectData> handle() {
|
||||||
return this.enduring ? this.ref.resolveLp().thenApply(LPSubject::getSubjectData) : this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
return this.enduring ?
|
||||||
|
this.ref.resolveLp().thenApply(LPSubject::getSubjectData) :
|
||||||
|
this.ref.resolveLp().thenApply(LPSubject::getTransientSubjectData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -30,14 +30,15 @@ import me.lucko.luckperms.sponge.service.CompatibilityUtil;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.service.context.Context;
|
import org.spongepowered.api.service.context.Context;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
|
import org.spongepowered.api.service.permission.SubjectReference;
|
||||||
import org.spongepowered.api.util.Tristate;
|
import org.spongepowered.api.util.Tristate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -50,26 +51,27 @@ import javax.annotation.Nonnull;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final class SubjectProxy implements Subject, ProxiedSubject {
|
public final class SubjectProxy implements Subject, ProxiedSubject {
|
||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final SubjectReference ref;
|
private final LPSubjectReference ref;
|
||||||
|
|
||||||
public SubjectProxy(LPPermissionService service, SubjectReference ref) {
|
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<LPSubject> getHandle() {
|
private CompletableFuture<LPSubject> handle() {
|
||||||
return this.ref.resolveLp();
|
return this.ref.resolveLp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public SubjectReference getReference() {
|
public LPSubjectReference asSubjectReference() {
|
||||||
return this.ref;
|
return this.ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<CommandSource> getCommandSource() {
|
public Optional<CommandSource> getCommandSource() {
|
||||||
return getHandle().thenApply(LPSubject::getCommandSource).join();
|
return handle().thenApply(LPSubject::getCommandSource).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -78,12 +80,6 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
return this.service.getCollection(this.ref.getCollectionIdentifier()).sponge();
|
return this.service.getCollection(this.ref.getCollectionIdentifier()).sponge();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public org.spongepowered.api.service.permission.SubjectReference asSubjectReference() {
|
|
||||||
return this.ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSubjectDataPersisted() {
|
public boolean isSubjectDataPersisted() {
|
||||||
return true;
|
return true;
|
||||||
@ -101,52 +97,52 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(@Nonnull Set<Context> contexts, @Nonnull String permission) {
|
public boolean hasPermission(@Nonnull Set<Context> contexts, @Nonnull String permission) {
|
||||||
return getHandle().thenApply(handle -> handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean()).join();
|
return handle().thenApply(handle -> handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission).asBoolean()).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(@Nonnull String permission) {
|
public boolean hasPermission(@Nonnull String permission) {
|
||||||
return getHandle().thenApply(handle -> handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean()).join();
|
return handle().thenApply(handle -> handle.getPermissionValue(ImmutableContextSet.empty(), permission).asBoolean()).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Tristate getPermissionValue(@Nonnull Set<Context> contexts, @Nonnull String permission) {
|
public Tristate getPermissionValue(@Nonnull Set<Context> contexts, @Nonnull String permission) {
|
||||||
return getHandle().thenApply(handle -> CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission))).join();
|
return handle().thenApply(handle -> CompatibilityUtil.convertTristate(handle.getPermissionValue(CompatibilityUtil.convertContexts(contexts), permission))).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(@Nonnull org.spongepowered.api.service.permission.SubjectReference parent) {
|
public boolean isChildOf(@Nonnull SubjectReference parent) {
|
||||||
return getHandle().thenApply(handle -> handle.isChildOf(ImmutableContextSet.empty(), SubjectReferenceFactory.obtain(this.service, parent))).join();
|
return handle().thenApply(handle -> handle.isChildOf(ImmutableContextSet.empty(), SubjectReferenceFactory.obtain(this.service, parent))).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(@Nonnull Set<Context> contexts, @Nonnull org.spongepowered.api.service.permission.SubjectReference parent) {
|
public boolean isChildOf(@Nonnull Set<Context> contexts, @Nonnull SubjectReference parent) {
|
||||||
return getHandle().thenApply(handle -> handle.isChildOf(CompatibilityUtil.convertContexts(contexts), SubjectReferenceFactory.obtain(this.service, parent))).join();
|
return handle().thenApply(handle -> handle.isChildOf(CompatibilityUtil.convertContexts(contexts), SubjectReferenceFactory.obtain(this.service, parent))).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<org.spongepowered.api.service.permission.SubjectReference> getParents() {
|
public List<SubjectReference> getParents() {
|
||||||
return (List) getHandle().thenApply(handle -> handle.getParents(ImmutableContextSet.empty())).join();
|
return (List) handle().thenApply(handle -> handle.getParents(ImmutableContextSet.empty())).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<org.spongepowered.api.service.permission.SubjectReference> getParents(@Nonnull Set<Context> contexts) {
|
public List<SubjectReference> getParents(@Nonnull Set<Context> contexts) {
|
||||||
return (List) getHandle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join();
|
return (List) handle().thenApply(handle -> handle.getParents(CompatibilityUtil.convertContexts(contexts))).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getOption(@Nonnull Set<Context> contexts, @Nonnull String key) {
|
public Optional<String> getOption(@Nonnull Set<Context> contexts, @Nonnull String key) {
|
||||||
return getHandle().thenApply(handle -> handle.getOption(CompatibilityUtil.convertContexts(contexts), key)).join();
|
return handle().thenApply(handle -> handle.getOption(CompatibilityUtil.convertContexts(contexts), key)).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getOption(@Nonnull String key) {
|
public Optional<String> getOption(@Nonnull String key) {
|
||||||
return getHandle().thenApply(handle -> handle.getOption(ImmutableContextSet.empty(), key)).join();
|
return handle().thenApply(handle -> handle.getOption(ImmutableContextSet.empty(), key)).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -157,13 +153,13 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getFriendlyIdentifier() {
|
public Optional<String> getFriendlyIdentifier() {
|
||||||
return getHandle().thenApply(LPSubject::getFriendlyIdentifier).join();
|
return handle().thenApply(LPSubject::getFriendlyIdentifier).join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Context> getActiveContexts() {
|
public Set<Context> getActiveContexts() {
|
||||||
return getHandle().thenApply(handle -> CompatibilityUtil.convertContexts(handle.getActiveContextSet())).join();
|
return CompatibilityUtil.convertContexts(this.service.getPlugin().getContextManager().getApplicableContext(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.model;
|
package me.lucko.luckperms.sponge.service.model;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||||
import org.spongepowered.api.text.Text;
|
import org.spongepowered.api.text.Text;
|
||||||
@ -48,7 +50,7 @@ public interface LPPermissionDescription {
|
|||||||
|
|
||||||
Optional<PluginContainer> getOwner();
|
Optional<PluginContainer> getOwner();
|
||||||
|
|
||||||
CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String collectionIdentifier);
|
CompletableFuture<Map<LPSubjectReference, Boolean>> findAssignedSubjects(String collectionIdentifier);
|
||||||
|
|
||||||
Map<LPSubject, Boolean> getAssignedSubjects(String collectionIdentifier);
|
Map<LPSubject, Boolean> getAssignedSubjects(String collectionIdentifier);
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ import com.google.common.collect.ImmutableCollection;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.service.context.ContextCalculator;
|
import org.spongepowered.api.service.context.ContextCalculator;
|
||||||
@ -46,7 +47,7 @@ import java.util.function.Predicate;
|
|||||||
*/
|
*/
|
||||||
public interface LPPermissionService {
|
public interface LPPermissionService {
|
||||||
|
|
||||||
LuckPermsPlugin getPlugin();
|
LuckPermsSpongePlugin getPlugin();
|
||||||
|
|
||||||
SubjectReferenceFactory getReferenceFactory();
|
SubjectReferenceFactory getReferenceFactory();
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ public interface LPPermissionService {
|
|||||||
void registerContextCalculator(ContextCalculator<Subject> calculator);
|
void registerContextCalculator(ContextCalculator<Subject> calculator);
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
ImmutableList<SubjectReference> sortSubjects(Collection<SubjectReference> s);
|
ImmutableList<LPSubjectReference> sortSubjects(Collection<LPSubjectReference> s);
|
||||||
|
|
||||||
void invalidateAllCaches(LPSubject.CacheLevel cacheLevel);
|
void invalidateAllCaches(LPSubject.CacheLevel cacheLevel);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ import com.google.common.collect.ImmutableList;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
@ -46,7 +48,7 @@ public interface LPSubject {
|
|||||||
|
|
||||||
String getIdentifier();
|
String getIdentifier();
|
||||||
|
|
||||||
default SubjectReference toReference() {
|
default LPSubjectReference toReference() {
|
||||||
return SubjectReferenceFactory.obtain(getService(), this);
|
return SubjectReferenceFactory.obtain(getService(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,14 +72,12 @@ public interface LPSubject {
|
|||||||
|
|
||||||
Tristate getPermissionValue(ImmutableContextSet contexts, String permission);
|
Tristate getPermissionValue(ImmutableContextSet contexts, String permission);
|
||||||
|
|
||||||
boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent);
|
boolean isChildOf(ImmutableContextSet contexts, LPSubjectReference parent);
|
||||||
|
|
||||||
ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts);
|
ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts);
|
||||||
|
|
||||||
Optional<String> getOption(ImmutableContextSet contexts, String key);
|
Optional<String> getOption(ImmutableContextSet contexts, String key);
|
||||||
|
|
||||||
ImmutableContextSet getActiveContextSet();
|
|
||||||
|
|
||||||
default void performCleanup() {
|
default void performCleanup() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||||
|
|
||||||
@ -63,9 +64,9 @@ public interface LPSubjectCollection {
|
|||||||
|
|
||||||
CompletableFuture<ImmutableSet<String>> getAllIdentifiers();
|
CompletableFuture<ImmutableSet<String>> getAllIdentifiers();
|
||||||
|
|
||||||
CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(String permission);
|
CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(String permission);
|
||||||
|
|
||||||
CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission);
|
CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission);
|
||||||
|
|
||||||
ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission);
|
ImmutableMap<LPSubject, Boolean> getLoadedWithPermission(String permission);
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
import me.lucko.luckperms.api.Tristate;
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.SubjectData;
|
import org.spongepowered.api.service.permission.SubjectData;
|
||||||
|
|
||||||
@ -58,15 +59,15 @@ public interface LPSubjectData {
|
|||||||
|
|
||||||
/* parents */
|
/* parents */
|
||||||
|
|
||||||
ImmutableMap<ImmutableContextSet, ImmutableList<SubjectReference>> getAllParents();
|
ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents();
|
||||||
|
|
||||||
default ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
default ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
|
||||||
return ImmutableList.copyOf(getAllParents().getOrDefault(contexts, ImmutableList.of()));
|
return ImmutableList.copyOf(getAllParents().getOrDefault(contexts, ImmutableList.of()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference parent);
|
CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, LPSubjectReference parent);
|
||||||
|
|
||||||
CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference parent);
|
CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, LPSubjectReference parent);
|
||||||
|
|
||||||
CompletableFuture<Boolean> clearParents();
|
CompletableFuture<Boolean> clearParents();
|
||||||
|
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.sponge.service.model;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||||
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
|
|
||||||
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
|
public interface LuckPermsSpongePlugin extends LuckPermsPlugin {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
ContextManager<Subject> getContextManager();
|
||||||
|
|
||||||
|
}
|
@ -25,11 +25,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.model;
|
package me.lucko.luckperms.sponge.service.model;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks that an object is a proxied representation of a {@link org.spongepowered.api.service.permission.Subject}.
|
* Marks that an object is a proxied representation of a {@link Subject}.
|
||||||
*/
|
*/
|
||||||
public interface ProxiedSubject {
|
public interface ProxiedSubject {
|
||||||
|
|
||||||
SubjectReference getReference();
|
@Nonnull
|
||||||
|
LPSubjectReference asSubjectReference();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.sponge.service.reference;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
|
||||||
|
import org.spongepowered.api.service.permission.SubjectReference;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LuckPerms model for the Sponge {@link SubjectReference}
|
||||||
|
*/
|
||||||
|
public interface LPSubjectReference extends SubjectReference {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
CompletableFuture<LPSubject> resolveLp();
|
||||||
|
|
||||||
|
}
|
@ -23,7 +23,10 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.model;
|
package me.lucko.luckperms.sponge.service.reference;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ import javax.annotation.Nonnull;
|
|||||||
* Use of this class (or interface) should have no negative impact on
|
* Use of this class (or interface) should have no negative impact on
|
||||||
* performance, as {@link #resolve()} calls are cached.
|
* performance, as {@link #resolve()} calls are cached.
|
||||||
*/
|
*/
|
||||||
public final class SubjectReference implements org.spongepowered.api.service.permission.SubjectReference {
|
final class LuckPermsSubjectReference implements LPSubjectReference {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time a subject instance should be cached in this reference
|
* The time a subject instance should be cached in this reference
|
||||||
@ -68,7 +71,7 @@ public final class SubjectReference implements org.spongepowered.api.service.per
|
|||||||
private long lastLookup = 0L;
|
private long lastLookup = 0L;
|
||||||
private WeakReference<LPSubject> cache = null;
|
private WeakReference<LPSubject> cache = null;
|
||||||
|
|
||||||
SubjectReference(LPPermissionService service, String collectionIdentifier, String subjectIdentifier) {
|
LuckPermsSubjectReference(LPPermissionService service, String collectionIdentifier, String subjectIdentifier) {
|
||||||
this.service = Objects.requireNonNull(service);
|
this.service = Objects.requireNonNull(service);
|
||||||
this.collectionIdentifier = Objects.requireNonNull(collectionIdentifier);
|
this.collectionIdentifier = Objects.requireNonNull(collectionIdentifier);
|
||||||
this.subjectIdentifier = Objects.requireNonNull(subjectIdentifier);
|
this.subjectIdentifier = Objects.requireNonNull(subjectIdentifier);
|
||||||
@ -130,6 +133,8 @@ public final class SubjectReference implements org.spongepowered.api.service.per
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
public CompletableFuture<LPSubject> resolveLp() {
|
public CompletableFuture<LPSubject> resolveLp() {
|
||||||
// check if there is a cached value before loading
|
// check if there is a cached value before loading
|
||||||
LPSubject s = tryCache();
|
LPSubject s = tryCache();
|
||||||
@ -157,9 +162,10 @@ public final class SubjectReference implements org.spongepowered.api.service.per
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o == this) return true;
|
if (o == this) return true;
|
||||||
if (!(o instanceof SubjectReference)) return false;
|
if (!(o instanceof LPSubjectReference)) return false;
|
||||||
final SubjectReference other = (SubjectReference) o;
|
final LPSubjectReference other = (LPSubjectReference) o;
|
||||||
return this.collectionIdentifier.equals(other.collectionIdentifier) && this.subjectIdentifier.equals(other.subjectIdentifier);
|
return this.collectionIdentifier.equals(other.getCollectionIdentifier()) &&
|
||||||
|
this.subjectIdentifier.equals(other.getSubjectIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -23,47 +23,52 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package me.lucko.luckperms.sponge.service.model;
|
package me.lucko.luckperms.sponge.service.reference;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.ProxiedSubject;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.Subject;
|
import org.spongepowered.api.service.permission.Subject;
|
||||||
|
import org.spongepowered.api.service.permission.SubjectReference;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the creation of {@link SubjectReference}s.
|
* Caches the creation of {@link LPSubjectReference}s.
|
||||||
*/
|
*/
|
||||||
public final class SubjectReferenceFactory {
|
public final class SubjectReferenceFactory {
|
||||||
|
|
||||||
// static util access
|
// static util access
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static SubjectReference deserialize(LPPermissionService service, String serialisedReference) {
|
public static LPSubjectReference deserialize(LPPermissionService service, String serialisedReference) {
|
||||||
Objects.requireNonNull(service, "service");
|
Objects.requireNonNull(service, "service");
|
||||||
return service.getReferenceFactory().deserialize(serialisedReference);
|
return service.getReferenceFactory().deserialize(serialisedReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SubjectReference obtain(LPPermissionService service, LPSubject subject) {
|
public static LPSubjectReference obtain(LPPermissionService service, LPSubject subject) {
|
||||||
Objects.requireNonNull(service, "service");
|
Objects.requireNonNull(service, "service");
|
||||||
return service.getReferenceFactory().obtain(subject);
|
return service.getReferenceFactory().obtain(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SubjectReference obtain(LPPermissionService service, Subject subject) {
|
public static LPSubjectReference obtain(LPPermissionService service, Subject subject) {
|
||||||
Objects.requireNonNull(service, "service");
|
Objects.requireNonNull(service, "service");
|
||||||
return service.getReferenceFactory().obtain(subject);
|
return service.getReferenceFactory().obtain(subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SubjectReference obtain(LPPermissionService service, org.spongepowered.api.service.permission.SubjectReference reference) {
|
public static LPSubjectReference obtain(LPPermissionService service, SubjectReference reference) {
|
||||||
Objects.requireNonNull(service, "service");
|
Objects.requireNonNull(service, "service");
|
||||||
return service.getReferenceFactory().obtain(reference);
|
return service.getReferenceFactory().obtain(reference);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SubjectReference obtain(LPPermissionService service, String collectionIdentifier, String subjectIdentifier) {
|
public static LPSubjectReference obtain(LPPermissionService service, String collectionIdentifier, String subjectIdentifier) {
|
||||||
Objects.requireNonNull(service, "service");
|
Objects.requireNonNull(service, "service");
|
||||||
return service.getReferenceFactory().obtain(collectionIdentifier, subjectIdentifier);
|
return service.getReferenceFactory().obtain(collectionIdentifier, subjectIdentifier);
|
||||||
}
|
}
|
||||||
@ -82,47 +87,47 @@ public final class SubjectReferenceFactory {
|
|||||||
*
|
*
|
||||||
* It's perfectly ok if two instances of the same SubjectReference exist. (hence the 1 hour expiry)
|
* It's perfectly ok if two instances of the same SubjectReference exist. (hence the 1 hour expiry)
|
||||||
*/
|
*/
|
||||||
private final LoadingCache<SubjectReferenceAttributes, SubjectReference> referenceCache = Caffeine.newBuilder()
|
private final LoadingCache<SubjectReferenceAttributes, LuckPermsSubjectReference> referenceCache = Caffeine.newBuilder()
|
||||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||||
.build(a -> new SubjectReference(SubjectReferenceFactory.this.service, a.collectionId, a.id));
|
.build(a -> new LuckPermsSubjectReference(SubjectReferenceFactory.this.service, a.collectionId, a.id));
|
||||||
|
|
||||||
public SubjectReferenceFactory(LPPermissionService service) {
|
public SubjectReferenceFactory(LPPermissionService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SubjectReference deserialize(String serialisedReference) {
|
public LPSubjectReference deserialize(String serialisedReference) {
|
||||||
Objects.requireNonNull(serialisedReference, "serialisedReference");
|
Objects.requireNonNull(serialisedReference, "serialisedReference");
|
||||||
List<String> parts = Splitter.on('/').limit(2).splitToList(serialisedReference);
|
List<String> parts = Splitter.on('/').limit(2).splitToList(serialisedReference);
|
||||||
return obtain(parts.get(0), parts.get(1));
|
return obtain(parts.get(0), parts.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubjectReference obtain(LPSubject subject) {
|
public LPSubjectReference obtain(LPSubject subject) {
|
||||||
Objects.requireNonNull(subject, "subject");
|
Objects.requireNonNull(subject, "subject");
|
||||||
SubjectReference ret = obtain(subject.getParentCollection().getIdentifier(), subject.getIdentifier());
|
LPSubjectReference ret = obtain(subject.getParentCollection().getIdentifier(), subject.getIdentifier());
|
||||||
ret.fillCache(subject);
|
((LuckPermsSubjectReference) ret).fillCache(subject);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubjectReference obtain(Subject subject) {
|
public LPSubjectReference obtain(Subject subject) {
|
||||||
Objects.requireNonNull(subject, "subject");
|
Objects.requireNonNull(subject, "subject");
|
||||||
if (subject instanceof ProxiedSubject) {
|
if (subject instanceof ProxiedSubject) {
|
||||||
return ((ProxiedSubject) subject).getReference();
|
return ((ProxiedSubject) subject).asSubjectReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
return obtain(subject.getContainingCollection().getIdentifier(), subject.getIdentifier());
|
return obtain(subject.getContainingCollection().getIdentifier(), subject.getIdentifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubjectReference obtain(org.spongepowered.api.service.permission.SubjectReference reference) {
|
public LPSubjectReference obtain(SubjectReference reference) {
|
||||||
Objects.requireNonNull(reference, "reference");
|
Objects.requireNonNull(reference, "reference");
|
||||||
if (reference instanceof SubjectReference) {
|
if (reference instanceof LPSubjectReference) {
|
||||||
return ((SubjectReference) reference);
|
return ((LPSubjectReference) reference);
|
||||||
} else {
|
} else {
|
||||||
return obtain(reference.getCollectionIdentifier(), reference.getSubjectIdentifier());
|
return obtain(reference.getCollectionIdentifier(), reference.getSubjectIdentifier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubjectReference obtain(String collectionIdentifier, String subjectIdentifier) {
|
public LPSubjectReference obtain(String collectionIdentifier, String subjectIdentifier) {
|
||||||
Objects.requireNonNull(collectionIdentifier, "collectionIdentifier");
|
Objects.requireNonNull(collectionIdentifier, "collectionIdentifier");
|
||||||
Objects.requireNonNull(subjectIdentifier, "subjectIdentifier");
|
Objects.requireNonNull(subjectIdentifier, "subjectIdentifier");
|
||||||
return this.referenceCache.get(new SubjectReferenceAttributes(collectionIdentifier, subjectIdentifier));
|
return this.referenceCache.get(new SubjectReferenceAttributes(collectionIdentifier, subjectIdentifier));
|
||||||
@ -134,10 +139,12 @@ public final class SubjectReferenceFactory {
|
|||||||
private static final class SubjectReferenceAttributes {
|
private static final class SubjectReferenceAttributes {
|
||||||
private final String collectionId;
|
private final String collectionId;
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
public SubjectReferenceAttributes(String collectionId, String id) {
|
private SubjectReferenceAttributes(String collectionId, String id) {
|
||||||
this.collectionId = collectionId;
|
this.collectionId = collectionId.toLowerCase();
|
||||||
this.id = id;
|
this.id = id.toLowerCase();
|
||||||
|
this.hashCode = calculateHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -148,14 +155,18 @@ public final class SubjectReferenceFactory {
|
|||||||
return this.collectionId.equals(other.collectionId) && this.id.equals(other.id);
|
return this.collectionId.equals(other.collectionId) && this.id.equals(other.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int calculateHashCode() {
|
||||||
public int hashCode() {
|
|
||||||
final int PRIME = 59;
|
final int PRIME = 59;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = result * PRIME + this.collectionId.hashCode();
|
result = result * PRIME + this.collectionId.hashCode();
|
||||||
result = result * PRIME + this.id.hashCode();
|
result = result * PRIME + this.id.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return this.hashCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -57,7 +57,6 @@ import me.lucko.luckperms.common.logging.SenderLogger;
|
|||||||
import me.lucko.luckperms.common.managers.track.StandardTrackManager;
|
import me.lucko.luckperms.common.managers.track.StandardTrackManager;
|
||||||
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
import me.lucko.luckperms.common.messaging.ExtendedMessagingService;
|
||||||
import me.lucko.luckperms.common.model.User;
|
import me.lucko.luckperms.common.model.User;
|
||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
|
||||||
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
|
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
import me.lucko.luckperms.common.storage.Storage;
|
||||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||||
@ -82,6 +81,7 @@ import me.lucko.luckperms.sponge.service.LuckPermsService;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LuckPermsSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
||||||
import me.lucko.luckperms.sponge.tasks.ServiceCacheHousekeepingTask;
|
import me.lucko.luckperms.sponge.tasks.ServiceCacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.sponge.utils.VersionData;
|
import me.lucko.luckperms.sponge.utils.VersionData;
|
||||||
@ -136,7 +136,7 @@ import java.util.stream.Stream;
|
|||||||
description = "A permissions plugin",
|
description = "A permissions plugin",
|
||||||
url = "https://github.com/lucko/LuckPerms"
|
url = "https://github.com/lucko/LuckPerms"
|
||||||
)
|
)
|
||||||
public class LPSpongePlugin implements LuckPermsPlugin {
|
public class LPSpongePlugin implements LuckPermsSpongePlugin {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
@ -39,7 +39,7 @@ import me.lucko.luckperms.common.locale.LocaleManager;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -54,18 +54,18 @@ public class ParentInfo extends SubCommand<LPSubjectData> {
|
|||||||
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
ImmutableContextSet contextSet = ArgumentUtils.handleContextSponge(0, args);
|
||||||
if (contextSet.isEmpty()) {
|
if (contextSet.isEmpty()) {
|
||||||
CommandUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
|
CommandUtils.sendPluginMessage(sender, "&aShowing parents matching contexts &bANY&a.");
|
||||||
Map<ImmutableContextSet, ImmutableList<SubjectReference>> parents = subjectData.getAllParents();
|
Map<ImmutableContextSet, ImmutableList<LPSubjectReference>> parents = subjectData.getAllParents();
|
||||||
if (parents.isEmpty()) {
|
if (parents.isEmpty()) {
|
||||||
CommandUtils.sendPluginMessage(sender, "That subject does not have any parents defined.");
|
CommandUtils.sendPluginMessage(sender, "That subject does not have any parents defined.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<ImmutableContextSet, ImmutableList<SubjectReference>> e : parents.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, ImmutableList<LPSubjectReference>> e : parents.entrySet()) {
|
||||||
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
|
CommandUtils.sendPluginMessage(sender, "&3>> &bContext: " + SpongeCommandUtils.contextToString(e.getKey()) + "\n" + SpongeCommandUtils.parentsToString(e.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
List<SubjectReference> parents = subjectData.getParents(contextSet);
|
List<LPSubjectReference> parents = subjectData.getParents(contextSet);
|
||||||
if (parents.isEmpty()) {
|
if (parents.isEmpty()) {
|
||||||
CommandUtils.sendPluginMessage(sender, "That subject does not have any parents defined in those contexts.");
|
CommandUtils.sendPluginMessage(sender, "That subject does not have any parents defined in those contexts.");
|
||||||
return CommandResult.SUCCESS;
|
return CommandResult.SUCCESS;
|
||||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
import me.lucko.luckperms.api.context.ContextSet;
|
import me.lucko.luckperms.api.context.ContextSet;
|
||||||
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
import me.lucko.luckperms.common.commands.utils.ArgumentUtils;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -73,9 +73,9 @@ public final class SpongeCommandUtils {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parentsToString(Iterable<SubjectReference> parents) {
|
public static String parentsToString(Iterable<LPSubjectReference> parents) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (SubjectReference s : parents) {
|
for (LPSubjectReference s : parents) {
|
||||||
sb.append("&3> &a")
|
sb.append("&3> &a")
|
||||||
.append(s.getSubjectIdentifier())
|
.append(s.getSubjectIdentifier())
|
||||||
.append(" &bfrom collection &a")
|
.append(" &bfrom collection &a")
|
||||||
|
@ -45,8 +45,8 @@ import me.lucko.luckperms.sponge.service.LuckPermsService;
|
|||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||||
@ -129,9 +129,7 @@ public class SpongeGroupManager extends AbstractGroupManager<SpongeGroup> implem
|
|||||||
@Override
|
@Override
|
||||||
public CompletableFuture<LPSubject> loadSubject(String identifier) {
|
public CompletableFuture<LPSubject> loadSubject(String identifier) {
|
||||||
if (!DataConstraints.GROUP_NAME_TEST.test(identifier)) {
|
if (!DataConstraints.GROUP_NAME_TEST.test(identifier)) {
|
||||||
CompletableFuture<LPSubject> fut = new CompletableFuture<>();
|
throw new IllegalArgumentException("Illegal subject identifier");
|
||||||
fut.completeExceptionally(new IllegalArgumentException("Illegal subject identifier"));
|
|
||||||
return fut;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LPSubject present = this.subjectLoadingCache.getIfPresent(identifier.toLowerCase());
|
LPSubject present = this.subjectLoadingCache.getIfPresent(identifier.toLowerCase());
|
||||||
@ -144,16 +142,20 @@ public class SpongeGroupManager extends AbstractGroupManager<SpongeGroup> implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<LPSubject> getSubject(String identifier) {
|
public Optional<LPSubject> getSubject(String identifier) {
|
||||||
|
if (!DataConstraints.GROUP_NAME_TEST.test(identifier)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
return Optional.ofNullable(getIfLoaded(identifier.toLowerCase())).map(SpongeGroup::sponge);
|
return Optional.ofNullable(getIfLoaded(identifier.toLowerCase())).map(SpongeGroup::sponge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> hasRegistered(String identifier) {
|
public CompletableFuture<Boolean> hasRegistered(String identifier) {
|
||||||
if (isLoaded(identifier.toLowerCase())) {
|
if (!DataConstraints.GROUP_NAME_TEST.test(identifier)) {
|
||||||
return CompletableFuture.completedFuture(true);
|
|
||||||
} else {
|
|
||||||
return CompletableFuture.completedFuture(false);
|
return CompletableFuture.completedFuture(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return CompletableFuture.completedFuture(isLoaded(identifier.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -161,6 +163,9 @@ public class SpongeGroupManager extends AbstractGroupManager<SpongeGroup> implem
|
|||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
||||||
for (String id : identifiers) {
|
for (String id : identifiers) {
|
||||||
|
if (!DataConstraints.GROUP_NAME_TEST.test(id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ret.add(loadSubject(id.toLowerCase()).join());
|
ret.add(loadSubject(id.toLowerCase()).join());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,9 +184,9 @@ public class SpongeGroupManager extends AbstractGroupManager<SpongeGroup> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(String permission) {
|
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(String permission) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
ImmutableMap.Builder<LPSubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||||
|
|
||||||
List<HeldPermission<String>> lookup = this.plugin.getStorage().getGroupsWithPermission(permission).join();
|
List<HeldPermission<String>> lookup = this.plugin.getStorage().getGroupsWithPermission(permission).join();
|
||||||
for (HeldPermission<String> holder : lookup) {
|
for (HeldPermission<String> holder : lookup) {
|
||||||
@ -195,9 +200,9 @@ public class SpongeGroupManager extends AbstractGroupManager<SpongeGroup> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission) {
|
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
ImmutableMap.Builder<LPSubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||||
|
|
||||||
List<HeldPermission<String>> lookup = this.plugin.getStorage().getGroupsWithPermission(permission).join();
|
List<HeldPermission<String>> lookup = this.plugin.getStorage().getGroupsWithPermission(permission).join();
|
||||||
for (HeldPermission<String> holder : lookup) {
|
for (HeldPermission<String> holder : lookup) {
|
||||||
|
@ -39,14 +39,15 @@ import me.lucko.luckperms.common.managers.user.AbstractUserManager;
|
|||||||
import me.lucko.luckperms.common.managers.user.UserHousekeeper;
|
import me.lucko.luckperms.common.managers.user.UserHousekeeper;
|
||||||
import me.lucko.luckperms.common.references.UserIdentifier;
|
import me.lucko.luckperms.common.references.UserIdentifier;
|
||||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.model.SpongeUser;
|
import me.lucko.luckperms.sponge.model.SpongeUser;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||||
@ -133,26 +134,14 @@ public class SpongeUserManager extends AbstractUserManager<SpongeUser> implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Predicate<String> getIdentifierValidityPredicate() {
|
public Predicate<String> getIdentifierValidityPredicate() {
|
||||||
return s -> {
|
return Uuids.PREDICATE;
|
||||||
try {
|
|
||||||
//noinspection ResultOfMethodCallIgnored
|
|
||||||
UUID.fromString(s);
|
|
||||||
return true;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<LPSubject> loadSubject(String identifier) {
|
public CompletableFuture<LPSubject> loadSubject(String identifier) {
|
||||||
UUID uuid;
|
UUID uuid = Uuids.parseNullable(identifier);
|
||||||
try {
|
if (uuid == null) {
|
||||||
uuid = UUID.fromString(identifier);
|
throw new IllegalArgumentException("Identifier is not a UUID: " + identifier);
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
CompletableFuture<LPSubject> fut = new CompletableFuture<>();
|
|
||||||
fut.completeExceptionally(e);
|
|
||||||
return fut;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LPSubject present = this.subjectLoadingCache.getIfPresent(uuid);
|
LPSubject present = this.subjectLoadingCache.getIfPresent(uuid);
|
||||||
@ -165,32 +154,25 @@ public class SpongeUserManager extends AbstractUserManager<SpongeUser> implement
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<LPSubject> getSubject(String identifier) {
|
public Optional<LPSubject> getSubject(String identifier) {
|
||||||
UUID uuid = UUID.fromString(identifier);
|
UUID uuid = Uuids.parseNullable(identifier);
|
||||||
|
if (uuid == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
return Optional.ofNullable(getIfLoaded(uuid)).map(SpongeUser::sponge);
|
return Optional.ofNullable(getIfLoaded(uuid)).map(SpongeUser::sponge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> hasRegistered(String identifier) {
|
public CompletableFuture<Boolean> hasRegistered(String identifier) {
|
||||||
UUID uuid = null;
|
UUID uuid = Uuids.parseNullable(identifier);
|
||||||
IllegalArgumentException ex = null;
|
if (uuid == null) {
|
||||||
try {
|
return CompletableFuture.completedFuture(false);
|
||||||
uuid = UUID.fromString(identifier);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
ex = e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid != null && isLoaded(UserIdentifier.of(uuid, null))) {
|
if (isLoaded(UserIdentifier.of(uuid, null))) {
|
||||||
return CompletableFuture.completedFuture(true);
|
return CompletableFuture.completedFuture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uuid == null) {
|
return this.plugin.getStorage().getUniqueUsers().thenApply(set -> set.contains(uuid));
|
||||||
CompletableFuture<Boolean> fut = new CompletableFuture<>();
|
|
||||||
fut.completeExceptionally(ex);
|
|
||||||
return fut;
|
|
||||||
}
|
|
||||||
|
|
||||||
UUID finalUuid = uuid;
|
|
||||||
return this.plugin.getStorage().getUniqueUsers().thenApply(set -> set.contains(finalUuid));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -198,13 +180,10 @@ public class SpongeUserManager extends AbstractUserManager<SpongeUser> implement
|
|||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
||||||
for (String id : identifiers) {
|
for (String id : identifiers) {
|
||||||
UUID uuid;
|
UUID uuid = Uuids.parseNullable(id);
|
||||||
try {
|
if (uuid == null) {
|
||||||
uuid = UUID.fromString(id);
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.add(loadSubject(uuid.toString()).join());
|
ret.add(loadSubject(uuid.toString()).join());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,9 +209,9 @@ public class SpongeUserManager extends AbstractUserManager<SpongeUser> implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(String permission) {
|
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(String permission) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
ImmutableMap.Builder<LPSubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||||
|
|
||||||
List<HeldPermission<UUID>> lookup = this.plugin.getStorage().getUsersWithPermission(permission).join();
|
List<HeldPermission<UUID>> lookup = this.plugin.getStorage().getUsersWithPermission(permission).join();
|
||||||
for (HeldPermission<UUID> holder : lookup) {
|
for (HeldPermission<UUID> holder : lookup) {
|
||||||
@ -246,9 +225,9 @@ public class SpongeUserManager extends AbstractUserManager<SpongeUser> implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission) {
|
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
ImmutableMap.Builder<SubjectReference, Boolean> ret = ImmutableMap.builder();
|
ImmutableMap.Builder<LPSubjectReference, Boolean> ret = ImmutableMap.builder();
|
||||||
|
|
||||||
List<HeldPermission<UUID>> lookup = this.plugin.getStorage().getUsersWithPermission(permission).join();
|
List<HeldPermission<UUID>> lookup = this.plugin.getStorage().getUsersWithPermission(permission).join();
|
||||||
for (HeldPermission<UUID> holder : lookup) {
|
for (HeldPermission<UUID> holder : lookup) {
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||||
@ -40,6 +39,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.common.utils.SafeIterator;
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
|||||||
log.log("Starting user migration.");
|
log.log("Starting user migration.");
|
||||||
AtomicInteger userCount = new AtomicInteger(0);
|
AtomicInteger userCount = new AtomicInteger(0);
|
||||||
SafeIterator.iterate(pmService.getUserSubjects().getAllSubjects(), pmUser -> {
|
SafeIterator.iterate(pmService.getUserSubjects().getAllSubjects(), pmUser -> {
|
||||||
UUID uuid = CommandUtils.parseUuid(pmUser.getIdentifier());
|
UUID uuid = Uuids.parseNullable(pmUser.getIdentifier());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.logErr("Could not parse UUID for user: " + pmUser.getIdentifier());
|
log.logErr("Could not parse UUID for user: " + pmUser.getIdentifier());
|
||||||
return;
|
return;
|
||||||
|
@ -31,7 +31,6 @@ import me.lucko.luckperms.common.commands.CommandResult;
|
|||||||
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
import me.lucko.luckperms.common.commands.abstraction.SubCommand;
|
||||||
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
import me.lucko.luckperms.common.commands.impl.migration.MigrationUtils;
|
||||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||||
import me.lucko.luckperms.common.commands.utils.CommandUtils;
|
|
||||||
import me.lucko.luckperms.common.locale.CommandSpec;
|
import me.lucko.luckperms.common.locale.CommandSpec;
|
||||||
import me.lucko.luckperms.common.locale.LocaleManager;
|
import me.lucko.luckperms.common.locale.LocaleManager;
|
||||||
import me.lucko.luckperms.common.logging.ProgressLogger;
|
import me.lucko.luckperms.common.logging.ProgressLogger;
|
||||||
@ -41,6 +40,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||||
import me.lucko.luckperms.common.utils.Predicates;
|
import me.lucko.luckperms.common.utils.Predicates;
|
||||||
import me.lucko.luckperms.common.utils.SafeIterator;
|
import me.lucko.luckperms.common.utils.SafeIterator;
|
||||||
|
import me.lucko.luckperms.common.utils.Uuids;
|
||||||
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
import me.lucko.luckperms.sponge.LPSpongePlugin;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
|||||||
int userWeight = maxWeight + 5;
|
int userWeight = maxWeight + 5;
|
||||||
|
|
||||||
SafeIterator.iterate(pexService.getUserSubjects().getAllSubjects(), pexUser -> {
|
SafeIterator.iterate(pexService.getUserSubjects().getAllSubjects(), pexUser -> {
|
||||||
UUID uuid = CommandUtils.parseUuid(pexUser.getIdentifier());
|
UUID uuid = Uuids.parseNullable(pexUser.getIdentifier());
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
log.logErr("Could not parse UUID for user: " + pexUser.getIdentifier());
|
log.logErr("Could not parse UUID for user: " + pexUser.getIdentifier());
|
||||||
return;
|
return;
|
||||||
|
@ -40,7 +40,7 @@ import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
|||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
@ -123,13 +123,13 @@ public class SpongeGroup extends Group {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent) {
|
public boolean isChildOf(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, NodeFactory.groupNode(parent.getSubjectIdentifier())).asBoolean();
|
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, NodeFactory.groupNode(parent.getSubjectIdentifier())).asBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
|
||||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
ImmutableSet.Builder<LPSubjectReference> subjects = ImmutableSet.builder();
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> entry : this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
for (Map.Entry<String, Boolean> entry : this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||||
if (!entry.getValue()) {
|
if (!entry.getValue()) {
|
||||||
@ -180,11 +180,6 @@ public class SpongeGroup extends Group {
|
|||||||
return this.plugin.getService().getDefaults().getOption(contexts, s);
|
return this.plugin.getService().getDefaults().getOption(contexts, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImmutableContextSet getActiveContextSet() {
|
|
||||||
return this.plugin.getContextManager().getApplicableContext(this.sponge());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateCaches(CacheLevel cacheLevel) {
|
public void invalidateCaches(CacheLevel cacheLevel) {
|
||||||
// invalidate for all changes
|
// invalidate for all changes
|
||||||
|
@ -40,7 +40,7 @@ import me.lucko.luckperms.sponge.service.LuckPermsSubjectData;
|
|||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
@ -132,13 +132,13 @@ public class SpongeUser extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference parent) {
|
public boolean isChildOf(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, NodeFactory.groupNode(parent.getSubjectIdentifier())).asBoolean();
|
return parent.getCollectionIdentifier().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, NodeFactory.groupNode(parent.getSubjectIdentifier())).asBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
|
||||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
ImmutableSet.Builder<LPSubjectReference> subjects = ImmutableSet.builder();
|
||||||
|
|
||||||
for (Map.Entry<String, Boolean> entry : this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
for (Map.Entry<String, Boolean> entry : this.parent.getCachedData().getPermissionData(this.plugin.getContextManager().formContexts(contexts)).getImmutableBacking().entrySet()) {
|
||||||
if (!entry.getValue()) {
|
if (!entry.getValue()) {
|
||||||
@ -189,11 +189,6 @@ public class SpongeUser extends User {
|
|||||||
return this.plugin.getService().getDefaults().getOption(contexts, s);
|
return this.plugin.getService().getDefaults().getOption(contexts, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImmutableContextSet getActiveContextSet() {
|
|
||||||
return this.plugin.getContextManager().getApplicableContext(this.sponge());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateCaches(CacheLevel cacheLevel) {
|
public void invalidateCaches(CacheLevel cacheLevel) {
|
||||||
// invalidate for all changes
|
// invalidate for all changes
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of LuckPerms, licensed under the MIT License.
|
||||||
|
*
|
||||||
|
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||||
|
* Copyright (c) contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.sponge.processors;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.api.Tristate;
|
||||||
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
|
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||||
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class DefaultsProcessor implements PermissionProcessor {
|
||||||
|
private final LuckPermsService service;
|
||||||
|
private final ImmutableContextSet contexts;
|
||||||
|
|
||||||
|
public DefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
||||||
|
this.service = service;
|
||||||
|
this.contexts = contexts;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract LPSubject getTypeDefaults(LuckPermsService service);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tristate hasPermission(String permission) {
|
||||||
|
Tristate t = getTypeDefaults(this.service).getPermissionValue(this.contexts, permission);
|
||||||
|
if (t != Tristate.UNDEFINED) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
t = this.service.getDefaults().getPermissionValue(this.contexts, permission);
|
||||||
|
if (t != Tristate.UNDEFINED) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Tristate.UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateBacking(Map<String, Boolean> map) {
|
||||||
|
// Do nothing, this doesn't use the backing
|
||||||
|
}
|
||||||
|
}
|
@ -25,39 +25,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.processors;
|
package me.lucko.luckperms.sponge.processors;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
|
||||||
import java.util.Map;
|
public class GroupDefaultsProcessor extends DefaultsProcessor implements PermissionProcessor {
|
||||||
|
|
||||||
public class GroupDefaultsProcessor implements PermissionProcessor {
|
|
||||||
private final LuckPermsService service;
|
|
||||||
private final ImmutableContextSet contexts;
|
|
||||||
|
|
||||||
public GroupDefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
public GroupDefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
||||||
this.service = service;
|
super(service, contexts);
|
||||||
this.contexts = contexts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate hasPermission(String permission) {
|
protected LPSubject getTypeDefaults(LuckPermsService service) {
|
||||||
Tristate t = this.service.getGroupSubjects().getDefaults().getPermissionValue(this.contexts, permission);
|
return service.getGroupSubjects().getDefaults();
|
||||||
if (t != Tristate.UNDEFINED) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
t = this.service.getDefaults().getPermissionValue(this.contexts, permission);
|
|
||||||
if (t != Tristate.UNDEFINED) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Tristate.UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateBacking(Map<String, Boolean> map) {
|
|
||||||
// Do nothing, this doesn't use the backing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,39 +25,18 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.sponge.processors;
|
package me.lucko.luckperms.sponge.processors;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.Tristate;
|
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
import me.lucko.luckperms.common.processors.PermissionProcessor;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
|
|
||||||
import java.util.Map;
|
public class UserDefaultsProcessor extends DefaultsProcessor implements PermissionProcessor {
|
||||||
|
|
||||||
public class UserDefaultsProcessor implements PermissionProcessor {
|
|
||||||
private final LuckPermsService service;
|
|
||||||
private final ImmutableContextSet contexts;
|
|
||||||
|
|
||||||
public UserDefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
public UserDefaultsProcessor(LuckPermsService service, ImmutableContextSet contexts) {
|
||||||
this.service = service;
|
super(service, contexts);
|
||||||
this.contexts = contexts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate hasPermission(String permission) {
|
protected LPSubject getTypeDefaults(LuckPermsService service) {
|
||||||
Tristate t = this.service.getUserSubjects().getDefaults().getPermissionValue(this.contexts, permission);
|
return service.getUserSubjects().getDefaults();
|
||||||
if (t != Tristate.UNDEFINED) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
t = this.service.getDefaults().getPermissionValue(this.contexts, permission);
|
|
||||||
if (t != Tristate.UNDEFINED) {
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Tristate.UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateBacking(Map<String, Boolean> map) {
|
|
||||||
// Do nothing, this doesn't use the backing
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
import org.spongepowered.api.service.permission.PermissionDescription;
|
import org.spongepowered.api.service.permission.PermissionDescription;
|
||||||
@ -89,7 +89,7 @@ public final class LuckPermsPermissionDescription implements LPPermissionDescrip
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Map<SubjectReference, Boolean>> findAssignedSubjects(String id) {
|
public CompletableFuture<Map<LPSubjectReference, Boolean>> findAssignedSubjects(String id) {
|
||||||
LPSubjectCollection collection = this.service.getCollection(id);
|
LPSubjectCollection collection = this.service.getCollection(id);
|
||||||
return (CompletableFuture) collection.getAllWithPermission(this.id);
|
return (CompletableFuture) collection.getAllWithPermission(this.id);
|
||||||
}
|
}
|
||||||
|
@ -42,9 +42,9 @@ import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
|
||||||
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
import me.lucko.luckperms.sponge.service.persisted.PersistedCollection;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorage;
|
import me.lucko.luckperms.sponge.service.storage.SubjectStorage;
|
||||||
|
|
||||||
import org.spongepowered.api.plugin.PluginContainer;
|
import org.spongepowered.api.plugin.PluginContainer;
|
||||||
@ -211,8 +211,8 @@ public class LuckPermsService implements LPPermissionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<SubjectReference> sortSubjects(Collection<SubjectReference> s) {
|
public ImmutableList<LPSubjectReference> sortSubjects(Collection<LPSubjectReference> s) {
|
||||||
List<SubjectReference> ret = new ArrayList<>(s);
|
List<LPSubjectReference> ret = new ArrayList<>(s);
|
||||||
ret.sort(Collections.reverseOrder((o1, o2) -> {
|
ret.sort(Collections.reverseOrder((o1, o2) -> {
|
||||||
if (o1.equals(o2)) {
|
if (o1.equals(o2)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -40,7 +40,7 @@ import me.lucko.luckperms.common.model.User;
|
|||||||
import me.lucko.luckperms.common.node.NodeFactory;
|
import me.lucko.luckperms.common.node.NodeFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.PermissionService;
|
import org.spongepowered.api.service.permission.PermissionService;
|
||||||
|
|
||||||
@ -178,11 +178,11 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableMap<ImmutableContextSet, ImmutableList<SubjectReference>> getAllParents() {
|
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
|
||||||
Map<ImmutableContextSet, ImmutableList.Builder<SubjectReference>> parents = new HashMap<>();
|
Map<ImmutableContextSet, ImmutableList.Builder<LPSubjectReference>> parents = new HashMap<>();
|
||||||
|
|
||||||
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (this.enduring ? this.holder.getEnduringNodes() : this.holder.getTransientNodes()).asMap().entrySet()) {
|
for (Map.Entry<ImmutableContextSet, Collection<Node>> e : (this.enduring ? this.holder.getEnduringNodes() : this.holder.getTransientNodes()).asMap().entrySet()) {
|
||||||
ImmutableList.Builder<SubjectReference> results = ImmutableList.builder();
|
ImmutableList.Builder<LPSubjectReference> results = ImmutableList.builder();
|
||||||
for (Node n : e.getValue()) {
|
for (Node n : e.getValue()) {
|
||||||
if (n.isGroupNode()) {
|
if (n.isGroupNode()) {
|
||||||
results.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
|
results.add(this.service.getGroupSubjects().loadSubject(n.getGroupName()).join().toReference());
|
||||||
@ -191,15 +191,15 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
parents.put(e.getKey(), results);
|
parents.put(e.getKey(), results);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<SubjectReference>> map = ImmutableMap.builder();
|
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> map = ImmutableMap.builder();
|
||||||
for (Map.Entry<ImmutableContextSet, ImmutableList.Builder<SubjectReference>> e : parents.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, ImmutableList.Builder<LPSubjectReference>> e : parents.entrySet()) {
|
||||||
map.put(e.getKey(), e.getValue().build());
|
map.put(e.getKey(), e.getValue().build());
|
||||||
}
|
}
|
||||||
return map.build();
|
return map.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference subject) {
|
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, LPSubjectReference subject) {
|
||||||
Objects.requireNonNull(contexts, "contexts");
|
Objects.requireNonNull(contexts, "contexts");
|
||||||
Objects.requireNonNull(subject, "subject");
|
Objects.requireNonNull(subject, "subject");
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ public class LuckPermsSubjectData implements LPSubjectData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference subject) {
|
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, LPSubjectReference subject) {
|
||||||
Objects.requireNonNull(contexts, "contexts");
|
Objects.requireNonNull(contexts, "contexts");
|
||||||
Objects.requireNonNull(subject, "subject");
|
Objects.requireNonNull(subject, "subject");
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ import me.lucko.luckperms.sponge.processors.SpongeWildcardProcessor;
|
|||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -70,7 +70,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
private final String calculatorDisplayName;
|
private final String calculatorDisplayName;
|
||||||
|
|
||||||
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
||||||
private final Map<ImmutableContextSet, Set<SubjectReference>> parents = new ConcurrentHashMap<>();
|
private final Map<ImmutableContextSet, Set<LPSubjectReference>> parents = new ConcurrentHashMap<>();
|
||||||
private final Map<ImmutableContextSet, Map<String, String>> options = new ConcurrentHashMap<>();
|
private final Map<ImmutableContextSet, Map<String, String>> options = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final LoadingCache<ImmutableContextSet, CalculatorHolder> permissionCache = Caffeine.newBuilder()
|
private final LoadingCache<ImmutableContextSet, CalculatorHolder> permissionCache = Caffeine.newBuilder()
|
||||||
@ -121,10 +121,10 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
this.service.invalidateAllCaches(LPSubject.CacheLevel.PERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replaceParents(Map<ImmutableContextSet, List<SubjectReference>> map) {
|
public void replaceParents(Map<ImmutableContextSet, List<LPSubjectReference>> map) {
|
||||||
this.parents.clear();
|
this.parents.clear();
|
||||||
for (Map.Entry<ImmutableContextSet, List<SubjectReference>> e : map.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, List<LPSubjectReference>> e : map.entrySet()) {
|
||||||
Set<SubjectReference> set = ConcurrentHashMap.newKeySet();
|
Set<LPSubjectReference> set = ConcurrentHashMap.newKeySet();
|
||||||
set.addAll(e.getValue());
|
set.addAll(e.getValue());
|
||||||
this.parents.put(e.getKey(), set);
|
this.parents.put(e.getKey(), set);
|
||||||
}
|
}
|
||||||
@ -194,17 +194,17 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableMap<ImmutableContextSet, ImmutableList<SubjectReference>> getAllParents() {
|
public ImmutableMap<ImmutableContextSet, ImmutableList<LPSubjectReference>> getAllParents() {
|
||||||
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<SubjectReference>> map = ImmutableMap.builder();
|
ImmutableMap.Builder<ImmutableContextSet, ImmutableList<LPSubjectReference>> map = ImmutableMap.builder();
|
||||||
for (Map.Entry<ImmutableContextSet, Set<SubjectReference>> e : this.parents.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, Set<LPSubjectReference>> e : this.parents.entrySet()) {
|
||||||
map.put(e.getKey(), this.service.sortSubjects(e.getValue()));
|
map.put(e.getKey(), this.service.sortSubjects(e.getValue()));
|
||||||
}
|
}
|
||||||
return map.build();
|
return map.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference parent) {
|
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
Set<SubjectReference> set = this.parents.computeIfAbsent(contexts, c -> ConcurrentHashMap.newKeySet());
|
Set<LPSubjectReference> set = this.parents.computeIfAbsent(contexts, c -> ConcurrentHashMap.newKeySet());
|
||||||
boolean b = set.add(parent);
|
boolean b = set.add(parent);
|
||||||
if (b) {
|
if (b) {
|
||||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||||
@ -213,8 +213,8 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference parent) {
|
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
Set<SubjectReference> set = this.parents.get(contexts);
|
Set<LPSubjectReference> set = this.parents.get(contexts);
|
||||||
boolean b = set != null && set.remove(parent);
|
boolean b = set != null && set.remove(parent);
|
||||||
if (b) {
|
if (b) {
|
||||||
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
this.service.invalidateAllCaches(LPSubject.CacheLevel.PARENT);
|
||||||
@ -235,7 +235,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) {
|
public CompletableFuture<Boolean> clearParents(ImmutableContextSet contexts) {
|
||||||
Set<SubjectReference> set = this.parents.get(contexts);
|
Set<LPSubjectReference> set = this.parents.get(contexts);
|
||||||
if (set == null) {
|
if (set == null) {
|
||||||
return CompletableFuture.completedFuture(false);
|
return CompletableFuture.completedFuture(false);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ package me.lucko.luckperms.sponge.service.legacy;
|
|||||||
|
|
||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -40,12 +40,13 @@ import me.lucko.luckperms.sponge.service.LuckPermsService;
|
|||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
import me.lucko.luckperms.sponge.service.model.LPSubjectCollection;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||||
|
|
||||||
import org.spongepowered.api.service.permission.SubjectCollection;
|
import org.spongepowered.api.service.permission.SubjectCollection;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@ -73,7 +74,9 @@ public class PersistedCollection implements LPSubjectCollection {
|
|||||||
Map<String, SubjectStorageModel> holders = this.service.getStorage().loadAllFromFile(this.identifier);
|
Map<String, SubjectStorageModel> holders = this.service.getStorage().loadAllFromFile(this.identifier);
|
||||||
for (Map.Entry<String, SubjectStorageModel> e : holders.entrySet()) {
|
for (Map.Entry<String, SubjectStorageModel> e : holders.entrySet()) {
|
||||||
PersistedSubject subject = this.subjects.get(e.getKey().toLowerCase());
|
PersistedSubject subject = this.subjects.get(e.getKey().toLowerCase());
|
||||||
subject.loadData(e.getValue());
|
if (subject != null) {
|
||||||
|
subject.loadData(e.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +107,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<LPSubject> getSubject(String identifier) {
|
public Optional<LPSubject> getSubject(String identifier) {
|
||||||
return Optional.of(this.subjects.get(identifier.toLowerCase()));
|
return Optional.of(Objects.requireNonNull(this.subjects.get(identifier.toLowerCase())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -116,7 +119,7 @@ public class PersistedCollection implements LPSubjectCollection {
|
|||||||
public CompletableFuture<ImmutableCollection<LPSubject>> loadSubjects(Set<String> identifiers) {
|
public CompletableFuture<ImmutableCollection<LPSubject>> loadSubjects(Set<String> identifiers) {
|
||||||
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
|
||||||
for (String id : identifiers) {
|
for (String id : identifiers) {
|
||||||
ret.add(this.subjects.get(id.toLowerCase()));
|
ret.add(Objects.requireNonNull(this.subjects.get(id.toLowerCase())));
|
||||||
}
|
}
|
||||||
return CompletableFuture.completedFuture(ret.build());
|
return CompletableFuture.completedFuture(ret.build());
|
||||||
}
|
}
|
||||||
@ -132,13 +135,13 @@ public class PersistedCollection implements LPSubjectCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(String permission) {
|
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(String permission) {
|
||||||
return CompletableFuture.completedFuture(getLoadedWithPermission(permission).entrySet().stream()
|
return CompletableFuture.completedFuture(getLoadedWithPermission(permission).entrySet().stream()
|
||||||
.collect(ImmutableCollectors.toMap(e -> e.getKey().toReference(), Map.Entry::getValue)));
|
.collect(ImmutableCollectors.toMap(e -> e.getKey().toReference(), Map.Entry::getValue)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<ImmutableMap<SubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission) {
|
public CompletableFuture<ImmutableMap<LPSubjectReference, Boolean>> getAllWithPermission(ImmutableContextSet contexts, String permission) {
|
||||||
return CompletableFuture.completedFuture(getLoadedWithPermission(contexts, permission).entrySet().stream()
|
return CompletableFuture.completedFuture(getLoadedWithPermission(contexts, permission).entrySet().stream()
|
||||||
.collect(ImmutableCollectors.toMap(e -> e.getKey().toReference(), Map.Entry::getValue)));
|
.collect(ImmutableCollectors.toMap(e -> e.getKey().toReference(), Map.Entry::getValue)));
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ import me.lucko.luckperms.sponge.service.LuckPermsService;
|
|||||||
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
import me.lucko.luckperms.sponge.service.ProxyFactory;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
import me.lucko.luckperms.sponge.service.model.LPSubject;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
import me.lucko.luckperms.sponge.service.storage.SubjectStorageModel;
|
||||||
|
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
@ -66,7 +66,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
.expireAfterAccess(20, TimeUnit.MINUTES)
|
.expireAfterAccess(20, TimeUnit.MINUTES)
|
||||||
.build(lookup -> lookupPermissionValue(lookup.getContexts(), lookup.getNode()));
|
.build(lookup -> lookupPermissionValue(lookup.getContexts(), lookup.getNode()));
|
||||||
|
|
||||||
private final LoadingCache<ImmutableContextSet, ImmutableList<SubjectReference>> parentLookupCache = Caffeine.newBuilder()
|
private final LoadingCache<ImmutableContextSet, ImmutableList<LPSubjectReference>> parentLookupCache = Caffeine.newBuilder()
|
||||||
.expireAfterAccess(20, TimeUnit.MINUTES)
|
.expireAfterAccess(20, TimeUnit.MINUTES)
|
||||||
.build(this::lookupParents);
|
.build(this::lookupParents);
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SubjectReference parent : getParents(contexts)) {
|
for (LPSubjectReference parent : getParents(contexts)) {
|
||||||
res = parent.resolveLp().join().getPermissionValue(contexts, node);
|
res = parent.resolveLp().join().getPermissionValue(contexts, node);
|
||||||
if (res != Tristate.UNDEFINED) {
|
if (res != Tristate.UNDEFINED) {
|
||||||
return res;
|
return res;
|
||||||
@ -214,8 +214,8 @@ public class PersistedSubject implements LPSubject {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableList<SubjectReference> lookupParents(ImmutableContextSet contexts) {
|
private ImmutableList<LPSubjectReference> lookupParents(ImmutableContextSet contexts) {
|
||||||
List<SubjectReference> s = new ArrayList<>();
|
List<LPSubjectReference> s = new ArrayList<>();
|
||||||
s.addAll(this.subjectData.getParents(contexts));
|
s.addAll(this.subjectData.getParents(contexts));
|
||||||
s.addAll(this.transientSubjectData.getParents(contexts));
|
s.addAll(this.transientSubjectData.getParents(contexts));
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (SubjectReference parent : getParents(contexts)) {
|
for (LPSubjectReference parent : getParents(contexts)) {
|
||||||
res = parent.resolveLp().join().getOption(contexts, key);
|
res = parent.resolveLp().join().getOption(contexts, key);
|
||||||
if (res.isPresent()) {
|
if (res.isPresent()) {
|
||||||
return res;
|
return res;
|
||||||
@ -283,7 +283,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(ImmutableContextSet contexts, SubjectReference subject) {
|
public boolean isChildOf(ImmutableContextSet contexts, LPSubjectReference subject) {
|
||||||
Objects.requireNonNull(contexts, "contexts");
|
Objects.requireNonNull(contexts, "contexts");
|
||||||
Objects.requireNonNull(subject, "subject");
|
Objects.requireNonNull(subject, "subject");
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ImmutableList<SubjectReference> getParents(ImmutableContextSet contexts) {
|
public ImmutableList<LPSubjectReference> getParents(ImmutableContextSet contexts) {
|
||||||
Objects.requireNonNull(contexts, "contexts");
|
Objects.requireNonNull(contexts, "contexts");
|
||||||
return this.parentLookupCache.get(contexts);
|
return this.parentLookupCache.get(contexts);
|
||||||
}
|
}
|
||||||
@ -308,9 +308,4 @@ public class PersistedSubject implements LPSubject {
|
|||||||
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
|
public Optional<String> getOption(ImmutableContextSet contexts, String key) {
|
||||||
return this.optionLookupCache.get(OptionLookupKey.of(key, contexts));
|
return this.optionLookupCache.get(OptionLookupKey.of(key, contexts));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ImmutableContextSet getActiveContextSet() {
|
|
||||||
return this.service.getPlugin().getContextManager().getApplicableContext(sponge());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import me.lucko.luckperms.api.Tristate;
|
|||||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -79,12 +79,12 @@ public class PersistedSubjectData extends CalculatedSubjectData implements Funct
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, SubjectReference parent) {
|
public CompletableFuture<Boolean> addParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
return super.addParent(contexts, parent).thenApply(this);
|
return super.addParent(contexts, parent).thenApply(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, SubjectReference parent) {
|
public CompletableFuture<Boolean> removeParent(ImmutableContextSet contexts, LPSubjectReference parent) {
|
||||||
return super.removeParent(contexts, parent).thenApply(this);
|
return super.removeParent(contexts, parent).thenApply(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ import me.lucko.luckperms.common.contexts.ContextSetJsonSerializer;
|
|||||||
import me.lucko.luckperms.common.utils.CollationKeyCache;
|
import me.lucko.luckperms.common.utils.CollationKeyCache;
|
||||||
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
import me.lucko.luckperms.sponge.service.calculated.CalculatedSubjectData;
|
||||||
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
import me.lucko.luckperms.sponge.service.model.LPPermissionService;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReference;
|
import me.lucko.luckperms.sponge.service.reference.LPSubjectReference;
|
||||||
import me.lucko.luckperms.sponge.service.model.SubjectReferenceFactory;
|
import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -52,9 +52,9 @@ public class SubjectStorageModel {
|
|||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions;
|
private final Map<ImmutableContextSet, Map<String, Boolean>> permissions;
|
||||||
private final Map<ImmutableContextSet, Map<String, String>> options;
|
private final Map<ImmutableContextSet, Map<String, String>> options;
|
||||||
private final Map<ImmutableContextSet, List<SubjectReference>> parents;
|
private final Map<ImmutableContextSet, List<LPSubjectReference>> parents;
|
||||||
|
|
||||||
public SubjectStorageModel(LPPermissionService service, Map<ImmutableContextSet, ? extends Map<String, Boolean>> permissions, Map<ImmutableContextSet, ? extends Map<String, String>> options, Map<ImmutableContextSet, ? extends List<SubjectReference>> parents) {
|
public SubjectStorageModel(LPPermissionService service, Map<ImmutableContextSet, ? extends Map<String, Boolean>> permissions, Map<ImmutableContextSet, ? extends Map<String, String>> options, Map<ImmutableContextSet, ? extends List<LPSubjectReference>> parents) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
|
|
||||||
ImmutableMap.Builder<ImmutableContextSet, Map<String, Boolean>> permissionsBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<ImmutableContextSet, Map<String, Boolean>> permissionsBuilder = ImmutableMap.builder();
|
||||||
@ -69,8 +69,8 @@ public class SubjectStorageModel {
|
|||||||
}
|
}
|
||||||
this.options = optionsBuilder.build();
|
this.options = optionsBuilder.build();
|
||||||
|
|
||||||
ImmutableMap.Builder<ImmutableContextSet, List<SubjectReference>> parentsBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<ImmutableContextSet, List<LPSubjectReference>> parentsBuilder = ImmutableMap.builder();
|
||||||
for (Map.Entry<ImmutableContextSet, ? extends List<SubjectReference>> e : parents.entrySet()) {
|
for (Map.Entry<ImmutableContextSet, ? extends List<LPSubjectReference>> e : parents.entrySet()) {
|
||||||
parentsBuilder.put(e.getKey(), ImmutableList.copyOf(e.getValue()));
|
parentsBuilder.put(e.getKey(), ImmutableList.copyOf(e.getValue()));
|
||||||
}
|
}
|
||||||
this.parents = parentsBuilder.build();
|
this.parents = parentsBuilder.build();
|
||||||
@ -137,7 +137,7 @@ public class SubjectStorageModel {
|
|||||||
}
|
}
|
||||||
this.options = optionsBuilder.build();
|
this.options = optionsBuilder.build();
|
||||||
|
|
||||||
ImmutableMap.Builder<ImmutableContextSet, List<SubjectReference>> parentsBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<ImmutableContextSet, List<LPSubjectReference>> parentsBuilder = ImmutableMap.builder();
|
||||||
for (JsonElement e : parents) {
|
for (JsonElement e : parents) {
|
||||||
if (!e.isJsonObject()) {
|
if (!e.isJsonObject()) {
|
||||||
continue;
|
continue;
|
||||||
@ -151,7 +151,7 @@ public class SubjectStorageModel {
|
|||||||
JsonArray data = section.get("data").getAsJsonArray();
|
JsonArray data = section.get("data").getAsJsonArray();
|
||||||
|
|
||||||
ImmutableContextSet contextSet = ContextSetJsonSerializer.deserializeContextSet(context).makeImmutable();
|
ImmutableContextSet contextSet = ContextSetJsonSerializer.deserializeContextSet(context).makeImmutable();
|
||||||
ImmutableList.Builder<SubjectReference> pars = ImmutableList.builder();
|
ImmutableList.Builder<LPSubjectReference> pars = ImmutableList.builder();
|
||||||
for (JsonElement p : data) {
|
for (JsonElement p : data) {
|
||||||
if (!p.isJsonObject()) {
|
if (!p.isJsonObject()) {
|
||||||
continue;
|
continue;
|
||||||
@ -228,7 +228,7 @@ public class SubjectStorageModel {
|
|||||||
root.add("options", options);
|
root.add("options", options);
|
||||||
|
|
||||||
JsonArray parents = new JsonArray();
|
JsonArray parents = new JsonArray();
|
||||||
for (Map.Entry<ImmutableContextSet, List<SubjectReference>> e : sortContextMap(this.parents)) {
|
for (Map.Entry<ImmutableContextSet, List<LPSubjectReference>> e : sortContextMap(this.parents)) {
|
||||||
if (e.getValue().isEmpty()) {
|
if (e.getValue().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ public class SubjectStorageModel {
|
|||||||
section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
|
section.add("context", ContextSetJsonSerializer.serializeContextSet(e.getKey()));
|
||||||
|
|
||||||
JsonArray data = new JsonArray();
|
JsonArray data = new JsonArray();
|
||||||
for (SubjectReference ref : e.getValue()) {
|
for (LPSubjectReference ref : e.getValue()) {
|
||||||
JsonObject parent = new JsonObject();
|
JsonObject parent = new JsonObject();
|
||||||
parent.addProperty("collection", ref.getCollectionIdentifier());
|
parent.addProperty("collection", ref.getCollectionIdentifier());
|
||||||
parent.addProperty("subject", ref.getCollectionIdentifier());
|
parent.addProperty("subject", ref.getCollectionIdentifier());
|
||||||
|
Loading…
Reference in New Issue
Block a user