use of me.lucko.luckperms.common.model.User 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.model.User 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.model.User 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;
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class MigrationZPermissions method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Object o, List<String> args, String label) {
ProgressLogger log = new ProgressLogger("zPermissions");
log.addListener(plugin.getConsoleSender());
log.addListener(sender);
log.log("Starting.");
if (!Bukkit.getPluginManager().isPluginEnabled("zPermissions")) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
if (!Bukkit.getServicesManager().isProvidedFor(ZPermissionsService.class)) {
log.logError("Plugin not loaded.");
return CommandResult.STATE_ERROR;
}
ZPermissionsService service = Bukkit.getServicesManager().getRegistration(ZPermissionsService.class).getProvider();
PermissionService internalService;
try {
Field psField = service.getClass().getDeclaredField("permissionService");
psField.setAccessible(true);
internalService = (PermissionService) psField.get(service);
} catch (Exception e) {
e.printStackTrace();
return CommandResult.FAILURE;
}
// Migrate all groups
log.log("Starting group migration.");
Map<UUID, Set<Node>> userParents = new HashMap<>();
AtomicInteger groupCount = new AtomicInteger(0);
AtomicInteger maxWeight = new AtomicInteger(0);
Iterators.iterate(internalService.getEntities(true), entity -> {
String groupName = MigrationUtils.standardizeName(entity.getDisplayName());
Group group = plugin.getStorage().createAndLoadGroup(groupName, CreationCause.INTERNAL).join();
int weight = entity.getPriority();
maxWeight.set(Math.max(maxWeight.get(), weight));
migrateEntity(group, entity, weight);
MigrationUtils.setGroupWeight(group, weight);
// store user data for later
Set<Membership> members = entity.getMemberships();
for (Membership membership : members) {
UUID uuid = BukkitMigrationUtils.lookupUuid(log, membership.getMember());
if (uuid == null) {
continue;
}
Set<Node> nodes = userParents.computeIfAbsent(uuid, u -> new HashSet<>());
if (membership.getExpiration() == null) {
nodes.add(NodeFactory.buildGroupNode(groupName).build());
} else {
long expiry = membership.getExpiration().toInstant().getEpochSecond();
nodes.add(NodeFactory.buildGroupNode(groupName).setExpiry(expiry).build());
}
}
plugin.getStorage().saveGroup(group);
log.logAllProgress("Migrated {} groups so far.", groupCount.incrementAndGet());
});
log.log("Migrated " + groupCount.get() + " groups");
// Migrate all tracks
log.log("Starting track migration.");
AtomicInteger trackCount = new AtomicInteger(0);
Iterators.iterate(service.getAllTracks(), t -> {
String trackName = MigrationUtils.standardizeName(t);
Track track = plugin.getStorage().createAndLoadTrack(trackName, CreationCause.INTERNAL).join();
track.setGroups(service.getTrackGroups(t));
plugin.getStorage().saveTrack(track);
log.logAllProgress("Migrated {} tracks so far.", trackCount.incrementAndGet());
});
log.log("Migrated " + trackCount.get() + " tracks");
// Migrate all users.
log.log("Starting user migration.");
maxWeight.addAndGet(10);
AtomicInteger userCount = new AtomicInteger(0);
Set<UUID> usersToMigrate = new HashSet<>(userParents.keySet());
usersToMigrate.addAll(service.getAllPlayersUUID());
Iterators.iterate(usersToMigrate, u -> {
PermissionEntity entity = internalService.getEntity(null, u, false);
String username = null;
if (entity != null) {
username = entity.getDisplayName();
}
User user = plugin.getStorage().loadUser(u, username).join();
// migrate permissions & meta
if (entity != null) {
migrateEntity(user, entity, maxWeight.get());
}
// migrate groups
Set<Node> parents = userParents.get(u);
if (parents != null) {
parents.forEach(user::setPermission);
}
user.getPrimaryGroup().setStoredValue(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u)));
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;
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class LPPermissionAttachment method setPermissionInternal.
private void setPermissionInternal(String name, boolean value) {
if (!this.permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_BUKKIT_ATTACHMENT_PERMISSIONS)) {
return;
}
// construct a node for the permission being set
// we use the servers static context to *try* to ensure that the node will apply
Node node = NodeFactory.builder(name).setValue(value).withExtraContext(this.permissible.getPlugin().getContextManager().getStaticContext()).build();
// convert the constructed node to a transient node instance to refer back to this attachment
ImmutableTransientNode<LPPermissionAttachment> transientNode = ImmutableTransientNode.of(node, this);
// set the transient node
User user = this.permissible.getUser();
if (user.setTransientPermission(transientNode).asBoolean()) {
user.reloadCachedData();
}
}
Aggregations