mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-28 05:35:26 +01:00
Cleanup migration commands
This commit is contained in:
parent
11465a4ce9
commit
dbc909a317
@ -72,7 +72,7 @@ public final class ImmutableContextSet implements ContextSet {
|
||||
|
||||
ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder();
|
||||
for (Map.Entry<String, String> e : map.entrySet()) {
|
||||
b.put(e.getKey(), e.getValue());
|
||||
b.put(e.getKey().toLowerCase(), e.getValue());
|
||||
}
|
||||
|
||||
return new ImmutableContextSet(b.build());
|
||||
|
@ -284,7 +284,7 @@ public final class MutableContextSet implements ContextSet {
|
||||
*/
|
||||
public void addAll(Iterable<? extends Map.Entry<String, String>> iterable) {
|
||||
if (iterable == null) {
|
||||
throw new NullPointerException("contexts");
|
||||
throw new NullPointerException("iterable");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> e : iterable) {
|
||||
@ -300,7 +300,7 @@ public final class MutableContextSet implements ContextSet {
|
||||
*/
|
||||
public void addAll(Map<String, String> map) {
|
||||
if (map == null) {
|
||||
throw new NullPointerException("contexts");
|
||||
throw new NullPointerException("map");
|
||||
}
|
||||
addAll(map.entrySet());
|
||||
}
|
||||
@ -334,7 +334,7 @@ public final class MutableContextSet implements ContextSet {
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
|
||||
map.entries().removeIf(entry -> entry.getKey().equalsIgnoreCase(key) && entry.getValue().equals(value));
|
||||
map.entries().removeIf(entry -> entry.getKey().equals(key) && entry.getValue().equals(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,12 +29,13 @@ import de.bananaco.bpermissions.api.Permission;
|
||||
import de.bananaco.bpermissions.api.World;
|
||||
import de.bananaco.bpermissions.api.WorldManager;
|
||||
|
||||
import me.lucko.luckperms.api.MetaUtils;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
@ -42,10 +43,10 @@ import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -56,9 +57,6 @@ import static me.lucko.luckperms.common.constants.Permission.MIGRATION;
|
||||
|
||||
public class MigrationBPermissions extends SubCommand<Object> {
|
||||
private static Field uConfigField;
|
||||
private static Method getConfigurationSectionMethod = null;
|
||||
private static Method getKeysMethod = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
uConfigField = Class.forName("de.bananaco.bpermissions.imp.YamlWorld").getDeclaredField("uconfig");
|
||||
@ -89,7 +87,24 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
log.log("Forcing the plugin to load all data. This could take a while.");
|
||||
for (World world : worldManager.getAllWorlds()) {
|
||||
log.log("Loading users in world " + world.getName());
|
||||
Set<String> users = getUsers(world);
|
||||
|
||||
YamlConfiguration yamlWorldUsers = null;
|
||||
try {
|
||||
yamlWorldUsers = (YamlConfiguration) uConfigField.get(world);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
|
||||
if (yamlWorldUsers == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ConfigurationSection configSection = yamlWorldUsers.getConfigurationSection("users");
|
||||
if (configSection == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Set<String> users = configSection.getKeys(false);
|
||||
if (users == null) {
|
||||
log.logErr("Couldn't get a list of users.");
|
||||
return CommandResult.FAILURE;
|
||||
@ -111,7 +126,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
log.log("Starting group migration in world " + world.getName() + ".");
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (Calculable group : world.getAll(CalculableType.GROUP)) {
|
||||
String groupName = group.getName().toLowerCase();
|
||||
String groupName = MigrationUtils.standardizeName(group.getName());
|
||||
if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) {
|
||||
groupName = "default";
|
||||
}
|
||||
@ -120,13 +135,16 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||
me.lucko.luckperms.common.core.model.Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
|
||||
migrateHolder(log, world, group, lpGroup);
|
||||
MigrationUtils.setGroupWeight(lpGroup, group.getPriority());
|
||||
migrateHolder(world, group, lpGroup);
|
||||
|
||||
plugin.getStorage().saveGroup(lpGroup);
|
||||
|
||||
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
|
||||
}
|
||||
log.log("Migrated " + groupCount.get() + " groups in world " + world.getName() + ".");
|
||||
|
||||
|
||||
// Migrate all users
|
||||
log.log("Starting user migration in world " + world.getName() + ".");
|
||||
AtomicInteger userCount = new AtomicInteger(0);
|
||||
@ -153,7 +171,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
plugin.getStorage().loadUser(uuid, "null").join();
|
||||
User lpUser = plugin.getUserManager().get(uuid);
|
||||
|
||||
migrateHolder(log, world, user, lpUser);
|
||||
migrateHolder(world, user, lpUser);
|
||||
|
||||
plugin.getStorage().saveUser(lpUser);
|
||||
plugin.getUserManager().cleanup(lpUser);
|
||||
@ -168,78 +186,35 @@ public class MigrationBPermissions extends SubCommand<Object> {
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Set<String> getUsers(World world) {
|
||||
try {
|
||||
Object yamlWorldUsers = uConfigField.get(world);
|
||||
if (getConfigurationSectionMethod == null) {
|
||||
getConfigurationSectionMethod = yamlWorldUsers.getClass().getMethod("getConfigurationSection", String.class);
|
||||
getConfigurationSectionMethod.setAccessible(true);
|
||||
}
|
||||
|
||||
Object configSection = getConfigurationSectionMethod.invoke(yamlWorldUsers, "users");
|
||||
if (configSection == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
if (getKeysMethod == null) {
|
||||
getKeysMethod = configSection.getClass().getMethod("getKeys", boolean.class);
|
||||
getKeysMethod.setAccessible(true);
|
||||
}
|
||||
|
||||
return (Set<String>) getKeysMethod.invoke(configSection, false);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void migrateHolder(ProgressLogger log, World world, Calculable c, PermissionHolder holder) {
|
||||
private static void migrateHolder(World world, Calculable c, PermissionHolder holder) {
|
||||
// Migrate the groups permissions in this world
|
||||
for (Permission p : c.getPermissions()) {
|
||||
try {
|
||||
holder.setPermission(p.name(), p.isTrue(), "global", world.getName());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
holder.setPermissionUnchecked(NodeFactory.make(p.name(), p.isTrue(), "global", world.getName()));
|
||||
|
||||
// Include any child permissions
|
||||
for (Map.Entry<String, Boolean> child : p.getChildren().entrySet()) {
|
||||
try {
|
||||
holder.setPermission(child.getKey(), child.getValue(), "global", world.getName());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
holder.setPermissionUnchecked(NodeFactory.make(child.getKey(), child.getValue(), "global", world.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate any inherited groups
|
||||
for (Group parent : c.getGroups()) {
|
||||
try {
|
||||
holder.setPermission("group." + parent.getName(), true, "global", world.getName());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
String parentName = MigrationUtils.standardizeName(parent.getName());
|
||||
if (parent.getName().equalsIgnoreCase(world.getDefaultGroup())) {
|
||||
parentName = "default";
|
||||
}
|
||||
|
||||
holder.setPermissionUnchecked(NodeFactory.make("group." + parentName, true, "global", world.getName()));
|
||||
}
|
||||
|
||||
// Migrate existing meta
|
||||
for (Map.Entry<String, String> meta : c.getMeta().entrySet()) {
|
||||
if (meta.getKey().equalsIgnoreCase("prefix") || meta.getKey().equalsIgnoreCase("suffix")) {
|
||||
String chatMeta = MetaUtils.escapeCharacters(meta.getValue());
|
||||
try {
|
||||
holder.setPermission(meta.getKey().toLowerCase() + "." + c.getPriority() + "." + chatMeta, true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
holder.setPermissionUnchecked(NodeFactory.makeChatMetaNode(meta.getKey().equalsIgnoreCase("prefix"), c.getPriority(), meta.getValue()).setWorld(world.getName()).build());
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
holder.setPermission("meta." + meta.getKey() + "." + meta.getValue(), true, "global", world.getName());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
holder.setPermissionUnchecked(NodeFactory.makeMetaNode(meta.getKey(), meta.getValue()).setWorld(world.getName()).build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,20 +22,19 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.Arg;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import org.anjocaido.groupmanager.GlobalGroups;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
@ -47,17 +46,16 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MigrationGroupManager extends SubCommand<Object> {
|
||||
// group manager global groups contain the ":" character, which is not allowed in windows file names
|
||||
private static final Function<String, String> GROUP_RENAME_FUNCTION = s -> s.replace(':', '-').toLowerCase();
|
||||
|
||||
public MigrationGroupManager() {
|
||||
super("groupmanager", "Migration from GroupManager", Permission.MIGRATION, Predicates.is(0),
|
||||
Arg.list(Arg.create("migrate as global", true, "if world permissions should be ignored, and just migrated as global"))
|
||||
@ -76,8 +74,8 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
log.logErr("Was expecting true/false, but got " + args.get(0) + " instead.");
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0));
|
||||
final Function<String, String> worldMappingFunc = s -> migrateAsGlobal ? "" : s;
|
||||
final boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0));
|
||||
final Function<String, String> worldMappingFunc = s -> migrateAsGlobal ? null : s;
|
||||
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("GroupManager")) {
|
||||
log.logErr("Plugin not loaded.");
|
||||
@ -85,7 +83,6 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
List<String> worlds = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
|
||||
GroupManager gm = (GroupManager) Bukkit.getPluginManager().getPlugin("GroupManager");
|
||||
|
||||
// Migrate Global Groups
|
||||
@ -94,34 +91,17 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
|
||||
AtomicInteger globalGroupCount = new AtomicInteger(0);
|
||||
for (Group g : gg.getGroupList()) {
|
||||
String name = GROUP_RENAME_FUNCTION.apply(g.getName());
|
||||
String groupName = MigrationUtils.standardizeName(g.getName());
|
||||
|
||||
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
|
||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(name);
|
||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
|
||||
for (String node : g.getPermissionList()) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!") || node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
} else if (node.startsWith("+")) {
|
||||
node = node.substring(1);
|
||||
value = true;
|
||||
}
|
||||
|
||||
try {
|
||||
group.setPermission(node, value);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
group.setPermissionUnchecked(MigrationUtils.parseNode(node, true).build());
|
||||
}
|
||||
|
||||
for (String s : g.getInherits()) {
|
||||
try {
|
||||
group.setPermission("group." + GROUP_RENAME_FUNCTION.apply(s), true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
group.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(s)));
|
||||
}
|
||||
|
||||
plugin.getStorage().saveGroup(group);
|
||||
@ -130,14 +110,9 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
log.log("Migrated " + globalGroupCount.get() + " global groups");
|
||||
|
||||
// Collect data
|
||||
|
||||
// UUID --> Map<Entry<String, String>, Boolean> where k=world, v = node
|
||||
Map<UUID, Map<Map.Entry<String, String>, Boolean>> users = new HashMap<>();
|
||||
// UUID --> primary group name
|
||||
Map<UUID, Set<Node>> users = new HashMap<>();
|
||||
Map<UUID, String> primaryGroups = new HashMap<>();
|
||||
|
||||
// String --> Map<Entry<String, String>, Boolean> where k=world, v = node
|
||||
Map<String, Map<Map.Entry<String, String>, Boolean>> groups = new HashMap<>();
|
||||
Map<String, Set<Node>> groups = new HashMap<>();
|
||||
|
||||
WorldsHolder wh = gm.getWorldsHolder();
|
||||
|
||||
@ -150,27 +125,36 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
WorldDataHolder wdh = wh.getWorldData(world);
|
||||
|
||||
AtomicInteger groupWorldCount = new AtomicInteger(0);
|
||||
for (Group g : wdh.getGroupList()) {
|
||||
String name = GROUP_RENAME_FUNCTION.apply(g.getName());
|
||||
for (Group group : wdh.getGroupList()) {
|
||||
String groupName = MigrationUtils.standardizeName(group.getName());
|
||||
|
||||
groups.putIfAbsent(name, new HashMap<>());
|
||||
groups.putIfAbsent(groupName, new HashSet<>());
|
||||
|
||||
for (String node : g.getPermissionList()) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!") || node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
} else if (node.startsWith("+")) {
|
||||
node = node.substring(1);
|
||||
value = true;
|
||||
for (String node : group.getPermissionList()) {
|
||||
groups.get(groupName).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
|
||||
}
|
||||
|
||||
for (String s : group.getInherits()) {
|
||||
groups.get(groupName).add(NodeFactory.make("group." + MigrationUtils.standardizeName(s), true, null, worldMappingFunc.apply(world)));
|
||||
}
|
||||
|
||||
|
||||
String[] metaKeys = group.getVariables().getVarKeyList();
|
||||
for (String key : metaKeys) {
|
||||
String value = group.getVariables().getVarString(key);
|
||||
key = key.toLowerCase();
|
||||
|
||||
if (key.equals("build")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
groups.get(name).put(Maps.immutableEntry(worldMappingFunc.apply(world), node), value);
|
||||
if (key.equals("prefix") || key.equals("suffix")) {
|
||||
groups.get(groupName).add(NodeFactory.makeChatMetaNode(key.equals("prefix"), 50, value).setWorld(worldMappingFunc.apply(world)).build());
|
||||
} else {
|
||||
groups.get(groupName).add(NodeFactory.makeMetaNode(key, value).setWorld(worldMappingFunc.apply(world)).build());
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : g.getInherits()) {
|
||||
groups.get(name).put(Maps.immutableEntry(worldMappingFunc.apply(world), "group." + GROUP_RENAME_FUNCTION.apply(s)), true);
|
||||
}
|
||||
log.logAllProgress("Migrated {} groups so far in world " + world, groupWorldCount.incrementAndGet());
|
||||
}
|
||||
log.log("Migrated " + groupWorldCount.get() + " groups in world " + world);
|
||||
@ -185,35 +169,42 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
continue;
|
||||
}
|
||||
|
||||
users.putIfAbsent(uuid, new HashMap<>());
|
||||
users.putIfAbsent(uuid, new HashSet<>());
|
||||
|
||||
for (String node : user.getPermissionList()) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("!") || node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
} else if (node.startsWith("+")) {
|
||||
node = node.substring(1);
|
||||
value = true;
|
||||
}
|
||||
|
||||
users.get(uuid).put(Maps.immutableEntry(worldMappingFunc.apply(world), node), value);
|
||||
users.get(uuid).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
|
||||
}
|
||||
|
||||
String finalWorld = worldMappingFunc.apply(world);
|
||||
|
||||
// Collect sub groups
|
||||
users.get(uuid).putAll(user.subGroupListStringCopy().stream()
|
||||
.map(n -> "group." + GROUP_RENAME_FUNCTION.apply(n))
|
||||
.map(n -> Maps.immutableEntry(finalWorld, n))
|
||||
.collect(Collectors.toMap(n -> n, n -> true))
|
||||
String finalWorld = worldMappingFunc.apply(world);
|
||||
users.get(uuid).addAll(user.subGroupListStringCopy().stream()
|
||||
.map(n -> "group." + MigrationUtils.standardizeName(n))
|
||||
.map(n -> NodeFactory.make(n, true, null, finalWorld))
|
||||
.collect(Collectors.toSet())
|
||||
);
|
||||
primaryGroups.put(uuid, GROUP_RENAME_FUNCTION.apply(user.getGroupName()));
|
||||
|
||||
// Get primary group
|
||||
primaryGroups.put(uuid, MigrationUtils.standardizeName(user.getGroupName()));
|
||||
|
||||
String[] metaKeys = user.getVariables().getVarKeyList();
|
||||
for (String key : metaKeys) {
|
||||
String value = user.getVariables().getVarString(key);
|
||||
key = key.toLowerCase();
|
||||
|
||||
if (key.equals("build")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key.equals("prefix") || key.equals("suffix")) {
|
||||
users.get(uuid).add(NodeFactory.makeChatMetaNode(key.equals("prefix"), 100, value).setWorld(worldMappingFunc.apply(world)).build());
|
||||
} else {
|
||||
users.get(uuid).add(NodeFactory.makeMetaNode(key, value).setWorld(worldMappingFunc.apply(world)).build());
|
||||
}
|
||||
}
|
||||
|
||||
log.logProgress("Migrated {} users so far in world " + world, userWorldCount.incrementAndGet());
|
||||
}
|
||||
log.log("Migrated " + userWorldCount.get() + " users in world " + world);
|
||||
|
||||
}
|
||||
|
||||
log.log("All data has now been processed, now starting the import process.");
|
||||
@ -221,23 +212,12 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
|
||||
log.log("Starting group migration.");
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (Map.Entry<String, Map<Map.Entry<String, String>, Boolean>> e : groups.entrySet()) {
|
||||
for (Map.Entry<String, Set<Node>> e : groups.entrySet()) {
|
||||
plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
|
||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(e.getKey());
|
||||
|
||||
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
||||
// n.key.key = world
|
||||
// n.key.value = node
|
||||
// n.value = true/false
|
||||
try {
|
||||
if (n.getKey().getKey().equals("")) {
|
||||
group.setPermission(n.getKey().getValue(), n.getValue());
|
||||
} else {
|
||||
group.setPermission(n.getKey().getValue(), n.getValue(), "global", n.getKey().getKey());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
for (Node node : e.getValue()) {
|
||||
group.setPermissionUnchecked(node);
|
||||
}
|
||||
|
||||
plugin.getStorage().saveGroup(group);
|
||||
@ -247,34 +227,19 @@ public class MigrationGroupManager extends SubCommand<Object> {
|
||||
|
||||
log.log("Starting user migration.");
|
||||
AtomicInteger userCount = new AtomicInteger(0);
|
||||
for (Map.Entry<UUID, Map<Map.Entry<String, String>, Boolean>> e : users.entrySet()) {
|
||||
for (Map.Entry<UUID, Set<Node>> e : users.entrySet()) {
|
||||
plugin.getStorage().loadUser(e.getKey(), "null").join();
|
||||
me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(e.getKey());
|
||||
|
||||
for (Map.Entry<Map.Entry<String, String>, Boolean> n : e.getValue().entrySet()) {
|
||||
// n.key.key = world
|
||||
// n.key.value = node
|
||||
// n.value = true/false
|
||||
try {
|
||||
if (n.getKey().getKey().equals("")) {
|
||||
user.setPermission(n.getKey().getValue(), n.getValue());
|
||||
} else {
|
||||
user.setPermission(n.getKey().getValue(), n.getValue(), "global", n.getKey().getKey());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
for (Node node : e.getValue()) {
|
||||
user.setPermissionUnchecked(node);
|
||||
}
|
||||
|
||||
String primaryGroup = primaryGroups.get(e.getKey());
|
||||
if (primaryGroup != null) {
|
||||
try {
|
||||
user.setPermission("group." + primaryGroup, true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
user.setPermissionUnchecked(NodeFactory.make("group." + primaryGroup));
|
||||
user.setPrimaryGroup(primaryGroup);
|
||||
try {
|
||||
user.unsetPermission("group.default");
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
user.unsetPermissionUnchecked(NodeFactory.make("group.default"));
|
||||
}
|
||||
|
||||
plugin.getStorage().saveUser(user);
|
||||
|
@ -22,11 +22,11 @@
|
||||
|
||||
package me.lucko.luckperms.bukkit.migration;
|
||||
|
||||
import me.lucko.luckperms.api.MetaUtils;
|
||||
import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
@ -35,8 +35,6 @@ import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.exceptions.ObjectLacksException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -100,26 +98,15 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
for (PermissionGroup group : manager.getGroupList()) {
|
||||
int groupWeight = maxWeight - group.getRank();
|
||||
|
||||
final String name = group.getName().toLowerCase();
|
||||
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
|
||||
Group lpGroup = plugin.getGroupManager().getIfLoaded(name);
|
||||
final String groupName = MigrationUtils.standardizeName(group.getName());
|
||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||
Group lpGroup = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
|
||||
lpGroup.removeIf(n -> n.getPermission().startsWith("weight."));
|
||||
lpGroup.setPermissionUnchecked(NodeFactory.make("weight." + groupWeight, true));
|
||||
MigrationUtils.setGroupWeight(lpGroup, groupWeight);
|
||||
|
||||
try {
|
||||
for (String node : group.getOwnPermissions(null)) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
try {
|
||||
lpGroup.setPermission(node, value);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpGroup.setPermissionUnchecked(MigrationUtils.parseNode(node, true).build());
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
// No docs on if #getOwnPermissions(null) is ok. Should be fine though.
|
||||
@ -127,35 +114,17 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
|
||||
for (String world : worlds) {
|
||||
for (String node : group.getOwnPermissions(world)) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
try {
|
||||
lpGroup.setPermission(node, value, "global", world.toLowerCase());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpGroup.setPermissionUnchecked(MigrationUtils.parseNode(node, true).setWorld(world.toLowerCase()).build());
|
||||
}
|
||||
}
|
||||
|
||||
for (PermissionGroup g : group.getParents()) {
|
||||
try {
|
||||
lpGroup.setPermission("group." + g.getName().toLowerCase(), true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpGroup.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(g.getName())));
|
||||
}
|
||||
|
||||
for (String world : worlds) {
|
||||
for (PermissionGroup g : group.getParents(world)) {
|
||||
try {
|
||||
lpGroup.setPermission("group." + g.getName().toLowerCase(), true, "global", world.toLowerCase());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpGroup.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(g.getName()), true, "global", world.toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,21 +132,11 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
String suffix = group.getOwnSuffix();
|
||||
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
prefix = MetaUtils.escapeCharacters(prefix);
|
||||
try {
|
||||
lpGroup.setPermission("prefix." + groupWeight + "." + prefix, true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpGroup.setPermissionUnchecked(NodeFactory.makePrefixNode(groupWeight, prefix).build());
|
||||
}
|
||||
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
suffix = MetaUtils.escapeCharacters(suffix);
|
||||
try {
|
||||
lpGroup.setPermission("suffix." + groupWeight + "." + suffix, true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpGroup.setPermissionUnchecked(NodeFactory.makeSuffixNode(groupWeight, suffix).build());
|
||||
}
|
||||
|
||||
plugin.getStorage().saveGroup(lpGroup);
|
||||
@ -217,17 +176,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
|
||||
try {
|
||||
for (String node : user.getOwnPermissions(null)) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
try {
|
||||
lpUser.setPermission(node, value);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpUser.setPermissionUnchecked(MigrationUtils.parseNode(node, true).build());
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
// No docs on if #getOwnPermissions(null) is ok. Should be fine though.
|
||||
@ -235,35 +184,17 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
|
||||
for (String world : worlds) {
|
||||
for (String node : user.getOwnPermissions(world)) {
|
||||
boolean value = true;
|
||||
if (node.startsWith("-")) {
|
||||
node = node.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
try {
|
||||
lpUser.setPermission(node, value, "global", world.toLowerCase());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpUser.setPermissionUnchecked(MigrationUtils.parseNode(node, true).setWorld(world.toLowerCase()).build());
|
||||
}
|
||||
}
|
||||
|
||||
for (String s : user.getGroupNames()) {
|
||||
try {
|
||||
lpUser.setPermission("group." + s.toLowerCase(), true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
for (String g : user.getGroupNames()) {
|
||||
lpUser.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(g)));
|
||||
}
|
||||
|
||||
for (String world : worlds) {
|
||||
for (String s : user.getGroupNames(world)) {
|
||||
try {
|
||||
lpUser.setPermission("group." + s.toLowerCase(), true, "global", world.toLowerCase());
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
for (String g : user.getGroupNames(world)) {
|
||||
lpUser.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(g), true, "global", world.toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,21 +202,11 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
String suffix = user.getOwnSuffix();
|
||||
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
prefix = MetaUtils.escapeCharacters(prefix);
|
||||
try {
|
||||
lpUser.setPermission("prefix." + maxWeight + "." + prefix, true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpUser.setPermissionUnchecked(NodeFactory.makePrefixNode(maxWeight, prefix).build());
|
||||
}
|
||||
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
suffix = MetaUtils.escapeCharacters(suffix);
|
||||
try {
|
||||
lpUser.setPermission("suffix." + maxWeight + "." + suffix, true);
|
||||
} catch (Exception ex) {
|
||||
log.handleException(ex);
|
||||
}
|
||||
lpUser.setPermissionUnchecked(NodeFactory.makeSuffixNode(maxWeight, suffix).build());
|
||||
}
|
||||
|
||||
// Lowest rank is the highest group #logic
|
||||
@ -299,13 +220,9 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
if (primary != null && !primary.equalsIgnoreCase("default")) {
|
||||
try {
|
||||
lpUser.setPermission("group." + primary.toLowerCase(), true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
lpUser.setPermissionUnchecked(NodeFactory.make("group." + primary.toLowerCase()));
|
||||
lpUser.setPrimaryGroup(primary);
|
||||
try {
|
||||
lpUser.unsetPermission("group.default");
|
||||
} catch (ObjectLacksException ignored) {}
|
||||
lpUser.unsetPermissionUnchecked(NodeFactory.make("group.default"));
|
||||
}
|
||||
|
||||
plugin.getUserManager().cleanup(lpUser);
|
||||
|
@ -36,6 +36,7 @@ import me.lucko.luckperms.common.commands.Arg;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
@ -88,7 +89,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
log.log("Starting.");
|
||||
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("PowerfulPerms")) {
|
||||
log.logErr("PowerfulPerms is not loaded.");
|
||||
log.logErr("Plugin not loaded.");
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
@ -168,12 +169,11 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
for (Group g : groups) {
|
||||
maxWeight = Math.max(maxWeight, g.getRank());
|
||||
|
||||
final String name = g.getName().toLowerCase();
|
||||
plugin.getStorage().createAndLoadGroup(name, CreationCause.INTERNAL).join();
|
||||
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(name);
|
||||
final String groupName = MigrationUtils.standardizeName(g.getName());
|
||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||
final me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
|
||||
group.removeIf(n -> n.getPermission().startsWith("weight."));
|
||||
group.setPermissionUnchecked(NodeFactory.make("weight." + g.getRank(), true));
|
||||
MigrationUtils.setGroupWeight(group, g.getRank());
|
||||
|
||||
for (Permission p : g.getOwnPermissions()) {
|
||||
applyPerm(group, p);
|
||||
@ -321,7 +321,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
|
||||
|
||||
private void applyGroup(PermissionManager pm, PermissionHolder holder, CachedGroup g, String server) {
|
||||
Group group = pm.getGroup(g.getGroupId());
|
||||
String node = "group." + group.getName();
|
||||
String node = "group." + MigrationUtils.standardizeName(group.getName());
|
||||
|
||||
long expireAt = 0L;
|
||||
if (g.willExpire()) {
|
||||
|
@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
@ -36,7 +37,6 @@ import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.utils.Predicates;
|
||||
import me.lucko.luckperms.common.utils.ProgressLogger;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService;
|
||||
@ -66,12 +66,12 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
log.log("Starting.");
|
||||
|
||||
if (!Bukkit.getPluginManager().isPluginEnabled("zPermissions")) {
|
||||
log.logErr("zPermissions is not loaded.");
|
||||
log.logErr("Plugin not loaded.");
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(ZPermissionsService.class)) {
|
||||
log.logErr("zPermissions is not loaded.");
|
||||
log.logErr("Plugin not loaded.");
|
||||
return CommandResult.STATE_ERROR;
|
||||
}
|
||||
|
||||
@ -91,8 +91,10 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
log.log("Starting group migration.");
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (String g : service.getAllGroups()) {
|
||||
plugin.getStorage().createAndLoadGroup(g.toLowerCase(), CreationCause.INTERNAL).join();
|
||||
Group group = plugin.getGroupManager().getIfLoaded(g.toLowerCase());
|
||||
String groupName = MigrationUtils.standardizeName(g);
|
||||
|
||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||
Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
|
||||
PermissionEntity entity = internalService.getEntity(g, null, true);
|
||||
migrateEntity(group, entity, null);
|
||||
@ -106,10 +108,13 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
log.log("Starting track migration.");
|
||||
AtomicInteger trackCount = new AtomicInteger(0);
|
||||
for (String t : service.getAllTracks()) {
|
||||
plugin.getStorage().createAndLoadTrack(t.toLowerCase(), CreationCause.INTERNAL).join();
|
||||
Track track = plugin.getTrackManager().getIfLoaded(t.toLowerCase());
|
||||
String trackName = MigrationUtils.standardizeName(t);
|
||||
|
||||
plugin.getStorage().createAndLoadTrack(trackName, CreationCause.INTERNAL).join();
|
||||
Track track = plugin.getTrackManager().getIfLoaded(trackName);
|
||||
track.setGroups(service.getTrackGroups(t));
|
||||
plugin.getStorage().saveTrack(track);
|
||||
|
||||
log.logAllProgress("Migrated {} tracks so far.", trackCount.incrementAndGet());
|
||||
}
|
||||
log.log("Migrated " + trackCount.get() + " tracks");
|
||||
@ -118,18 +123,17 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
log.log("Starting user migration.");
|
||||
AtomicInteger userCount = new AtomicInteger(0);
|
||||
for (UUID u : service.getAllPlayersUUID()) {
|
||||
plugin.getStorage().loadUser(u, "null").join();
|
||||
User user = plugin.getUserManager().get(u);
|
||||
|
||||
PermissionEntity entity = internalService.getEntity(null, u, false);
|
||||
migrateEntity(user, entity, internalService.getGroups(u));
|
||||
|
||||
user.setPrimaryGroup(service.getPlayerPrimaryGroup(u));
|
||||
|
||||
String username = null;
|
||||
if (!entity.isGroup()) {
|
||||
user.setName(entity.getDisplayName());
|
||||
username = entity.getDisplayName();
|
||||
}
|
||||
|
||||
plugin.getStorage().loadUser(u, username).join();
|
||||
User user = plugin.getUserManager().get(u);
|
||||
migrateEntity(user, entity, internalService.getGroups(u));
|
||||
user.setPrimaryGroup(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u)));
|
||||
|
||||
plugin.getUserManager().cleanup(user);
|
||||
plugin.getStorage().saveUser(user);
|
||||
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
|
||||
@ -140,41 +144,36 @@ public class MigrationZPermissions extends SubCommand<Object> {
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
private void migrateEntity(PermissionHolder group, PermissionEntity entity, List<Membership> memberships) {
|
||||
private void migrateEntity(PermissionHolder holder, PermissionEntity entity, List<Membership> memberships) {
|
||||
for (Entry e : entity.getPermissions()) {
|
||||
if (e.getWorld() != null) {
|
||||
try {
|
||||
group.setPermission(e.getPermission(), true, "global", e.getWorld().getName());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
|
||||
holder.setPermissionUnchecked(MigrationUtils.parseNode(e.getPermission(), true).setWorld(e.getWorld().getName()).build());
|
||||
} else {
|
||||
try {
|
||||
group.setPermission(e.getPermission(), true); // TODO handle negated.
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
holder.setPermissionUnchecked(MigrationUtils.parseNode(e.getPermission(), true).build());
|
||||
}
|
||||
}
|
||||
|
||||
if (entity.isGroup()) {
|
||||
// entity.getMemberships() doesn't work for groups (always returns 0 records)
|
||||
for (Inheritance inheritance : entity.getInheritancesAsChild()) {
|
||||
try {
|
||||
if (!inheritance.getParent().getName().equals(group.getObjectName())) {
|
||||
group.setPermission("group." + inheritance.getParent().getName(), true);
|
||||
}
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
if (!inheritance.getParent().getName().equals(holder.getObjectName())) {
|
||||
holder.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(inheritance.getParent().getName())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// entity.getMemberships() doesn't work (always returns 0 records)
|
||||
for (Membership membership : memberships) {
|
||||
try {
|
||||
group.setPermission("group." + membership.getGroup().getDisplayName(), true);
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
holder.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(membership.getGroup().getDisplayName())));
|
||||
}
|
||||
}
|
||||
|
||||
int weight = entity.isGroup() ? 50 : 100;
|
||||
for (EntityMetadata metadata : entity.getMetadata()) {
|
||||
try {
|
||||
group.setPermission(NodeFactory.makeMetaNode(metadata.getName(), metadata.getStringValue()).build());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
String key = metadata.getName().toLowerCase();
|
||||
|
||||
if (key.equals("prefix") || key.equals("suffix")) {
|
||||
holder.setPermissionUnchecked(NodeFactory.makeChatMetaNode(key.equals("prefix"), weight, metadata.getStringValue()).build());
|
||||
} else {
|
||||
holder.setPermissionUnchecked(NodeFactory.makeMetaNode(key, metadata.getStringValue()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
@ -79,52 +80,34 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
int groupWeight = maxWeight - g.getRank();
|
||||
|
||||
// Make a LuckPerms group for the one being migrated
|
||||
plugin.getStorage().createAndLoadGroup(g.getName().toLowerCase(), CreationCause.INTERNAL).join();
|
||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(g.getName().toLowerCase());
|
||||
String groupName = MigrationUtils.standardizeName(g.getName());
|
||||
plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
|
||||
me.lucko.luckperms.common.core.model.Group group = plugin.getGroupManager().getIfLoaded(groupName);
|
||||
|
||||
group.removeIf(n -> n.getPermission().startsWith("weight."));
|
||||
group.setPermissionUnchecked(NodeFactory.make("weight." + groupWeight, true));
|
||||
MigrationUtils.setGroupWeight(group, groupWeight);
|
||||
|
||||
// Migrate global perms
|
||||
for (String perm : g.getPerms()) {
|
||||
boolean value = true;
|
||||
if (perm.startsWith("-") || perm.startsWith("!")) {
|
||||
perm = perm.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
group.setPermissionUnchecked(NodeFactory.make(perm, value));
|
||||
group.setPermissionUnchecked(MigrationUtils.parseNode(perm, true).build());
|
||||
}
|
||||
|
||||
// Migrate per-server perms
|
||||
for (Map.Entry<String, Server> e : g.getServers().entrySet()) {
|
||||
for (String perm : e.getValue().getPerms()) {
|
||||
boolean value = true;
|
||||
if (perm.startsWith("-") || perm.startsWith("!")) {
|
||||
perm = perm.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
group.setPermissionUnchecked(NodeFactory.make(perm, value, e.getKey()));
|
||||
group.setPermissionUnchecked(MigrationUtils.parseNode(perm, true).setWorld(e.getKey()).build());
|
||||
}
|
||||
|
||||
// Migrate per-world perms
|
||||
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
|
||||
for (String perm : we.getValue().getPerms()) {
|
||||
boolean value = true;
|
||||
if (perm.startsWith("-") || perm.startsWith("!")) {
|
||||
perm = perm.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
group.setPermissionUnchecked(NodeFactory.make(perm, value, e.getKey(), we.getKey()));
|
||||
group.setPermissionUnchecked(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).setWorld(we.getKey()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate any parent groups
|
||||
for (String inherit : g.getInheritances()) {
|
||||
group.setPermissionUnchecked(NodeFactory.make("group." + inherit));
|
||||
group.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(inherit)));
|
||||
}
|
||||
|
||||
// Migrate prefix and suffix
|
||||
@ -134,7 +117,6 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
group.setPermissionUnchecked(NodeFactory.makePrefixNode(groupWeight, prefix).build());
|
||||
}
|
||||
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
group.setPermissionUnchecked(NodeFactory.makeSuffixNode(groupWeight, suffix).build());
|
||||
}
|
||||
@ -158,49 +140,31 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
}
|
||||
|
||||
// Make a LuckPerms user for the one being migrated.
|
||||
plugin.getStorage().loadUser(u.getUUID(), "null").join();
|
||||
plugin.getStorage().loadUser(u.getUUID(), u.getName()).join();
|
||||
me.lucko.luckperms.common.core.model.User user = plugin.getUserManager().get(u.getUUID());
|
||||
|
||||
// Migrate global perms
|
||||
for (String perm : u.getPerms()) {
|
||||
boolean value = true;
|
||||
if (perm.startsWith("-") || perm.startsWith("!")) {
|
||||
perm = perm.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
user.setPermissionUnchecked(NodeFactory.make(perm, value));
|
||||
user.setPermissionUnchecked(MigrationUtils.parseNode(perm, true).build());
|
||||
}
|
||||
|
||||
// Migrate per-server perms
|
||||
for (Map.Entry<String, Server> e : u.getServers().entrySet()) {
|
||||
for (String perm : e.getValue().getPerms()) {
|
||||
boolean value = true;
|
||||
if (perm.startsWith("-") || perm.startsWith("!")) {
|
||||
perm = perm.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
user.setPermissionUnchecked(NodeFactory.make(perm, value, e.getKey()));
|
||||
user.setPermissionUnchecked(MigrationUtils.parseNode(perm, true).setWorld(e.getKey()).build());
|
||||
}
|
||||
|
||||
// Migrate per-world perms
|
||||
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
|
||||
for (String perm : we.getValue().getPerms()) {
|
||||
boolean value = true;
|
||||
if (perm.startsWith("-") || perm.startsWith("!")) {
|
||||
perm = perm.substring(1);
|
||||
value = false;
|
||||
}
|
||||
|
||||
user.setPermissionUnchecked(NodeFactory.make(perm, value, e.getKey(), we.getKey()));
|
||||
user.setPermissionUnchecked(MigrationUtils.parseNode(perm, true).setServer(e.getKey()).setWorld(we.getKey()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Migrate groups
|
||||
for (String group : u.getGroupsString()) {
|
||||
user.setPermissionUnchecked(NodeFactory.make("group." + group));
|
||||
user.setPermissionUnchecked(NodeFactory.make("group." + MigrationUtils.standardizeName(group)));
|
||||
}
|
||||
|
||||
// Migrate prefix & suffix
|
||||
@ -210,7 +174,6 @@ public class MigrationBungeePerms extends SubCommand<Object> {
|
||||
if (prefix != null && !prefix.equals("")) {
|
||||
user.setPermissionUnchecked(NodeFactory.makePrefixNode(maxWeight, prefix).build());
|
||||
}
|
||||
|
||||
if (suffix != null && !suffix.equals("")) {
|
||||
user.setPermissionUnchecked(NodeFactory.makeSuffixNode(maxWeight, suffix).build());
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
package me.lucko.luckperms.common.commands.migration;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import me.lucko.luckperms.common.commands.Command;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
@ -35,60 +37,31 @@ import me.lucko.luckperms.common.utils.Predicates;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MigrationMainCommand extends MainCommand<Object> {
|
||||
private static final Map<String, String> PLUGINS = ImmutableMap.<String, String>builder()
|
||||
.put("org.anjocaido.groupmanager.GroupManager", "me.lucko.luckperms.bukkit.migration.MigrationGroupManager")
|
||||
.put("ru.tehkode.permissions.bukkit.PermissionsEx", "me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx")
|
||||
.put("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin", "me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms")
|
||||
.put("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService", "me.lucko.luckperms.bukkit.migration.MigrationZPermissions")
|
||||
.put("net.alpenblock.bungeeperms.BungeePerms", "me.lucko.luckperms.bungee.migration.MigrationBungeePerms")
|
||||
.put("de.bananaco.bpermissions.api.WorldManager", "me.lucko.luckperms.bukkit.migration.MigrationBPermissions")
|
||||
.put("ninja.leaping.permissionsex.sponge.PermissionsExPlugin", "me.lucko.luckperms.sponge.migration.MigrationPermissionsEx")
|
||||
.put("io.github.djxy.permissionmanager.PermissionManager", "me.lucko.luckperms.sponge.migration.MigrationPermissionManager")
|
||||
.build();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Command<Object, ?>> getAvailableCommands() {
|
||||
List<SubCommand<Object>> l = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Class.forName("org.anjocaido.groupmanager.GroupManager");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationGroupManager").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("ru.tehkode.permissions.bukkit.PermissionsEx");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPermissionsEx").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("com.github.cheesesoftware.PowerfulPermsAPI.PowerfulPermsPlugin");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationPowerfulPerms").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("org.tyrannyofheaven.bukkit.zPermissions.ZPermissionsService");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationZPermissions").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("net.alpenblock.bungeeperms.BungeePerms");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bungee.migration.MigrationBungeePerms").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("de.bananaco.bpermissions.api.WorldManager");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.bukkit.migration.MigrationBPermissions").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("ninja.leaping.permissionsex.sponge.PermissionsExPlugin");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionsEx").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("io.github.djxy.permissionmanager.PermissionManager");
|
||||
l.add((SubCommand<Object>) Class.forName("me.lucko.luckperms.sponge.migration.MigrationPermissionManager").newInstance());
|
||||
} catch (Throwable ignored) {
|
||||
for (Map.Entry<String, String> plugin : PLUGINS.entrySet()) {
|
||||
try {
|
||||
Class.forName(plugin.getKey());
|
||||
l.add((SubCommand<Object>) Class.forName(plugin.getValue()).newInstance());
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
|
||||
return l.stream().collect(Collectors.toList());
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||
*
|
||||
* 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.commands.migration;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.Node;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
|
||||
@UtilityClass
|
||||
public class MigrationUtils {
|
||||
|
||||
public static Node.Builder parseNode(String permission, boolean value) {
|
||||
if (permission.startsWith("-") || permission.startsWith("!")) {
|
||||
permission = permission.substring(1);
|
||||
value = false;
|
||||
} else if (permission.startsWith("+")) {
|
||||
permission = permission.substring(1);
|
||||
value = true;
|
||||
}
|
||||
|
||||
return NodeFactory.newBuilder(permission).setValue(value);
|
||||
}
|
||||
|
||||
public static void setGroupWeight(Group group, int weight) {
|
||||
group.removeIf(n -> n.getPermission().startsWith("weight."));
|
||||
group.setPermissionUnchecked(NodeFactory.make("weight." + weight));
|
||||
}
|
||||
|
||||
public static String standardizeName(String string) {
|
||||
return string.trim().replace(':', '-').replace(' ', '-').replace('.', '-').toLowerCase();
|
||||
}
|
||||
|
||||
}
|
@ -61,8 +61,8 @@ public class Patterns {
|
||||
});
|
||||
|
||||
public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
|
||||
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]");
|
||||
public static final Pattern NON_ALPHA_NUMERIC_SPACE = Pattern.compile("[\\/\\$\\.\\-]");
|
||||
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\. ]");
|
||||
public static final Pattern NON_ALPHA_NUMERIC_SPACE = Pattern.compile("[\\/\\$\\.]");
|
||||
public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]");
|
||||
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");
|
||||
public static final Pattern NODE_CONTEXTS = Pattern.compile("\\(.+\\).*");
|
||||
|
@ -195,11 +195,18 @@ public class ImmutableNode implements Node {
|
||||
throw new IllegalArgumentException("Empty permission");
|
||||
}
|
||||
|
||||
if (server != null && (server.equalsIgnoreCase("global") || server.equals(""))) {
|
||||
if (server != null) {
|
||||
server = server.toLowerCase();
|
||||
}
|
||||
if (world != null) {
|
||||
world = world.toLowerCase();
|
||||
}
|
||||
|
||||
if (server != null && (server.equals("global") || server.equals(""))) {
|
||||
server = null;
|
||||
}
|
||||
|
||||
if (world != null && (world.equalsIgnoreCase("global") || world.equals(""))) {
|
||||
if (world != null && (world.equals("global") || world.equals(""))) {
|
||||
world = null;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
@ -50,7 +51,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject;
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject;
|
||||
|
||||
public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
public MigrationPermissionManager() {
|
||||
@ -88,12 +89,12 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
// Migrate defaults
|
||||
log.log("Migrating default subjects.");
|
||||
for (SubjectCollection collection : pmService.getKnownSubjects().values()) {
|
||||
MigrationUtils.migrateSubjectData(
|
||||
SpongeMigrationUtils.migrateSubjectData(
|
||||
collection.getDefaults().getSubjectData(),
|
||||
lpService.getSubjects("defaults").get(collection.getIdentifier()).getSubjectData()
|
||||
);
|
||||
}
|
||||
MigrationUtils.migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
SpongeMigrationUtils.migrateSubjectData(pmService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
|
||||
// Migrate groups
|
||||
log.log("Starting group migration.");
|
||||
@ -108,7 +109,7 @@ public class MigrationPermissionManager extends SubCommand<Object> {
|
||||
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (Subject pmGroup : pmService.getGroupSubjects().getAllSubjects()) {
|
||||
String pmName = MigrationUtils.convertName(pmGroup.getIdentifier());
|
||||
String pmName = MigrationUtils.standardizeName(pmGroup.getIdentifier());
|
||||
|
||||
// Make a LuckPerms group for the one being migrated
|
||||
plugin.getStorage().createAndLoadGroup(pmName, CreationCause.INTERNAL).join();
|
||||
|
@ -26,6 +26,7 @@ import me.lucko.luckperms.api.event.cause.CreationCause;
|
||||
import me.lucko.luckperms.common.commands.CommandException;
|
||||
import me.lucko.luckperms.common.commands.CommandResult;
|
||||
import me.lucko.luckperms.common.commands.SubCommand;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.commands.utils.Util;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
@ -55,7 +56,7 @@ import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static me.lucko.luckperms.sponge.migration.MigrationUtils.migrateSubject;
|
||||
import static me.lucko.luckperms.sponge.migration.SpongeMigrationUtils.migrateSubject;
|
||||
|
||||
public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
public MigrationPermissionsEx() {
|
||||
@ -84,12 +85,12 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Migrate defaults
|
||||
log.log("Migrating default subjects.");
|
||||
for (SubjectCollection collection : pexService.getKnownSubjects().values()) {
|
||||
MigrationUtils.migrateSubjectData(
|
||||
SpongeMigrationUtils.migrateSubjectData(
|
||||
collection.getDefaults().getSubjectData(),
|
||||
lpService.getSubjects("defaults").get(collection.getIdentifier()).getSubjectData()
|
||||
);
|
||||
}
|
||||
MigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
SpongeMigrationUtils.migrateSubjectData(pexService.getDefaults().getSubjectData(), lpService.getDefaults().getSubjectData());
|
||||
|
||||
log.log("Calculating group weightings.");
|
||||
int maxWeight = 0;
|
||||
@ -110,7 +111,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
log.log("Starting group migration.");
|
||||
AtomicInteger groupCount = new AtomicInteger(0);
|
||||
for (Subject pexGroup : pexService.getGroupSubjects().getAllSubjects()) {
|
||||
String pexName = MigrationUtils.convertName(pexGroup.getIdentifier());
|
||||
String pexName = MigrationUtils.standardizeName(pexGroup.getIdentifier());
|
||||
|
||||
Optional<String> rankString = pexGroup.getOption("rank");
|
||||
OptionalInt rank = OptionalInt.empty();
|
||||
@ -135,7 +136,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
|
||||
// Pull track data
|
||||
Optional<String> track = pexGroup.getOption("rank-ladder");
|
||||
if (track.isPresent() && rank.isPresent()) {
|
||||
String trackName = MigrationUtils.convertName(track.get());
|
||||
String trackName = MigrationUtils.standardizeName(track.get());
|
||||
if (!tracks.containsKey(trackName)) {
|
||||
tracks.put(trackName, new TreeMap<>(Comparator.reverseOrder()));
|
||||
}
|
||||
|
@ -25,11 +25,12 @@ package me.lucko.luckperms.sponge.migration;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.common.commands.migration.MigrationUtils;
|
||||
import me.lucko.luckperms.common.core.NodeBuilder;
|
||||
import me.lucko.luckperms.common.core.NodeFactory;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.PermissionHolder;
|
||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||
import me.lucko.luckperms.exceptions.ObjectAlreadyHasException;
|
||||
import me.lucko.luckperms.sponge.service.proxy.Util;
|
||||
|
||||
import org.spongepowered.api.service.context.Context;
|
||||
@ -43,12 +44,13 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class MigrationUtils {
|
||||
public class SpongeMigrationUtils {
|
||||
|
||||
public static void migrateSubject(Subject subject, PermissionHolder holder, int priority) {
|
||||
|
||||
holder.removeIf(n -> n.getPermission().startsWith("weight."));
|
||||
holder.setPermissionUnchecked(NodeFactory.make("weight." + priority, true));
|
||||
if (holder instanceof Group) {
|
||||
MigrationUtils.setGroupWeight((Group) holder, priority);
|
||||
}
|
||||
|
||||
// Migrate permissions
|
||||
Map<Set<Context>, Map<String, Boolean>> perms = subject.getSubjectData().getAllPermissions();
|
||||
@ -61,9 +63,7 @@ public class MigrationUtils {
|
||||
String world = extractedContexts.getWorld();
|
||||
|
||||
for (Map.Entry<String, Boolean> perm : e.getValue().entrySet()) {
|
||||
try {
|
||||
holder.setPermission(new NodeBuilder(perm.getKey()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
} catch (ObjectAlreadyHasException ignored) {}
|
||||
holder.setPermissionUnchecked(new NodeBuilder(perm.getKey()).setServer(server).setWorld(world).withExtraContext(contexts).setValue(perm.getValue()).build());
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public class MigrationUtils {
|
||||
continue; // LuckPerms does not support persisting other subject types.
|
||||
}
|
||||
|
||||
holder.setPermissionUnchecked(new NodeBuilder("group." + convertName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
holder.setPermissionUnchecked(new NodeBuilder("group." + MigrationUtils.standardizeName(s.getIdentifier())).setServer(server).setWorld(world).withExtraContext(contexts).setValue(true).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -132,8 +132,4 @@ public class MigrationUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String convertName(String s) {
|
||||
return s.replace(' ', '_').toLowerCase();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user