Added PermissionInfo for this fucking Essentials
This commit is contained in:
parent
0d443d90f5
commit
dd8435dc4d
96
src/com/platymuus/bukkit/permissions/PermissionInfo.java
Normal file
96
src/com/platymuus/bukkit/permissions/PermissionInfo.java
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
package com.platymuus.bukkit.permissions;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class representing the global and world nodes attached to a player or
|
||||||
|
* group.
|
||||||
|
*/
|
||||||
|
public class PermissionInfo {
|
||||||
|
|
||||||
|
private final PermissionsPlugin plugin;
|
||||||
|
private final String node;
|
||||||
|
|
||||||
|
protected PermissionInfo(PermissionsPlugin plugin, String node) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.node = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of groups this group/player inherits permissions from.
|
||||||
|
*
|
||||||
|
* @return The list of groups.
|
||||||
|
*/
|
||||||
|
public List<Group> getGroups() {
|
||||||
|
ArrayList<Group> result = new ArrayList<Group>();
|
||||||
|
|
||||||
|
if (node.startsWith("users")) {
|
||||||
|
for (String key : plugin.api.getPlayerGroups(node.replace("users/", ""))) {
|
||||||
|
Group group = plugin.getGroup(key);
|
||||||
|
if (group != null) {
|
||||||
|
result.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (node.startsWith("groups")) {
|
||||||
|
for (String key : plugin.api.getGroupInheritance(node.replace("groups/", ""))) {
|
||||||
|
Group group = plugin.getGroup(key);
|
||||||
|
if (group != null) {
|
||||||
|
result.add(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a map of non-world-specific permission nodes to boolean values that
|
||||||
|
* this group/player defines.
|
||||||
|
*
|
||||||
|
* @return The map of permissions.
|
||||||
|
*/
|
||||||
|
public Map<String, Boolean> getPermissions() {
|
||||||
|
if (node.startsWith("users")) {
|
||||||
|
return plugin.api.getPlayerPermissions(node.replace("users/", ""));
|
||||||
|
} else if (node.startsWith("groups")) {
|
||||||
|
return plugin.api.getGroupPermissions(node.replace("groups/", ""));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of worlds this group/player defines world-specific
|
||||||
|
* permissions for.
|
||||||
|
*
|
||||||
|
* @return The list of worlds.
|
||||||
|
*/
|
||||||
|
public Set<String> getWorlds() {
|
||||||
|
if (node.startsWith("users")) {
|
||||||
|
return new HashSet<String>(plugin.api.getPlayerWorlds(node.replace("users/", "")));
|
||||||
|
} else if (node.startsWith("groups")) {
|
||||||
|
return new HashSet<String>(plugin.api.getGroupWorlds(node.replace("groups/", "")));
|
||||||
|
} else {
|
||||||
|
return new HashSet<String>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a map of world-specific permission nodes to boolean values that this
|
||||||
|
* group/player defines.
|
||||||
|
*
|
||||||
|
* @param world
|
||||||
|
* The name of the world.
|
||||||
|
* @return The map of permissions.
|
||||||
|
*/
|
||||||
|
public Map<String, Boolean> getWorldPermissions(String world) {
|
||||||
|
if (node.startsWith("users")) {
|
||||||
|
return plugin.api.getPlayerPermissions(node.replace("users/", ""), world);
|
||||||
|
} else if (node.startsWith("groups")) {
|
||||||
|
return plugin.api.getGroupPermissions(node.replace("groups/", ""), world);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,7 +19,8 @@ public class PermissionsPlugin extends JavaPlugin {
|
|||||||
// -- Basic stuff
|
// -- Basic stuff
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
api = ((SimplyPlugin) getServer().getPluginManager().getPlugin("SimplyPerms")).getAPI();
|
api = ((SimplyPlugin) getServer().getPluginManager().getPlugin(
|
||||||
|
"SimplyPerms")).getAPI();
|
||||||
|
|
||||||
// How are you gentlemen
|
// How are you gentlemen
|
||||||
getLogger().info("SimplyWrapper successfully enabled !");
|
getLogger().info("SimplyWrapper successfully enabled !");
|
||||||
@ -32,7 +33,8 @@ public class PermissionsPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
return getServer().getPluginManager().getPlugin("SimplyPerms").getConfig();
|
return getServer().getPluginManager().getPlugin("SimplyPerms")
|
||||||
|
.getConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- External API
|
// -- External API
|
||||||
@ -40,7 +42,7 @@ public class PermissionsPlugin extends JavaPlugin {
|
|||||||
* Get the group with the given name.
|
* Get the group with the given name.
|
||||||
*
|
*
|
||||||
* @param groupName
|
* @param groupName
|
||||||
* The name of the group.
|
* The name of the group.
|
||||||
* @return A Group if it exists or null otherwise.
|
* @return A Group if it exists or null otherwise.
|
||||||
*/
|
*/
|
||||||
public Group getGroup(String groupName) {
|
public Group getGroup(String groupName) {
|
||||||
@ -54,7 +56,7 @@ public class PermissionsPlugin extends JavaPlugin {
|
|||||||
* Returns a list of groups a player is in.
|
* Returns a list of groups a player is in.
|
||||||
*
|
*
|
||||||
* @param playerName
|
* @param playerName
|
||||||
* The name of the player.
|
* The name of the player.
|
||||||
* @return The groups this player is in. May be empty.
|
* @return The groups this player is in. May be empty.
|
||||||
*/
|
*/
|
||||||
public List<Group> getGroups(String playerName) {
|
public List<Group> getGroups(String playerName) {
|
||||||
@ -69,6 +71,21 @@ public class PermissionsPlugin extends JavaPlugin {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns permission info on the given player.
|
||||||
|
*
|
||||||
|
* @param playerName
|
||||||
|
* The name of the player.
|
||||||
|
* @return A PermissionsInfo about this player.
|
||||||
|
*/
|
||||||
|
public PermissionInfo getPlayerInfo(String playerName) {
|
||||||
|
if (!api.isPlayerInDB(playerName)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return new PermissionInfo(this, "users/" + playerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all defined groups.
|
* Returns a list of all defined groups.
|
||||||
*
|
*
|
||||||
|
@ -4,5 +4,5 @@ main: com.platymuus.bukkit.permissions.PermissionsPlugin
|
|||||||
author: Xefir Destiny
|
author: Xefir Destiny
|
||||||
website: http://dev.bukkit.org/server-mods/simplyperms/
|
website: http://dev.bukkit.org/server-mods/simplyperms/
|
||||||
description: Wrapper for SimplyPerms to keep compatibility with old PermissionsBukkit based plugins
|
description: Wrapper for SimplyPerms to keep compatibility with old PermissionsBukkit based plugins
|
||||||
version: 1.1
|
version: 1.2
|
||||||
depend: [ SimplyPerms ]
|
depend: [ SimplyPerms ]
|
||||||
|
Loading…
Reference in New Issue
Block a user