Merge branch 'master' of github.com:MilkBowl/Vault

This commit is contained in:
Morgan 2011-07-18 12:35:28 -04:00
commit 4ad44bb1c1
3 changed files with 303 additions and 273 deletions

View File

@ -276,4 +276,13 @@ public interface Permission {
*/ */
public void setGroupInfoString(String world, String groupName, String node, String value); public void setGroupInfoString(String world, String groupName, String node, String value);
/**
* Gets the list of groups that this player has
*
* @param world Name of World
* @param playerName Name of Player
*/
public String[] getPlayerGroups(String world, String playerName);
public String getPrimaryGroup(String world, String playerName);
} }

View File

@ -338,4 +338,13 @@ public class Permission_Permissions implements Permission {
return false; return false;
} }
} }
@Override
public String[] getPlayerGroups(String world, String playerName) {
return this.permission.getHandler().getGroups(world, playerName);
}
public String getPrimaryGroup(String world, String playerName) {
return this.permission.getHandler().getPrimaryGroup(world, playerName);
}
} }

View File

@ -38,314 +38,326 @@ import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx; import ru.tehkode.permissions.bukkit.PermissionsEx;
public class Permission_PermissionsEx implements Permission { public class Permission_PermissionsEx implements Permission {
private static final Logger log = Logger.getLogger("Minecraft"); private static final Logger log = Logger.getLogger("Minecraft");
private String name = "PermissionsEx";
private Plugin plugin = null;
private PluginManager pluginManager = null;
private PermissionsEx permission = null;
private PermissionServerListener permissionServerListener = null;
public Permission_PermissionsEx(Plugin plugin) { private String name = "PermissionsEx";
this.plugin = plugin; private Plugin plugin = null;
pluginManager = this.plugin.getServer().getPluginManager(); private PluginManager pluginManager = null;
private PermissionsEx permission = null;
private PermissionServerListener permissionServerListener = null;
permissionServerListener = new PermissionServerListener(this); public Permission_PermissionsEx(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin); permissionServerListener = new PermissionServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
if (permission == null) { this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
if (perms != null) {
if (perms.isEnabled()) {
permission = (PermissionsEx) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
}
@Override // Load Plugin in case it was loaded before
public boolean isEnabled() { if (permission == null) {
if(permission == null) { Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
return false; if (perms != null) {
} else { if (perms.isEnabled()) {
return permission.isEnabled(); permission = (PermissionsEx) perms;
} log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
} }
}
@Override }
public boolean has(Player player, String permission) { }
return playerHas(player, permission);
}
@Override @Override
public boolean playerHas(Player player, String permission) { public boolean isEnabled() {
return this.permission.has(player, permission); if(permission == null) {
} return false;
} else {
return permission.isEnabled();
}
}
@Override @Override
public boolean playerInGroup(String worldName, String playerName, String groupName) { public boolean has(Player player, String permission) {
//Try catch the check because we don't know if the objects will actually exist Good Job on the crap Permissions plugin, why do we support this again? return playerHas(player, permission);
try { }
PermissionUser[] userList = PermissionsEx.getPermissionManager().getGroup(groupName).getUsers();
for (PermissionUser user : userList) {
if (user.getName() == playerName)
return true;
else
return false;
}
} catch (Exception e) {
return false;
}
return false;
}
private class PermissionServerListener extends ServerListener { @Override
Permission_PermissionsEx permission = null; public boolean playerHas(Player player, String permission) {
return this.permission.has(player, permission);
}
public PermissionServerListener(Permission_PermissionsEx permission) { @Override
this.permission = permission; public boolean playerInGroup(String worldName, String playerName, String groupName) {
} //Try catch the check because we don't know if the objects will actually exist Good Job on the crap Permissions plugin, why do we support this again?
try {
PermissionUser[] userList = PermissionsEx.getPermissionManager().getGroup(groupName).getUsers();
for (PermissionUser user : userList) {
if (user.getName() == playerName)
return true;
else
return false;
}
} catch (Exception e) {
return false;
}
return false;
}
public void onPluginEnable(PluginEnableEvent event) { private class PermissionServerListener extends ServerListener {
if (permission.permission == null) { Permission_PermissionsEx permission = null;
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
if (perms != null) { public PermissionServerListener(Permission_PermissionsEx permission) {
if (perms.isEnabled()) { this.permission = permission;
permission.permission = (PermissionsEx) perms; }
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
public void onPluginDisable(PluginDisableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
if (permission.permission != null) { if (permission.permission == null) {
if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) { Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
permission.permission = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override if (perms != null) {
public String getName() { if (perms.isEnabled()) {
return name; permission.permission = (PermissionsEx) perms;
} log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override public void onPluginDisable(PluginDisableEvent event) {
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) { if (permission.permission != null) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionInteger(node, world, defaultValue); if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) {
} permission.permission = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override @Override
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) { public String getName() {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionDouble(node, world, defaultValue); return name;
} }
@Override @Override
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) { public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionBoolean(node, world, defaultValue); return PermissionsEx.getPermissionManager().getUser(playerName).getOptionInteger(node, world, defaultValue);
} }
@Override @Override
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) { public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOption(node, world, defaultValue); return PermissionsEx.getPermissionManager().getUser(playerName).getOptionDouble(node, world, defaultValue);
} }
@Override @Override
public boolean playerAddGroup(String worldName, String playerName, String groupName) { public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); return PermissionsEx.getPermissionManager().getUser(playerName).getOptionBoolean(node, world, defaultValue);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); }
if(group == null || user == null) {
return false;
} else {
user.addGroup(group);
return true;
}
}
@Override @Override
public boolean playerRemoveGroup(String worldName, String playerName, String groupName) { public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); return PermissionsEx.getPermissionManager().getUser(playerName).getOption(node, world, defaultValue);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); }
if(group == null || user == null) {
return false;
} else {
user.removeGroup(group);
return true;
}
}
@Override @Override
public boolean playerAdd(String worldName, String playerName, String permission) { public boolean playerAddGroup(String worldName, String playerName, String groupName) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(user == null) { PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
return false; if(group == null || user == null) {
} else { return false;
user.addPermission(permission, worldName); } else {
return true; user.addGroup(group);
} return true;
} }
}
@Override @Override
public boolean playerRemove(String worldName, String playerName, String permission) { public boolean playerRemoveGroup(String worldName, String playerName, String groupName) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(user == null) { PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
return false; if(group == null || user == null) {
} else { return false;
user.removePermission(permission, worldName); } else {
return true; user.removeGroup(group);
} return true;
} }
}
@Override @Override
public boolean groupAdd(String worldName, String groupName, String permission) { public boolean playerAdd(String worldName, String playerName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null) { if(user == null) {
return false; return false;
} else { } else {
group.addPermission(permission, worldName); user.addPermission(permission, worldName);
return true; return true;
} }
} }
@Override @Override
public boolean groupRemove(String worldName, String groupName, String permission) { public boolean playerRemove(String worldName, String playerName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null) { if(user == null) {
return false; return false;
} else { } else {
group.removePermission(permission, worldName); user.removePermission(permission, worldName);
return true; return true;
} }
} }
@Override @Override
public void setPlayerInfoInteger(String world, String playerName, String node, int value) { public boolean groupAdd(String worldName, String groupName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(user != null) { if(group == null) {
user.setOption(node, String.valueOf(value), world); return false;
} } else {
} group.addPermission(permission, worldName);
return true;
}
}
@Override @Override
public void setPlayerInfoDouble(String world, String playerName, String node, double value) { public boolean groupRemove(String worldName, String groupName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(user != null) { if(group == null) {
user.setOption(node, String.valueOf(value), world); return false;
} } else {
} group.removePermission(permission, worldName);
return true;
}
}
@Override @Override
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) { public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) { if(user != null) {
user.setOption(node, String.valueOf(value), world); user.setOption(node, String.valueOf(value), world);
} }
} }
@Override @Override
public void setPlayerInfoString(String world, String playerName, String node, String value) { public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName); PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) { if(user != null) {
user.setOption(node, String.valueOf(value), world); user.setOption(node, String.valueOf(value), world);
} }
} }
@Override @Override
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) { public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null) { if(user != null) {
return defaultValue; user.setOption(node, String.valueOf(value), world);
} else { }
return group.getOptionInteger(node, world, defaultValue); }
}
}
@Override @Override
public void setGroupInfoInteger(String world, String groupName, String node, int value) { public void setPlayerInfoString(String world, String playerName, String node, String value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null) { if(user != null) {
return; user.setOption(node, String.valueOf(value), world);
} else { }
group.setOption(node, world, String.valueOf(value)); }
}
}
@Override @Override
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) { public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return defaultValue; return defaultValue;
} else { } else {
return group.getOptionDouble(node, world, defaultValue); return group.getOptionInteger(node, world, defaultValue);
} }
} }
@Override @Override
public void setGroupInfoDouble(String world, String groupName, String node, double value) { public void setGroupInfoInteger(String world, String groupName, String node, int value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return; return;
} else { } else {
group.setOption(node, world, String.valueOf(value)); group.setOption(node, world, String.valueOf(value));
} }
} }
@Override @Override
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) { public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return defaultValue; return defaultValue;
} else { } else {
return group.getOptionBoolean(node, world, defaultValue); return group.getOptionDouble(node, world, defaultValue);
} }
} }
@Override @Override
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) { public void setGroupInfoDouble(String world, String groupName, String node, double value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return; return;
} else { } else {
group.setOption(node, world, String.valueOf(value)); group.setOption(node, world, String.valueOf(value));
} }
} }
@Override @Override
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) { public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return defaultValue; return defaultValue;
} else { } else {
return group.getOption(node, world, defaultValue); return group.getOptionBoolean(node, world, defaultValue);
} }
} }
@Override @Override
public void setGroupInfoString(String world, String groupName, String node, String value) { public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return; return;
} else { } else {
group.setOption(node, world, value); group.setOption(node, world, String.valueOf(value));
} }
} }
@Override @Override
public boolean groupHas(String worldName, String groupName, String permission) { public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName); PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) { if(group == null) {
return false; return defaultValue;
} else { } else {
return group.has(permission, worldName); return group.getOption(node, world, defaultValue);
} }
} }
@Override
public void setGroupInfoString(String world, String groupName, String node, String value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, value);
}
}
@Override
public boolean groupHas(String worldName, String groupName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return false;
} else {
return group.has(permission, worldName);
}
}
@Override
public String[] getPlayerGroups(String world, String playerName) {
return PermissionsEx.getPermissionManager().getUser(playerName).getGroupsNames();
}
@Override
public String getPrimaryGroup(String world, String playerName) {
if (PermissionsEx.getPermissionManager().getUser(playerName).getGroupsNames().length > 0)
return PermissionsEx.getPermissionManager().getUser(playerName).getGroupsNames()[0];
else
return null;
}
} }