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