use of me.lucko.luckperms.common.logging.ProgressLogger in project LuckPerms by lucko.
the class MigrationBPermissions method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger("bPermissions");
log.addListener(plugin.getConsoleSender());
log.addListener(sender);
log.log("Starting.");
WorldManager worldManager = WorldManager.getInstance();
if (worldManager == null) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
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());
YamlConfiguration yamlWorldUsers = null;
try {
yamlWorldUsers = (YamlConfiguration) UCONFIG_FIELD.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.logError("Couldn't get a list of users.");
return CommandResult.FAILURE;
}
AtomicInteger userLoadCount = new AtomicInteger(0);
users.forEach(s -> {
world.loadOne(s, CalculableType.USER);
log.logProgress("Forcefully loaded {} users so far.", userLoadCount.incrementAndGet());
});
}
log.log("Forcefully loaded all users.");
// Migrate one world at a time.
log.log("Starting world migration.");
Iterators.iterate(worldManager.getAllWorlds(), world -> {
log.log("Migrating world: " + world.getName());
// Migrate all groups
log.log("Starting group migration in world " + world.getName() + ".");
AtomicInteger groupCount = new AtomicInteger(0);
Iterators.iterate(world.getAll(CalculableType.GROUP), group -> {
String groupName = MigrationUtils.standardizeName(group.getName());
if (group.getName().equalsIgnoreCase(world.getDefaultGroup())) {
groupName = NodeFactory.DEFAULT_GROUP_NAME;
}
// Make a LuckPerms group for the one being migrated.
Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
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);
Iterators.iterate(world.getAll(CalculableType.USER), user -> {
// There is no mention of UUIDs in the API. I assume that name = uuid. idk?
UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getName());
if (uuid == null) {
return;
}
// Make a LuckPerms user for the one being migrated.
User lpUser = plugin.getStorage().loadUser(uuid, null).join();
migrateHolder(world, user, lpUser);
plugin.getStorage().saveUser(lpUser);
plugin.getUserManager().cleanup(lpUser);
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
});
log.log("Migrated " + userCount.get() + " users in world " + world.getName() + ".");
});
log.log("Success! Migration complete.");
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.logging.ProgressLogger in project LuckPerms by lucko.
the class MigrationGroupManager method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger("GroupManager");
log.addListener(plugin.getConsoleSender());
log.addListener(sender);
log.log("Starting.");
if (!args.get(0).equalsIgnoreCase("true") && !args.get(0).equalsIgnoreCase("false")) {
log.logError("Was expecting true/false, but got " + args.get(0) + " instead.");
return CommandResult.STATE_ERROR;
}
final boolean migrateAsGlobal = Boolean.parseBoolean(args.get(0));
final Function<String, String> worldMappingFunc = s -> migrateAsGlobal ? null : s;
if (!Bukkit.getPluginManager().isPluginEnabled("GroupManager")) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
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
log.log("Starting global group migration.");
GlobalGroups gg = GroupManager.getGlobalGroups();
AtomicInteger globalGroupCount = new AtomicInteger(0);
Iterators.iterate(gg.getGroupList(), g -> {
String groupName = MigrationUtils.standardizeName(g.getName());
Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
for (String node : g.getPermissionList()) {
if (node.isEmpty())
continue;
group.setPermission(MigrationUtils.parseNode(node, true).build());
}
for (String s : g.getInherits()) {
if (s.isEmpty())
continue;
group.setPermission(NodeFactory.make(NodeFactory.groupNode(MigrationUtils.standardizeName(s))));
}
plugin.getStorage().saveGroup(group);
log.logAllProgress("Migrated {} groups so far.", globalGroupCount.incrementAndGet());
});
log.log("Migrated " + globalGroupCount.get() + " global groups");
// Collect data
Map<UUID, Set<Node>> users = new HashMap<>();
Map<UUID, String> primaryGroups = new HashMap<>();
Map<String, Set<Node>> groups = new HashMap<>();
WorldsHolder wh = gm.getWorldsHolder();
// Collect data for all users and groups.
log.log("Collecting user and group data.");
Iterators.iterate(worlds, String::toLowerCase, world -> {
log.log("Querying world " + world);
WorldDataHolder wdh = wh.getWorldData(world);
AtomicInteger groupWorldCount = new AtomicInteger(0);
Iterators.iterate(wdh.getGroupList(), group -> {
String groupName = MigrationUtils.standardizeName(group.getName());
groups.putIfAbsent(groupName, new HashSet<>());
for (String node : group.getPermissionList()) {
if (node.isEmpty())
continue;
groups.get(groupName).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
}
for (String s : group.getInherits()) {
if (s.isEmpty())
continue;
groups.get(groupName).add(NodeFactory.make(NodeFactory.groupNode(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.isEmpty() || value.isEmpty())
continue;
if (key.equals("build"))
continue;
if (key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY)) {
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
groups.get(groupName).add(NodeFactory.buildChatMetaNode(type, 50, value).setWorld(worldMappingFunc.apply(world)).build());
} else {
groups.get(groupName).add(NodeFactory.buildMetaNode(key, value).setWorld(worldMappingFunc.apply(world)).build());
}
}
log.logAllProgress("Migrated {} groups so far in world " + world, groupWorldCount.incrementAndGet());
});
log.log("Migrated " + groupWorldCount.get() + " groups in world " + world);
AtomicInteger userWorldCount = new AtomicInteger(0);
Iterators.iterate(wdh.getUserList(), user -> {
UUID uuid = BukkitMigrationUtils.lookupUuid(log, user.getUUID());
if (uuid == null) {
return;
}
users.putIfAbsent(uuid, new HashSet<>());
for (String node : user.getPermissionList()) {
if (node.isEmpty())
continue;
users.get(uuid).add(MigrationUtils.parseNode(node, true).setWorld(worldMappingFunc.apply(world)).build());
}
// Collect sub groups
String finalWorld = worldMappingFunc.apply(world);
users.get(uuid).addAll(user.subGroupListStringCopy().stream().filter(n -> !n.isEmpty()).map(n -> NodeFactory.groupNode(MigrationUtils.standardizeName(n))).map(n -> NodeFactory.make(n, true, null, finalWorld)).collect(Collectors.toSet()));
// 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.isEmpty() || value.isEmpty())
continue;
if (key.equals("build"))
continue;
if (key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY)) {
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
users.get(uuid).add(NodeFactory.buildChatMetaNode(type, 100, value).setWorld(worldMappingFunc.apply(world)).build());
} else {
users.get(uuid).add(NodeFactory.buildMetaNode(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.");
log.log("Found a total of " + users.size() + " users and " + groups.size() + " groups.");
log.log("Starting group migration.");
AtomicInteger groupCount = new AtomicInteger(0);
Iterators.iterate(groups.entrySet(), e -> {
Group group = plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
for (Node node : e.getValue()) {
group.setPermission(node);
}
plugin.getStorage().saveGroup(group);
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
});
log.log("Migrated " + groupCount.get() + " groups");
log.log("Starting user migration.");
AtomicInteger userCount = new AtomicInteger(0);
Iterators.iterate(users.entrySet(), e -> {
User user = plugin.getStorage().loadUser(e.getKey(), null).join();
for (Node node : e.getValue()) {
user.setPermission(node);
}
String primaryGroup = primaryGroups.get(e.getKey());
if (primaryGroup != null && !primaryGroup.isEmpty()) {
user.setPermission(NodeFactory.buildGroupNode(primaryGroup).build());
user.getPrimaryGroup().setStoredValue(primaryGroup);
user.unsetPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build());
}
plugin.getStorage().saveUser(user);
plugin.getUserManager().cleanup(user);
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
});
log.log("Migrated " + userCount.get() + " users.");
log.log("Success! Migration complete.");
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.logging.ProgressLogger in project LuckPerms by lucko.
the class MigrationPermissionsBukkit method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger("PermissionsBukkit");
log.addListener(plugin.getConsoleSender());
log.addListener(sender);
log.log("Starting.");
if (!Bukkit.getPluginManager().isPluginEnabled("PermissionsBukkit")) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
PermissionsPlugin permissionsBukkit = (PermissionsPlugin) Bukkit.getPluginManager().getPlugin("PermissionsBukkit");
FileConfiguration config = permissionsBukkit.getConfig();
// Migrate all groups
log.log("Starting group migration.");
AtomicInteger groupCount = new AtomicInteger(0);
ConfigurationSection groupsSection = config.getConfigurationSection("groups");
Iterators.iterate(groupsSection.getKeys(false), key -> {
final String groupName = MigrationUtils.standardizeName(key);
Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
// migrate data
if (groupsSection.isConfigurationSection(key)) {
migrate(lpGroup, groupsSection.getConfigurationSection(key));
}
plugin.getStorage().saveGroup(lpGroup).join();
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
});
log.log("Migrated " + groupCount.get() + " groups");
// Migrate all users
log.log("Starting user migration.");
AtomicInteger userCount = new AtomicInteger(0);
ConfigurationSection usersSection = config.getConfigurationSection("users");
Iterators.iterate(usersSection.getKeys(false), key -> {
UUID uuid = BukkitMigrationUtils.lookupUuid(log, key);
if (uuid == null) {
return;
}
User lpUser = plugin.getStorage().loadUser(uuid, null).join();
// migrate data
if (usersSection.isConfigurationSection(key)) {
migrate(lpUser, usersSection.getConfigurationSection(key));
}
plugin.getUserManager().cleanup(lpUser);
plugin.getStorage().saveUser(lpUser);
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
});
log.log("Migrated " + userCount.get() + " users.");
log.log("Success! Migration complete.");
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.logging.ProgressLogger in project LuckPerms by lucko.
the class MigrationPermissionsEx method execute.
@SuppressWarnings("deprecation")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger("PermissionsEx");
log.addListener(plugin.getConsoleSender());
log.addListener(sender);
log.log("Starting.");
if (!Bukkit.getPluginManager().isPluginEnabled("PermissionsEx")) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
PermissionsEx pex = (PermissionsEx) Bukkit.getPluginManager().getPlugin("PermissionsEx");
PermissionManager manager = pex.getPermissionsManager();
log.log("Calculating group weightings.");
int i = 0;
for (PermissionGroup group : manager.getGroupList()) {
i = Math.max(i, group.getRank());
}
int maxWeight = i + 5;
// Migrate all groups.
log.log("Starting group migration.");
AtomicInteger groupCount = new AtomicInteger(0);
Set<String> ladders = new HashSet<>();
Iterators.iterate(manager.getGroupList(), group -> {
int groupWeight = maxWeight - group.getRank();
final String groupName = MigrationUtils.standardizeName(group.getName());
Group lpGroup = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
MigrationUtils.setGroupWeight(lpGroup, groupWeight);
// migrate data
migrateEntity(group, lpGroup, groupWeight);
// remember known ladders
if (group.isRanked()) {
ladders.add(group.getRankLadder().toLowerCase());
}
plugin.getStorage().saveGroup(lpGroup).join();
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
});
log.log("Migrated " + groupCount.get() + " groups");
// Migrate all ladders/tracks.
log.log("Starting tracks migration.");
for (String rankLadder : ladders) {
Track track = plugin.getStorage().createAndLoadTrack(rankLadder, CreationCause.INTERNAL).join();
// Get a list of all groups in a ladder
List<String> ladder = manager.getRankLadder(rankLadder).entrySet().stream().sorted(Comparator.<Map.Entry<Integer, PermissionGroup>>comparingInt(Map.Entry::getKey).reversed()).map(e -> MigrationUtils.standardizeName(e.getValue().getName())).collect(Collectors.toList());
track.setGroups(ladder);
plugin.getStorage().saveTrack(track);
}
log.log("Migrated " + ladders.size() + " tracks");
// Migrate all users
log.log("Starting user migration.");
AtomicInteger userCount = new AtomicInteger(0);
// Increment the max weight from the group migrations. All user meta should override.
int userWeight = maxWeight + 5;
Iterators.iterate(manager.getUsers(), user -> {
UUID u = BukkitMigrationUtils.lookupUuid(log, user.getIdentifier());
if (u == null) {
return;
}
// load in a user instance
User lpUser = plugin.getStorage().loadUser(u, user.getName()).join();
// migrate data
migrateEntity(user, lpUser, userWeight);
plugin.getUserManager().cleanup(lpUser);
plugin.getStorage().saveUser(lpUser);
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
});
log.log("Migrated " + userCount.get() + " users.");
log.log("Success! Migration complete.");
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.logging.ProgressLogger in project LuckPerms by lucko.
the class MigrationPowerfulPerms method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger("PowerfulPerms");
log.addListener(plugin.getConsoleSender());
log.addListener(sender);
log.log("Starting.");
if (!Bukkit.getPluginManager().isPluginEnabled("PowerfulPerms")) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
String method = plugin.getConfiguration().get(ConfigKeys.STORAGE_METHOD);
StorageType type = StorageType.parse(method);
if (type == null || type != StorageType.MYSQL) {
// We need to load the Hikari/MySQL stuff.
plugin.getDependencyManager().loadStorageDependencies(ImmutableSet.of(StorageType.MYSQL));
}
String address = args.get(0);
String database = args.get(1);
String username = args.get(2);
String password = args.get(3);
String dbTable = args.get(4);
// Find a list of UUIDs
log.log("Getting a list of UUIDs to migrate.");
Set<UUID> uuids = new HashSet<>();
try (HikariSupplier hikari = new HikariSupplier(address, database, username, password)) {
hikari.setup("powerfulperms-migrator-pool");
try (Connection c = hikari.getConnection()) {
DatabaseMetaData meta = c.getMetaData();
try (ResultSet rs = meta.getTables(null, null, dbTable, null)) {
if (!rs.next()) {
log.log("Error - Couldn't find table.");
return CommandResult.FAILURE;
}
}
}
try (Connection c = hikari.getConnection()) {
try (PreparedStatement ps = c.prepareStatement("SELECT COLUMN_NAME, COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=?")) {
ps.setString(1, dbTable);
try (ResultSet rs = ps.executeQuery()) {
log.log("Found table: " + dbTable);
while (rs.next()) {
log.log("" + rs.getString("COLUMN_NAME") + " - " + rs.getString("COLUMN_TYPE"));
}
}
}
try (PreparedStatement ps = c.prepareStatement("SELECT `uuid` FROM " + dbTable)) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
uuids.add(UUID.fromString(rs.getString("uuid")));
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (uuids.isEmpty()) {
log.logError("Unable to find any UUIDs to migrate.");
return CommandResult.FAILURE;
}
log.log("Found " + uuids.size() + " uuids. Starting migration.");
PowerfulPermsPlugin ppPlugin = (PowerfulPermsPlugin) Bukkit.getPluginManager().getPlugin("PowerfulPerms");
PermissionManager pm = ppPlugin.getPermissionManager();
Collection<Group> groups = pm.getGroups().values();
AtomicInteger maxWeight = new AtomicInteger(0);
// Groups first.
log.log("Starting group migration.");
AtomicInteger groupCount = new AtomicInteger(0);
Iterators.iterate(groups, g -> {
maxWeight.set(Math.max(maxWeight.get(), g.getRank()));
String groupName = MigrationUtils.standardizeName(g.getName());
me.lucko.luckperms.common.model.Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
MigrationUtils.setGroupWeight(group, g.getRank());
for (Permission p : g.getOwnPermissions()) {
applyPerm(group, p);
}
for (Group parent : g.getParents()) {
group.setPermission(NodeFactory.buildGroupNode(parent.getName().toLowerCase()).build());
}
// server --> prefix afaik
for (Map.Entry<String, String> prefix : g.getPrefixes().entrySet()) {
if (prefix.getValue().isEmpty())
continue;
String server = prefix.getKey().toLowerCase();
if (prefix.getKey().equals("*") || prefix.getKey().equals("all")) {
server = null;
}
if (server != null) {
group.setPermission(NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).setServer(server).build());
} else {
group.setPermission(NodeFactory.buildPrefixNode(g.getRank(), prefix.getValue()).build());
}
}
for (Map.Entry<String, String> suffix : g.getSuffixes().entrySet()) {
if (suffix.getValue().isEmpty())
continue;
String server = suffix.getKey().toLowerCase();
if (suffix.getKey().equals("*") || suffix.getKey().equals("all")) {
server = null;
}
if (server != null) {
group.setPermission(NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).setServer(server).build());
} else {
group.setPermission(NodeFactory.buildSuffixNode(g.getRank(), suffix.getValue()).build());
}
}
plugin.getStorage().saveGroup(group);
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
});
log.log("Migrated " + groupCount.get() + " groups");
// Migrate all users
log.log("Starting user migration.");
AtomicInteger userCount = new AtomicInteger(0);
// Increment the max weight from the group migrations. All user meta should override.
maxWeight.addAndGet(5);
// Migrate all users and their groups
Iterators.iterate(uuids, uuid -> {
// Create a LuckPerms user for the UUID
User user = plugin.getStorage().loadUser(uuid, null).join();
List<Permission> permissions = joinFuture(pm.getPlayerOwnPermissions(uuid));
for (Permission p : permissions) {
applyPerm(user, p);
}
// server --> list of groups
Map<String, List<CachedGroup>> parents = joinFuture(pm.getPlayerOwnGroups(uuid));
for (Map.Entry<String, List<CachedGroup>> parent : parents.entrySet()) {
String server = parent.getKey().toLowerCase();
if (parent.getKey().equals("*") || parent.getKey().equals("all")) {
server = null;
}
for (CachedGroup group : parent.getValue()) {
applyGroup(pm, user, group, server);
}
}
String prefix = joinFuture(pm.getPlayerOwnPrefix(uuid));
String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
if (prefix != null && !prefix.isEmpty()) {
user.setPermission(NodeFactory.buildPrefixNode(maxWeight.get(), prefix).build());
}
if (suffix != null && !suffix.isEmpty()) {
user.setPermission(NodeFactory.buildSuffixNode(maxWeight.get(), suffix).build());
}
Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid));
if (primaryGroup != null && primaryGroup.getName() != null) {
String primary = primaryGroup.getName().toLowerCase();
if (!primary.equals(NodeFactory.DEFAULT_GROUP_NAME)) {
user.setPermission(NodeFactory.buildGroupNode(primary).build());
user.getPrimaryGroup().setStoredValue(primary);
}
}
plugin.getUserManager().cleanup(user);
plugin.getStorage().saveUser(user);
log.logProgress("Migrated {} users so far.", userCount.incrementAndGet());
});
log.log("Migrated " + userCount.get() + " users.");
log.log("Success! Migration complete.");
return CommandResult.SUCCESS;
}
Aggregations