Null support for getPrimaryGroup.

This commit is contained in:
Sleaker 2011-07-11 10:59:02 -07:00
parent 027a493fc7
commit 9a41f10e00

View File

@ -38,315 +38,315 @@ import ru.tehkode.permissions.PermissionUser;
import ru.tehkode.permissions.bukkit.PermissionsEx;
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;
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) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
public Permission_PermissionsEx(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
permissionServerListener = new PermissionServerListener(this);
permissionServerListener = new PermissionServerListener(this);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
this.pluginManager.registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
// Load Plugin in case it was loaded before
if (permission == null) {
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));
}
}
}
}
// Load Plugin in case it was loaded before
if (permission == null) {
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
public boolean isEnabled() {
if(permission == null) {
return false;
} else {
return permission.isEnabled();
}
}
@Override
public boolean isEnabled() {
if(permission == null) {
return false;
} else {
return permission.isEnabled();
}
}
@Override
public boolean has(Player player, String permission) {
return playerHas(player, permission);
}
@Override
public boolean has(Player player, String permission) {
return playerHas(player, permission);
}
@Override
public boolean playerHas(Player player, String permission) {
return this.permission.has(player, permission);
}
@Override
public boolean playerHas(Player player, String permission) {
return this.permission.has(player, permission);
}
@Override
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;
}
@Override
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;
}
private class PermissionServerListener extends ServerListener {
Permission_PermissionsEx permission = null;
private class PermissionServerListener extends ServerListener {
Permission_PermissionsEx permission = null;
public PermissionServerListener(Permission_PermissionsEx permission) {
this.permission = permission;
}
public PermissionServerListener(Permission_PermissionsEx permission) {
this.permission = permission;
}
public void onPluginEnable(PluginEnableEvent event) {
if (permission.permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
public void onPluginEnable(PluginEnableEvent event) {
if (permission.permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsEx");
if (perms != null) {
if (perms.isEnabled()) {
permission.permission = (PermissionsEx) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
if (perms != null) {
if (perms.isEnabled()) {
permission.permission = (PermissionsEx) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (permission.permission != null) {
if (event.getPlugin().getDescription().getName().equals("PermissionsEx")) {
permission.permission = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
public void onPluginDisable(PluginDisableEvent event) {
if (permission.permission != null) {
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
public String getName() {
return name;
}
@Override
public String getName() {
return name;
}
@Override
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionInteger(node, world, defaultValue);
}
@Override
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionInteger(node, world, defaultValue);
}
@Override
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionDouble(node, world, defaultValue);
}
@Override
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionDouble(node, world, defaultValue);
}
@Override
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionBoolean(node, world, defaultValue);
}
@Override
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOptionBoolean(node, world, defaultValue);
}
@Override
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOption(node, world, defaultValue);
}
@Override
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
return PermissionsEx.getPermissionManager().getUser(playerName).getOption(node, world, defaultValue);
}
@Override
public boolean playerAddGroup(String worldName, String playerName, String groupName) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null || user == null) {
return false;
} else {
user.addGroup(group);
return true;
}
}
@Override
public boolean playerAddGroup(String worldName, String playerName, String groupName) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null || user == null) {
return false;
} else {
user.addGroup(group);
return true;
}
}
@Override
public boolean playerRemoveGroup(String worldName, String playerName, String groupName) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null || user == null) {
return false;
} else {
user.removeGroup(group);
return true;
}
}
@Override
public boolean playerRemoveGroup(String worldName, String playerName, String groupName) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(group == null || user == null) {
return false;
} else {
user.removeGroup(group);
return true;
}
}
@Override
public boolean playerAdd(String worldName, String playerName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user == null) {
return false;
} else {
user.addPermission(permission, worldName);
return true;
}
}
@Override
public boolean playerAdd(String worldName, String playerName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user == null) {
return false;
} else {
user.addPermission(permission, worldName);
return true;
}
}
@Override
public boolean playerRemove(String worldName, String playerName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user == null) {
return false;
} else {
user.removePermission(permission, worldName);
return true;
}
}
@Override
public boolean playerRemove(String worldName, String playerName, String permission) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user == null) {
return false;
} else {
user.removePermission(permission, worldName);
return true;
}
}
@Override
public boolean groupAdd(String worldName, String groupName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return false;
} else {
group.addPermission(permission, worldName);
return true;
}
}
@Override
public boolean groupAdd(String worldName, String groupName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return false;
} else {
group.addPermission(permission, worldName);
return true;
}
}
@Override
public boolean groupRemove(String worldName, String groupName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return false;
} else {
group.removePermission(permission, worldName);
return true;
}
}
@Override
public boolean groupRemove(String worldName, String groupName, String permission) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return false;
} else {
group.removePermission(permission, worldName);
return true;
}
}
@Override
public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoString(String world, String playerName, String node, String value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public void setPlayerInfoString(String world, String playerName, String node, String value) {
PermissionUser user = PermissionsEx.getPermissionManager().getUser(playerName);
if(user != null) {
user.setOption(node, String.valueOf(value), world);
}
}
@Override
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOptionInteger(node, world, defaultValue);
}
}
@Override
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOptionInteger(node, world, defaultValue);
}
}
@Override
public void setGroupInfoInteger(String world, String groupName, String node, int value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, String.valueOf(value));
}
}
@Override
public void setGroupInfoInteger(String world, String groupName, String node, int value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, String.valueOf(value));
}
}
@Override
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOptionDouble(node, world, defaultValue);
}
}
@Override
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOptionDouble(node, world, defaultValue);
}
}
@Override
public void setGroupInfoDouble(String world, String groupName, String node, double value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, String.valueOf(value));
}
}
@Override
public void setGroupInfoDouble(String world, String groupName, String node, double value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, String.valueOf(value));
}
}
@Override
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOptionBoolean(node, world, defaultValue);
}
}
@Override
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOptionBoolean(node, world, defaultValue);
}
}
@Override
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, String.valueOf(value));
}
}
@Override
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return;
} else {
group.setOption(node, world, String.valueOf(value));
}
}
@Override
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
return group.getOption(node, world, defaultValue);
}
}
@Override
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
PermissionGroup group = PermissionsEx.getPermissionManager().getGroup(groupName);
if(group == null) {
return defaultValue;
} else {
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 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 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) {
@ -355,6 +355,9 @@ public class Permission_PermissionsEx implements Permission {
@Override
public String getPrimaryGroup(String world, String playerName) {
return PermissionsEx.getPermissionManager().getUser(playerName).getGroupsNames()[0];
if (PermissionsEx.getPermissionManager().getUser(playerName).getGroupsNames().length > 0)
return PermissionsEx.getPermissionManager().getUser(playerName).getGroupsNames()[0];
else
return null;
}
}