use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class LPBukkitPlugin method performFinalSetup.
@Override
protected void performFinalSetup() {
// register permissions
try {
PluginManager pm = this.bootstrap.getServer().getPluginManager();
PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
for (CommandPermission p : CommandPermission.values()) {
pm.addPermission(new Permission(p.getPermission(), permDefault));
}
} catch (Exception e) {
// this throws an exception if the plugin is /reloaded, grr
}
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
this.bootstrap.getScheduler().doSync(() -> this.bootstrap.getServer().getOperators().forEach(o -> o.setOp(false)));
}
// replace the temporary executor when the Bukkit one starts
this.bootstrap.getServer().getScheduler().runTaskAsynchronously(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false));
// Load any online users (in the case of a reload)
for (Player player : this.bootstrap.getServer().getOnlinePlayers()) {
this.bootstrap.getScheduler().doAsync(() -> {
try {
User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
if (user != null) {
this.bootstrap.getScheduler().doSync(() -> {
try {
LPPermissible lpPermissible = new LPPermissible(player, user, this);
PermissibleInjector.inject(player, lpPermissible);
} catch (Throwable t) {
t.printStackTrace();
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
use of me.lucko.luckperms.common.model.User 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.model.User in project LuckPerms by lucko.
the class MigrationPermissionsEx method migrateEntity.
private static void migrateEntity(PermissionEntity entity, PermissionHolder holder, int weight) {
// migrate permanent permissions
for (Map.Entry<String, List<String>> worldData : getPermanentPermissions(entity).entrySet()) {
String world = standardizeWorld(worldData.getKey());
for (String node : worldData.getValue()) {
if (node.isEmpty())
continue;
holder.setPermission(MigrationUtils.parseNode(node, true).setWorld(world).build());
}
}
// migrate temporary permissions
Map<String, List<String>> timedPermissions;
Map<String, Long> timedPermissionsTime;
try {
// noinspection unchecked
timedPermissions = (Map<String, List<String>>) TIMED_PERMISSIONS_FIELD.get(entity);
// noinspection unchecked
timedPermissionsTime = (Map<String, Long>) TIMED_PERMISSIONS_TIME_FIELD.get(entity);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
for (Map.Entry<String, List<String>> worldData : timedPermissions.entrySet()) {
String world = standardizeWorld(worldData.getKey());
for (String node : worldData.getValue()) {
if (node.isEmpty())
continue;
long expiry = timedPermissionsTime.getOrDefault(Strings.nullToEmpty(world) + ":" + node, 0L);
holder.setPermission(MigrationUtils.parseNode(node, true).setWorld(world).setExpiry(expiry).build());
}
}
// migrate parents
for (Map.Entry<String, List<PermissionGroup>> worldData : entity.getAllParents().entrySet()) {
String world = standardizeWorld(worldData.getKey());
// keep track of primary group
String primary = null;
int primaryWeight = Integer.MAX_VALUE;
for (PermissionGroup parent : worldData.getValue()) {
String parentName = parent.getName();
long expiry = 0L;
// check for temporary parent
if (entity instanceof PermissionUser) {
String expiryOption = entity.getOption("group-" + parentName + "-until", world);
if (expiryOption != null) {
try {
expiry = Long.parseLong(expiryOption);
} catch (NumberFormatException e) {
// ignore
}
}
}
holder.setPermission(NodeFactory.buildGroupNode(MigrationUtils.standardizeName(parentName)).setWorld(world).setExpiry(expiry).build());
// migrate primary groups
if (world == null && holder instanceof User && expiry == 0) {
if (parent.getRank() < primaryWeight) {
primary = parent.getName();
primaryWeight = parent.getRank();
}
}
}
if (primary != null && !primary.isEmpty() && !primary.equalsIgnoreCase(NodeFactory.DEFAULT_GROUP_NAME)) {
User user = ((User) holder);
user.getPrimaryGroup().setStoredValue(primary);
user.unsetPermission(NodeFactory.buildGroupNode(NodeFactory.DEFAULT_GROUP_NAME).build());
}
}
// migrate prefix / suffix
String prefix = entity.getOwnPrefix();
String suffix = entity.getOwnSuffix();
if (prefix != null && !prefix.isEmpty()) {
holder.setPermission(NodeFactory.buildPrefixNode(weight, prefix).build());
}
if (suffix != null && !suffix.isEmpty()) {
holder.setPermission(NodeFactory.buildSuffixNode(weight, suffix).build());
}
// migrate options
for (Map.Entry<String, Map<String, String>> worldData : entity.getAllOptions().entrySet()) {
String world = standardizeWorld(worldData.getKey());
for (Map.Entry<String, String> opt : worldData.getValue().entrySet()) {
if (opt.getKey() == null || opt.getKey().isEmpty() || opt.getValue() == null || opt.getValue().isEmpty()) {
continue;
}
String key = opt.getKey().toLowerCase();
boolean ignore = key.equals(NodeFactory.PREFIX_KEY) || key.equals(NodeFactory.SUFFIX_KEY) || key.equals(NodeFactory.WEIGHT_KEY) || key.equals("rank") || key.equals("rank-ladder") || key.equals("name") || key.equals("username") || (key.startsWith("group-") && key.endsWith("-until"));
if (ignore) {
continue;
}
holder.setPermission(NodeFactory.buildMetaNode(opt.getKey(), opt.getValue()).setWorld(world).build());
}
}
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class VaultPermissionHook method holderSave.
void holderSave(PermissionHolder holder) {
if (holder.getType().isUser()) {
User u = (User) holder;
this.plugin.getStorage().saveUser(u).thenRunAsync(() -> u.getRefreshBuffer().request(), this.plugin.getBootstrap().getScheduler().async());
}
if (holder.getType().isGroup()) {
Group g = (Group) holder;
this.plugin.getStorage().saveGroup(g).thenRunAsync(() -> this.plugin.getUpdateTaskBuffer().request(), this.plugin.getBootstrap().getScheduler().async());
}
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class VaultPermissionHook method userRemovePermission.
@Override
public boolean userRemovePermission(String world, UUID uuid, String permission) {
if (uuid == null) {
return false;
}
Objects.requireNonNull(permission, "permission");
User user = getUser(uuid);
if (user == null) {
return false;
}
holderRemovePermission(user, permission, world);
return true;
}
Aggregations