use of ru.tehkode.permissions.PermissionManager in project Towny by ElgarL.
the class PEXSource method getGroupPermissionIntNode.
/**
* @param playerName
* @param node
* @return -1 = can't find
*/
@Override
public int getGroupPermissionIntNode(String playerName, String node) {
int iReturn = -1;
Player player = BukkitTools.getPlayer(playerName);
String worldName = player.getWorld().getName();
PermissionManager pexPM = PermissionsEx.getPermissionManager();
String result = pexPM.getUser(player).getOption(node, worldName);
try {
iReturn = Integer.parseInt(result);
} catch (NumberFormatException e) {
}
if (iReturn == -1)
iReturn = getEffectivePermIntNode(playerName, node);
return iReturn;
}
use of ru.tehkode.permissions.PermissionManager in project Towny by ElgarL.
the class PEXSource method getPlayerPermissionStringNode.
/**
* @param playerName
* @param node
* @return empty = can't find
*/
@Override
public String getPlayerPermissionStringNode(String playerName, String node) {
Player player = BukkitTools.getPlayer(playerName);
String worldName = player.getWorld().getName();
PermissionManager pexPM = PermissionsEx.getPermissionManager();
// return pexPM.getUser(player).getOptionInteger(node, worldName, -1);
String result = pexPM.getUser(player).getOption(node, worldName);
if (result != null)
return result;
return "";
}
use of ru.tehkode.permissions.PermissionManager 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 ru.tehkode.permissions.PermissionManager in project Towny by ElgarL.
the class PEXSource method getPrefixSuffix.
/**
* getPermissionNode
*
* returns the specified prefix/suffix nodes from permissionsEX
*
* @param resident
* @param node
* @return String of the prefix or suffix
*/
@Override
public String getPrefixSuffix(Resident resident, String node) {
String group = "", user = "";
Player player = BukkitTools.getPlayer(resident.getName());
PermissionManager pexPM = PermissionsEx.getPermissionManager();
if (node == "prefix") {
group = pexPM.getUser(player).getPrefix(player.getWorld().getName());
user = pexPM.getUser(player).getOwnPrefix();
} else if (node == "suffix") {
group = pexPM.getUser(player).getSuffix(player.getWorld().getName());
user = pexPM.getUser(player).getOwnSuffix();
}
if (group == null)
group = "";
if (user == null)
user = "";
if (!group.equals(user))
user = group + user;
user = TownySettings.parseSingleLineString(user);
return user;
}
Aggregations