update GM hooking.

This commit is contained in:
Sleaker 2012-02-08 22:04:42 -08:00
parent a56e4808b9
commit 7c23cb38d3

View File

@ -30,7 +30,6 @@ public class Permission_GroupManager extends Permission {
private GroupManager groupManager; private GroupManager groupManager;
private AnjoPermissionsHandler perms; private AnjoPermissionsHandler perms;
@SuppressWarnings("deprecation")
public Permission_GroupManager(Vault plugin) { public Permission_GroupManager(Vault plugin) {
this.plugin = plugin; this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin); Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
@ -41,7 +40,6 @@ public class Permission_GroupManager extends Permission {
if (perms != null) { if (perms != null) {
if (perms.isEnabled()) { if (perms.isEnabled()) {
groupManager = (GroupManager) perms; groupManager = (GroupManager) perms;
this.perms = groupManager.getPermissionHandler();
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name)); log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
} }
} }
@ -55,7 +53,6 @@ public class Permission_GroupManager extends Permission {
this.permission = permission; this.permission = permission;
} }
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
if (permission.groupManager == null) { if (permission.groupManager == null) {
@ -64,7 +61,6 @@ public class Permission_GroupManager extends Permission {
if (perms != null) { if (perms != null) {
if (perms.isEnabled()) { if (perms.isEnabled()) {
permission.groupManager = (GroupManager) perms; permission.groupManager = (GroupManager) perms;
permission.perms = groupManager.getPermissionHandler();
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name)); log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
} }
} }
@ -76,7 +72,6 @@ public class Permission_GroupManager extends Permission {
if (permission.groupManager != null) { if (permission.groupManager != null) {
if (event.getPlugin().getDescription().getName().equals("GroupManager")) { if (event.getPlugin().getDescription().getName().equals("GroupManager")) {
permission.groupManager = null; permission.groupManager = null;
permission.perms = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name)); log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
} }
} }
@ -90,33 +85,44 @@ public class Permission_GroupManager extends Permission {
@Override @Override
public boolean isEnabled() { public boolean isEnabled() {
if (groupManager == null) { return groupManager != null && groupManager.isEnabled();
return false;
} else {
return groupManager.isEnabled();
}
} }
@Override @Override
public boolean playerHas(String worldName, String playerName, String permission) { public boolean playerHas(String worldName, String playerName, String permission) {
Player p = plugin.getServer().getPlayer(playerName); OverloadedWorldHolder owh;
if (p != null) { if (worldName == null) {
if (p.hasPermission(permission)) owh = groupManager.getWorldsHolder().getDefaultWorld();
return true; }
} else {
return perms.has(plugin.getServer().getPlayer(playerName), permission); owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return false;
}
User user = owh.getUser(playerName);
if (user == null) {
return false;
} else {
return user.hasSamePermissionNode(permission);
}
} }
@Override @Override
public boolean playerAdd(String worldName, String playerName, String permission) { public boolean playerAdd(String worldName, String playerName, String permission) {
OverloadedWorldHolder owh = groupManager.getWorldsHolder().getWorldData(worldName); OverloadedWorldHolder owh;
if (worldName == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) { if (owh == null) {
return false; return false;
} }
User user = owh.getUser(playerName); User user = owh.getUser(playerName);
if (user == null) { if (user == null) {
return false; return false;
} }
user.addPermission(permission); user.addPermission(permission);
@ -125,14 +131,19 @@ public class Permission_GroupManager extends Permission {
@Override @Override
public boolean playerRemove(String worldName, String playerName, String permission) { public boolean playerRemove(String worldName, String playerName, String permission) {
OverloadedWorldHolder owh = groupManager.getWorldsHolder().getWorldData(worldName); OverloadedWorldHolder owh;
if (worldName == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
} else {
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) { if (owh == null) {
return false; return false;
} }
User user = owh.getUser(playerName); User user = owh.getUser(playerName);
if (user == null) { if (user == null) {
return false; return false;
} }
user.removePermission(permission); user.removePermission(permission);
@ -141,54 +152,83 @@ public class Permission_GroupManager extends Permission {
@Override @Override
public boolean groupHas(String worldName, String groupName, String permission) { public boolean groupHas(String worldName, String groupName, String permission) {
OverloadedWorldHolder owh = groupManager.getWorldsHolder().getWorldData(worldName); OverloadedWorldHolder owh;
if (owh == null) { if (worldName == null) {
return false; owh = groupManager.getWorldsHolder().getDefaultWorld();
} } else {
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return false;
}
Group group = owh.getGroup(groupName); Group group = owh.getGroup(groupName);
if (group == null) { if (group == null) {
return false; return false;
} }
return group.hasSamePermissionNode(permission); return group.hasSamePermissionNode(permission);
} }
@Override @Override
public boolean groupAdd(String worldName, String groupName, String permission) { public boolean groupAdd(String worldName, String groupName, String permission) {
OverloadedWorldHolder owh = groupManager.getWorldsHolder().getWorldData(worldName); OverloadedWorldHolder owh;
if (owh == null) { if (worldName == null) {
return false; owh = groupManager.getWorldsHolder().getDefaultWorld();
} } else {
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return false;
}
Group group = owh.getGroup(groupName); Group group = owh.getGroup(groupName);
if (group == null) { if (group == null) {
return false; return false;
} }
group.addPermission(permission); group.addPermission(permission);
return true; return true;
} }
@Override @Override
public boolean groupRemove(String worldName, String groupName, String permission) { public boolean groupRemove(String worldName, String groupName, String permission) {
OverloadedWorldHolder owh = groupManager.getWorldsHolder().getWorldData(worldName); OverloadedWorldHolder owh;
if (owh == null) { if (worldName == null) {
return false; owh = groupManager.getWorldsHolder().getDefaultWorld();
} } else {
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return false;
}
Group group = owh.getGroup(groupName); Group group = owh.getGroup(groupName);
if (group == null) { if (group == null) {
return false; return false;
} }
group.removePermission(permission); group.removePermission(permission);
return true; return true;
} }
@Override @Override
public boolean playerInGroup(String worldName, String playerName, String groupName) { public boolean playerInGroup(String worldName, String playerName, String groupName) {
return perms.inGroup(playerName, groupName); OverloadedWorldHolder owh;
if (worldName == null) {
owh = groupManager.getWorldsHolder().getWorldDataByPlayerName(playerName);
}
else {
owh = groupManager.getWorldsHolder().getWorldData(worldName);
}
if (owh == null) {
return false;
}
User user = owh.getUser(playerName);
if (user == null) {
return false;
}
return user.getGroup().getName().equalsIgnoreCase(groupName) || user.subGroupListStringCopy().contains(groupName);
} }
@Override @Override
@ -261,58 +301,58 @@ public class Permission_GroupManager extends Permission {
@Override @Override
public boolean playerAddTransient(String world, String player, String permission) { public boolean playerAddTransient(String world, String player, String permission) {
if (world != null) { if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!"); throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
} }
Player p = plugin.getServer().getPlayer(player); Player p = plugin.getServer().getPlayer(player);
if (p == null) { if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
} }
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) { for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) { if (paInfo.getAttachment().getPlugin().equals(plugin)) {
paInfo.getAttachment().setPermission(permission, true); paInfo.getAttachment().setPermission(permission, true);
return true; return true;
} }
} }
PermissionAttachment attach = p.addAttachment(plugin); PermissionAttachment attach = p.addAttachment(plugin);
attach.setPermission(permission, true); attach.setPermission(permission, true);
return true; return true;
} }
@Override @Override
public boolean playerRemoveTransient(String world, String player, String permission) { public boolean playerRemoveTransient(String world, String player, String permission) {
if (world != null) { if (world != null) {
throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!"); throw new UnsupportedOperationException(getName() + " does not support World based transient permissions!");
} }
Player p = plugin.getServer().getPlayer(player); Player p = plugin.getServer().getPlayer(player);
if (p == null) { if (p == null) {
throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!");
} }
for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) { for (PermissionAttachmentInfo paInfo : p.getEffectivePermissions()) {
if (paInfo.getAttachment().getPlugin().equals(plugin)) { if (paInfo.getAttachment().getPlugin().equals(plugin)) {
return paInfo.getAttachment().getPermissions().remove(permission); return paInfo.getAttachment().getPermissions().remove(permission);
} }
} }
return false; return false;
} }
@Override @Override
public String[] getGroups() { public String[] getGroups() {
Set<String> groupNames = new HashSet<String>(); Set<String> groupNames = new HashSet<String>();
for (World world : Bukkit.getServer().getWorlds()) { for (World world : Bukkit.getServer().getWorlds()) {
Collection<Group> groups = groupManager.getWorldsHolder().getWorldData(world.getName()).getGroupList(); Collection<Group> groups = groupManager.getWorldsHolder().getWorldData(world.getName()).getGroupList();
for (Group group : groups) { for (Group group : groups) {
groupNames.add(group.getName()); groupNames.add(group.getName());
} }
} }
return groupNames.toArray(new String[0]); return groupNames.toArray(new String[0]);
} }
@Override @Override
public boolean hasSuperPermsCompat() { public boolean hasSuperPermsCompat() {
return true; return true;
} }
} }