use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class ConfigurateDao method loadGroup.
@Override
public Optional<Group> loadGroup(String name) throws Exception {
Group group = this.plugin.getGroupManager().getIfLoaded(name);
if (group != null) {
group.getIoLock().lock();
}
try {
ConfigurationNode object = readFile(StorageLocation.GROUP, name);
if (object == null) {
return Optional.empty();
}
if (group == null) {
group = this.plugin.getGroupManager().getOrMake(name);
group.getIoLock().lock();
}
Set<NodeModel> data = readNodes(object);
Set<Node> nodes = data.stream().map(NodeModel::toNode).collect(Collectors.toSet());
group.setEnduringNodes(nodes);
} catch (Exception e) {
throw reportException(name, e);
} finally {
if (group != null) {
group.getIoLock().unlock();
}
}
group.getRefreshBuffer().requestDirectly();
return Optional.of(group);
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class GroupRename method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Group group, List<String> args, String label) {
String newGroupName = args.get(0).toLowerCase();
if (!DataConstraints.GROUP_NAME_TEST.test(newGroupName)) {
Message.GROUP_INVALID_ENTRY.send(sender, newGroupName);
return CommandResult.INVALID_ARGS;
}
if (plugin.getStorage().loadGroup(newGroupName).join().isPresent()) {
Message.ALREADY_EXISTS.send(sender, newGroupName);
return CommandResult.INVALID_ARGS;
}
Group newGroup;
try {
newGroup = plugin.getStorage().createAndLoadGroup(newGroupName, CreationCause.COMMAND).get();
} catch (Exception e) {
e.printStackTrace();
Message.CREATE_ERROR.send(sender, newGroupName);
return CommandResult.FAILURE;
}
try {
plugin.getStorage().deleteGroup(group, DeletionCause.COMMAND).get();
} catch (Exception e) {
e.printStackTrace();
Message.DELETE_ERROR.send(sender, group.getFriendlyName());
return CommandResult.FAILURE;
}
newGroup.replaceEnduringNodes(group.getEnduringNodes());
Message.RENAME_SUCCESS.send(sender, group.getName(), newGroup.getName());
ExtendedLogEntry.build().actor(sender).acted(group).action("rename", newGroup.getName()).build().submit(plugin, sender);
StorageAssistant.save(newGroup, sender, plugin);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.Group in project LuckPerms by lucko.
the class TrackAppend method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
String groupName = args.get(0).toLowerCase();
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
sendDetailedUsage(sender, label);
return CommandResult.INVALID_ARGS;
}
Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
if (group == null) {
return CommandResult.LOADING_ERROR;
}
DataMutateResult result = track.appendGroup(group);
if (result.asBoolean()) {
Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName());
if (track.getGroups().size() > 1) {
Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), group.getName()));
}
ExtendedLogEntry.build().actor(sender).acted(track).action("append", group.getName()).build().submit(plugin, sender);
StorageAssistant.save(track, sender, plugin);
return CommandResult.SUCCESS;
} else {
Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
return CommandResult.STATE_ERROR;
}
}
use of me.lucko.luckperms.common.model.Group 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.model.Group 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;
}
Aggregations