toLower all group/permission strings for PermBukkit implementation.

This commit is contained in:
Sleaker 2012-04-12 21:20:49 -07:00
parent 550f774d3d
commit 7fcc556774

View File

@ -35,200 +35,214 @@ import com.platymuus.bukkit.permissions.PermissionsPlugin;
public class Permission_PermissionsBukkit extends Permission {
private final String name = "PermissionsBukkit";
private PermissionsPlugin perms = null;
private final String name = "PermissionsBukkit";
private PermissionsPlugin perms = null;
public Permission_PermissionsBukkit(Vault plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
// Load Plugin in case it was loaded before
if (perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
if (perms != null) {
perms = (PermissionsPlugin) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
public Permission_PermissionsBukkit(Vault plugin) {
this.plugin = plugin;
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
public class PermissionServerListener implements Listener {
Permission_PermissionsBukkit permission = null;
// Load Plugin in case it was loaded before
if (perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
if (perms != null) {
perms = (PermissionsPlugin) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
public PermissionServerListener(Permission_PermissionsBukkit permission) {
this.permission = permission;
}
public class PermissionServerListener implements Listener {
Permission_PermissionsBukkit permission = null;
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (permission.perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
public PermissionServerListener(Permission_PermissionsBukkit permission) {
this.permission = permission;
}
if (perms != null) {
if (perms.isEnabled()) {
permission.perms = (PermissionsPlugin) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (permission.perms == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (permission.perms != null) {
if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) {
permission.perms = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
if (perms != null) {
if (perms.isEnabled()) {
permission.perms = (PermissionsPlugin) perms;
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override
public String getName() {
return name;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if (permission.perms != null) {
if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) {
permission.perms = null;
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
}
}
}
}
@Override
public boolean isEnabled() {
if (perms == null) {
return false;
} else {
return perms.isEnabled();
}
}
@Override
public String getName() {
return name;
}
@Override
public boolean playerHas(String world, String player, String permission) {
if (plugin.getServer().getPlayer(player) != null)
return plugin.getServer().getPlayer(player).hasPermission(permission);
else
return false;
}
@Override
public boolean isEnabled() {
if (perms == null) {
return false;
} else {
return perms.isEnabled();
}
}
@Override
public boolean playerAdd(String world, String player, String permission) {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player setperm " + player + " " + permission + " true");
}
@Override
public boolean playerHas(String world, String player, String permission) {
if (Bukkit.getPlayer(player) != null) {
return Bukkit.getPlayer(player).hasPermission(permission);
} else {
return false;
}
}
@Override
public boolean playerRemove(String world, String player, String permission) {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player unsetperm " + player + " " + permission);
}
@Override
public boolean playerAdd(String world, String player, String permission) {
permission = permission.toLowerCase();
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player setperm " + player + " " + permission + " true");
}
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
@Override
public boolean groupHas(String world, String group, String permission) {
if (world != null && !world.isEmpty()) {
return perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) == null ? false : perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission);
}
if (perms.getGroup(group) == null)
return false;
else if (perms.getGroup(group).getInfo() == null)
return false;
else if (perms.getGroup(group).getInfo().getPermissions() == null)
return false;
return perms.getGroup(group).getInfo().getPermissions().get(permission);
}
@Override
public boolean playerRemove(String world, String player, String permission) {
permission = permission.toLowerCase();
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player unsetperm " + player + " " + permission);
}
@Override
public boolean groupAdd(String world, String group, String permission) {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group setperm " + group + " " + permission + " true");
}
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
@Override
public boolean groupRemove(String world, String group, String permission) {
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group unsetperm " + group + " " + permission);
}
@Override
public boolean groupHas(String world, String group, String permission) {
group = group.toLowerCase();
permission = permission.toLowerCase();
@Override
public boolean playerInGroup(String world, String player, String group) {
if (world != null) {
for (Group g : perms.getPlayerInfo(player).getGroups()) {
if (g.getName().equals(group)) {
return g.getInfo().getWorlds().contains(world);
}
}
return false;
}
Group g = perms.getGroup(group);
if (g == null) {
return false;
}
return g.getPlayers().contains(player);
}
if (world != null && !world.isEmpty()) {
return perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) == null ? false : perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission);
}
if (perms.getGroup(group) == null) {
return false;
} else if (perms.getGroup(group).getInfo() == null) {
return false;
} else if (perms.getGroup(group).getInfo().getPermissions() == null) {
return false;
}
return perms.getGroup(group).getInfo().getPermissions().get(permission);
}
@Override
public boolean playerAddGroup(String world, String player, String group) {
if (world != null) {
return false;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player addgroup " + player + " " + group);
}
@Override
public boolean groupAdd(String world, String group, String permission) {
group = group.toLowerCase();
permission = permission.toLowerCase();
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group setperm " + group + " " + permission + " true");
}
@Override
public boolean playerRemoveGroup(String world, String player, String group) {
if (world != null) {
return false;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player removegroup " + player + " " + group);
}
@Override
public boolean groupRemove(String world, String group, String permission) {
group = group.toLowerCase();
permission = permission.toLowerCase();
if (world != null) {
permission = world + ":" + permission;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group unsetperm " + group + " " + permission);
}
@Override
public String[] getPlayerGroups(String world, String player) {
List<String> groupList = new ArrayList<String>();
PermissionInfo info = perms.getPlayerInfo(player);
if (world != null && info != null) {
for (Group group : perms.getPlayerInfo(player).getGroups()) {
if (group.getInfo().getWorlds().contains(world)) {
groupList.add(group.getName());
}
}
return groupList.toArray(new String[0]);
}
if (info != null) {
for (Group group : info.getGroups()) {
groupList.add(group.getName());
}
}
return groupList.toArray(new String[0]);
}
@Override
public boolean playerInGroup(String world, String player, String group) {
group = group.toLowerCase();
if (world != null) {
for (Group g : perms.getPlayerInfo(player).getGroups()) {
if (g.getName().equals(group)) {
return g.getInfo().getWorlds().contains(world);
}
}
return false;
}
Group g = perms.getGroup(group);
if (g == null) {
return false;
}
return g.getPlayers().contains(player);
}
@Override
public String getPrimaryGroup(String world, String player) {
if (perms.getPlayerInfo(player) == null)
return null;
else if (perms.getPlayerInfo(player).getGroups() != null && !perms.getPlayerInfo(player).getGroups().isEmpty() ) {
return perms.getPlayerInfo(player).getGroups().get(0).getName();
}
return null;
}
@Override
public boolean playerAddGroup(String world, String player, String group) {
group = group.toLowerCase();
if (world != null) {
return false;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player addgroup " + player + " " + group);
}
@Override
public String[] getGroups() {
List<String> groupNames = new ArrayList<String>();
for (Group group : perms.getAllGroups()) {
groupNames.add(group.getName());
}
@Override
public boolean playerRemoveGroup(String world, String player, String group) {
group = group.toLowerCase();
if (world != null) {
return false;
}
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player removegroup " + player + " " + group);
}
return groupNames.toArray(new String[0]);
}
@Override
public String[] getPlayerGroups(String world, String player) {
List<String> groupList = new ArrayList<String>();
PermissionInfo info = perms.getPlayerInfo(player);
if (world != null && info != null) {
for (Group group : perms.getPlayerInfo(player).getGroups()) {
if (group.getInfo().getWorlds().contains(world)) {
groupList.add(group.getName());
}
}
return groupList.toArray(new String[0]);
}
if (info != null) {
for (Group group : info.getGroups()) {
groupList.add(group.getName());
}
}
return groupList.toArray(new String[0]);
}
@Override
public boolean hasSuperPermsCompat() {
return true;
}
@Override
public String getPrimaryGroup(String world, String player) {
if (perms.getPlayerInfo(player) == null) {
return null;
} else if (perms.getPlayerInfo(player).getGroups() != null && !perms.getPlayerInfo(player).getGroups().isEmpty() ) {
return perms.getPlayerInfo(player).getGroups().get(0).getName();
}
return null;
}
@Override
public String[] getGroups() {
List<String> groupNames = new ArrayList<String>();
for (Group group : perms.getAllGroups()) {
groupNames.add(group.getName());
}
return groupNames.toArray(new String[0]);
}
@Override
public boolean hasSuperPermsCompat() {
return true;
}
}