use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.
the class DefaultPermissions method registerCorePermissions.
public static void registerCorePermissions() {
Permission parent = registerPermission(ROOT, "Gives the user the ability to use all CraftBukkit utilities and commands");
CommandPermissions.registerPermissions(parent);
BroadcastPermissions.registerPermissions(parent);
parent.recalculatePermissibles();
}
use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.
the class DefaultPermissions method registerPermission.
public static Permission registerPermission(String name, String desc, Permission parent) {
Permission perm = registerPermission(name, desc);
parent.getChildren().put(perm.getName(), true);
return perm;
}
use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.
the class DefaultPermissions method registerPermission.
public static Permission registerPermission(String name, String desc, PermissionDefault def, Permission parent) {
Permission perm = registerPermission(name, desc, def);
parent.getChildren().put(perm.getName(), true);
return perm;
}
use of org.bukkit.permissions.Permission in project Bukkit by Bukkit.
the class PluginManagerTest method testRemovePermissionByPermission.
private void testRemovePermissionByPermission(final String name) {
final Permission perm = new Permission(name);
pm.addPermission(perm);
assertThat("Permission \"" + name + "\" was not added", pm.getPermission(name), is(perm));
pm.removePermission(perm);
assertThat("Permission \"" + name + "\" was not removed", pm.getPermission(name), is(nullValue()));
}
use of org.bukkit.permissions.Permission in project Jobs by GamingMesh.
the class PermissionHandler method recalculatePermissions.
public void recalculatePermissions(JobsPlayer jPlayer) {
Player player = plugin.getServer().getPlayer(jPlayer.getPlayerUUID());
if (player == null)
return;
boolean changed = false;
// remove old permissions
String permName = "jobs.players." + player.getName();
Permission permission = plugin.getServer().getPluginManager().getPermission(permName);
if (permission != null) {
plugin.getServer().getPluginManager().removePermission(permission);
changed = true;
}
// Permissions should only apply if we have permission to use jobs in this world
if (hasWorldPermission(player, player.getWorld().getName())) {
List<JobProgression> progression = jPlayer.getJobProgression();
// calculate new permissions
HashMap<String, Boolean> permissions = new HashMap<String, Boolean>();
if (progression.size() == 0) {
Job job = Jobs.getNoneJob();
if (job != null) {
for (JobPermission perm : job.getPermissions()) {
if (perm.getLevelRequirement() <= 0) {
if (perm.getValue()) {
permissions.put(perm.getNode(), true);
} else {
/*
* If the key exists, don't put a false node in
* This is in case we already have a true node there
*/
if (!permissions.containsKey(perm.getNode())) {
permissions.put(perm.getNode(), false);
}
}
}
}
}
} else {
for (JobProgression prog : progression) {
for (JobPermission perm : prog.getJob().getPermissions()) {
if (prog.getLevel() >= perm.getLevelRequirement()) {
/*
* If the key exists, don't put a false node in
* This is in case we already have a true node there
*/
if (perm.getValue()) {
permissions.put(perm.getNode(), true);
} else {
if (!permissions.containsKey(perm.getNode())) {
permissions.put(perm.getNode(), false);
}
}
}
}
}
}
// add new permissions (if applicable)
if (permissions.size() > 0) {
plugin.getServer().getPluginManager().addPermission(new Permission(permName, PermissionDefault.FALSE, permissions));
changed = true;
}
}
// If the permissions changed, recalculate them
if (!changed)
return;
// find old attachment
PermissionAttachment attachment = null;
for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
if (pai.getAttachment() != null && pai.getAttachment().getPlugin() instanceof JobsPlugin) {
attachment = pai.getAttachment();
}
}
// create if attachment doesn't exist
if (attachment == null) {
attachment = player.addAttachment(plugin);
attachment.setPermission(permName, true);
}
// recalculate!
player.recalculatePermissions();
}
Aggregations