Re-Added Permission2 support for legacy compatibility

This commit is contained in:
Sleaker 2011-08-09 08:43:15 -07:00
parent f0b13387b5
commit 46ad7835a4
4 changed files with 333 additions and 128 deletions

View File

@ -30,7 +30,8 @@ import net.milkbowl.vault.economy.plugins.Economy_iConomy4;
import net.milkbowl.vault.economy.plugins.Economy_iConomy5;
import net.milkbowl.vault.permission.Permission;
import net.milkbowl.vault.permission.plugins.Permission_GroupManager;
import net.milkbowl.vault.permission.plugins.Permission_Permissions;
import net.milkbowl.vault.permission.plugins.Permission_Permissions2;
import net.milkbowl.vault.permission.plugins.Permission_Permissions3;
import net.milkbowl.vault.permission.plugins.Permission_PermissionsEx;
import org.bukkit.command.Command;
@ -135,13 +136,22 @@ public class Vault extends JavaPlugin {
log.info(String.format("[%s][Permission] GroupManager not found.", getDescription().getName()));
}
// Try to load Permissions (Phoenix)
if (packageExists(new String[] { "com.nijikokun.bukkit.Permissions.Permissions" })) {
Permission nPerms = new Permission_Permissions(this);
getServer().getServicesManager().register(net.milkbowl.vault.permission.Permission.class, nPerms, this, ServicePriority.Lowest);
log.info(String.format("[%s][Permission] Permissions (Yetti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
// Try to load Permissions (Yeti)
if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) {
Permission nPerms = new Permission_Permissions3(this);
getServer().getServicesManager().register(net.milkbowl.vault.permission.Permission.class, nPerms, this, ServicePriority.Low);
log.info(String.format("[%s][Permission] Permissions (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] Permissions (Yetti) not found.", getDescription().getName()));
log.info(String.format("[%s][Permission] Permissions (Yeti) not found.", getDescription().getName()));
}
//Try to load Permissions (Phoenix)
if (packageExists(new String[] { "com.nijiko.permissions.Control"} )) {
Permission oPerms = new Permission_Permissions2(this);
getServer().getServicesManager().register(net.milkbowl.vault.permission.Permission.class, oPerms, this, ServicePriority.Lowest);
log.info(String.format("[%s][Permission] Permissions (Phoenix) found: %s", getDescription().getName(), oPerms.isEnabled() ? "Loaded" : "Waiting"));
} else {
log.info(String.format("[%s][Permission] Permissions (Phoenix) not found.", getDescription().getName()));
}

View File

@ -38,7 +38,8 @@ public abstract class Permission {
/**
* Checks if player has a permission node. (Short for playerHas(...)
* @param player Player instance
* @param worldName
* @param playerName
* @param permission Permission node
* @return Success or Failure
*/

View File

@ -0,0 +1,264 @@
package net.milkbowl.vault.permission.plugins;
import java.util.logging.Logger;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import net.milkbowl.vault.permission.Permission;
@SuppressWarnings("deprecation")
public class Permission_Permissions2 extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "Permissions (Phoenix)";
private PermissionHandler perms;
private Plugin plugin = null;
private PluginManager pluginManager = null;
private Permissions permission = null;
private PermissionServerListener permissionServerListener = null;
public Permission_Permissions2(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
permissionServerListener = new PermissionServerListener(this);
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("Permissions");
if (perms != null) {
if (perms.isEnabled() && perms.getDescription().getVersion().startsWith("2")) {
permission = (Permissions) perms;
this.perms = permission.getHandler();
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
}
}
private class PermissionServerListener extends ServerListener {
Permission_Permissions2 permission = null;
public PermissionServerListener(Permission_Permissions2 permission) {
this.permission = permission;
}
public void onPluginEnable(PluginEnableEvent event) {
if (permission.permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Permissions");
if (perms != null) {
if (perms.isEnabled()) {
permission.permission = (Permissions) 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("Permissions")) {
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 boolean isEnabled() {
if(permission == null) {
return false;
} else {
return permission.isEnabled();
}
}
@Override
public boolean playerHas(String worldName, String playerName, String permission) {
return this.perms.has(worldName, playerName, permission);
}
@Override
public boolean playerAdd(String worldName, String playerName, String permission) {
this.perms.addUserPermission(worldName, playerName, permission);
return true;
}
@Override
public boolean playerRemove(String worldName, String playerName, String permission) {
this.perms.removeUserPermission(worldName, playerName, permission);
return true;
}
@Override
public boolean groupHas(String worldName, String groupName, String permission) {
//Unable to directly check group permissions in P2
return false;
}
@Override
public boolean groupAdd(String worldName, String groupName,String permission) {
//Unable to alter group permissions in P2
return false;
}
@Override
public boolean groupRemove(String worldName, String groupName, String permission) {
//Unable to alter group permissions in P2
return false;
}
@Override
public boolean playerInGroup(String worldName, String playerName, String groupName) {
return this.perms.inGroup(worldName, playerName, groupName);
}
@Override
public boolean playerAddGroup(String worldName, String playerName, String groupName) {
//Unable to add groups in P2
return false;
}
@Override
public boolean playerRemoveGroup(String worldName, String playerName, String groupName) {
//Unable to remove groups in P2
return false;
}
@Override
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
int i = this.perms.getPermissionInteger(world, playerName, node);
return (i == -1) ? defaultValue : i;
}
@Override
public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
//Unable to set player info nodes in P2
}
public void setGroupInfo(String world, String groupName, String node, Object value) {
this.perms.addGroupInfo(world, groupName, node, value);
}
@Override
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
int i = this.perms.getGroupPermissionInteger(world, groupName, node);
return (i == -1) ? defaultValue : i;
}
@Override
public void setGroupInfoInteger(String world, String groupName, String node, int value) {
setGroupInfo(world, groupName, node, value);
}
@Override
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
double d = this.perms.getPermissionDouble(world, playerName, node);
return (d == -1) ? defaultValue : d;
}
@Override
public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
//Unable to set player info nodes in P2
}
@Override
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
double d = this.perms.getGroupPermissionDouble(world, groupName, node);
return (d == -1) ? defaultValue : d;
}
@Override
public void setGroupInfoDouble(String world, String groupName, String node, double value) {
setGroupInfo(world, groupName, node, value);
}
@Override
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
//Warning does not support default value
return this.perms.getPermissionBoolean(world, playerName, node);
}
@Override
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
//Unable to set player info nodes in P2
}
@Override
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
return this.perms.getGroupPermissionBoolean(world, groupName, node);
}
@Override
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
setGroupInfo(world, groupName, node, value);
}
@Override
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
String s = this.perms.getPermissionString(world, playerName, node);
return (s == "" || s == null) ? defaultValue : s;
}
@Override
public void setPlayerInfoString(String world, String playerName, String node, String value) {
//Unable to set player info nodes in P2
}
@Override
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
String s = this.perms.getGroupPermissionString(world, groupName, node);
return (s == "" || s == null) ? defaultValue : s;
}
@Override
public void setGroupInfoString(String world, String groupName, String node, String value) {
setGroupInfo(world, groupName, node, value);
}
@Override
public String[] getPlayerGroups(String world, String playerName) {
return this.perms.getGroups(world, playerName);
}
@Override
public String getPrimaryGroup(String world, String playerName) {
return this.perms.getGroup(world, playerName);
}
@Override
public String getPlayerPrefix(String world, String playerName) {
return this.perms.getPermissionString(world, playerName, "prefix");
}
@Override
public String getPlayerSuffix(String world, String playerName) {
return this.perms.getPermissionString(world, playerName, "suffix");
}
@Override
public void setPlayerSuffix(Player player, String suffix) {
//Unable to set player info nodes in P2
}
}

View File

@ -33,18 +33,20 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijiko.permissions.Group;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
public class Permission_Permissions extends Permission {
public class Permission_Permissions3 extends Permission {
private static final Logger log = Logger.getLogger("Minecraft");
private String name = "Permissions (Yetti)";
private String name = "Permissions (Yeti)";
private PermissionHandler perms;
private Plugin plugin = null;
private PluginManager pluginManager = null;
private Permissions permission = null;
private PermissionServerListener permissionServerListener = null;
public Permission_Permissions(Plugin plugin) {
public Permission_Permissions3(Plugin plugin) {
this.plugin = plugin;
pluginManager = this.plugin.getServer().getPluginManager();
@ -57,8 +59,9 @@ public class Permission_Permissions extends Permission {
if (permission == null) {
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Permissions");
if (perms != null) {
if (perms.isEnabled()) {
if (perms.isEnabled() && perms.getDescription().getVersion().startsWith("3")) {
permission = (Permissions) perms;
this.perms = permission.getHandler();
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
}
}
@ -80,9 +83,9 @@ public class Permission_Permissions extends Permission {
}
private class PermissionServerListener extends ServerListener {
Permission_Permissions permission = null;
Permission_Permissions3 permission = null;
public PermissionServerListener(Permission_Permissions permission) {
public PermissionServerListener(Permission_Permissions3 permission) {
this.permission = permission;
}
@ -116,50 +119,26 @@ public class Permission_Permissions extends Permission {
@Override
public int getPlayerInfoInteger(String world, String playerName, String node, int defaultValue) {
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
if(s == null) {
return defaultValue;
} else {
try {
return Integer.parseInt(s);
} catch(NumberFormatException e) {
return defaultValue;
}
}
Integer i = this.perms.getInfoInteger(world, playerName, node, false);
return (i == null) ? defaultValue : i;
}
@Override
public double getPlayerInfoDouble(String world, String playerName, String node, double defaultValue) {
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
if(s == null) {
return defaultValue;
} else {
try {
return Double.parseDouble(s);
} catch(NumberFormatException e) {
return defaultValue;
}
}
Double d = this.perms.getInfoDouble(world, playerName, node, false);
return (d == null) ? defaultValue : d;
}
@Override
public boolean getPlayerInfoBoolean(String world, String playerName, String node, boolean defaultValue) {
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
if (s == null) {
return defaultValue;
} else {
return Boolean.parseBoolean(s);
}
Boolean b = this.perms.getInfoBoolean(world, playerName, node, false);
return (b == null) ? defaultValue : b;
}
@Override
public String getPlayerInfoString(String world, String playerName, String node, String defaultValue) {
String s = this.permission.getHandler().getInfoString(world, playerName, node, false);
if(s == null) {
return defaultValue;
} else {
return s;
}
String s = this.perms.getInfoString(world, playerName, node, false);
return (s == null) ? defaultValue : s;
}
@Override
@ -176,152 +155,103 @@ public class Permission_Permissions extends Permission {
@Override
public boolean playerAdd(String worldName, String playerName, String permission) {
this.permission.getHandler().addUserPermission(worldName, playerName, permission);
this.perms.addUserPermission(worldName, playerName, permission);
return true;
}
@Override
public boolean playerRemove(String worldName, String playerName, String permission) {
this.permission.getHandler().removeUserPermission(worldName, playerName, permission);
this.perms.removeUserPermission(worldName, playerName, permission);
return true;
}
@Override
public boolean groupAdd(String worldName, String groupName, String permission) {
this.permission.getHandler().addGroupPermission(worldName, groupName, permission);
this.perms.addGroupPermission(worldName, groupName, permission);
return true;
}
@Override
public boolean groupRemove(String worldName, String groupName, String permission) {
this.permission.getHandler().removeGroupPermission(worldName, groupName, permission);
this.perms.removeGroupPermission(worldName, groupName, permission);
return true;
}
public void setPlayerInfo(String world, String playerName, String node, Object value) {
this.perms.addUserInfo(world, playerName, node, value);
}
@Override
public void setPlayerInfoInteger(String world, String playerName, String node, int value) {
try {
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setPlayerInfo(world, playerName, node, value);
}
@Override
public void setPlayerInfoDouble(String world, String playerName, String node, double value) {
try {
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setPlayerInfo(world, playerName, node, value);
}
@Override
public void setPlayerInfoBoolean(String world, String playerName, String node, boolean value) {
try {
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setPlayerInfo(world, playerName, node, value);
}
@Override
public void setPlayerInfoString(String world, String playerName, String node, String value) {
try {
this.permission.getHandler().safeGetUser(world, playerName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setPlayerInfo(world, playerName, node, value);
}
@Override
public int getGroupInfoInteger(String world, String groupName, String node, int defaultValue) {
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
if(s == null) {
return defaultValue;
} else {
try {
return Integer.parseInt(s);
} catch(NumberFormatException e) {
return defaultValue;
}
}
Integer i = this.perms.getInfoInteger(world, groupName, node, true);
return (i == null) ? defaultValue : i;
}
public void setGroupInfo(String world, String groupName, String node, Object value) {
this.perms.addGroupInfo(world, groupName, node, value);
}
@Override
public void setGroupInfoInteger(String world, String groupName, String node, int value) {
try {
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setGroupInfo(world, groupName, node, value);
}
@Override
public double getGroupInfoDouble(String world, String groupName, String node, double defaultValue) {
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
if(s == null) {
return defaultValue;
} else {
try {
return Double.parseDouble(s);
} catch(NumberFormatException e) {
return defaultValue;
}
}
Double d = this.perms.getInfoDouble(world, groupName, node, true);
return (d == null) ? defaultValue : d;
}
@Override
public void setGroupInfoDouble(String world, String groupName, String node, double value) {
try {
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setGroupInfo(world, groupName, node, value);
}
@Override
public boolean getGroupInfoBoolean(String world, String groupName, String node, boolean defaultValue) {
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
if(s == null) {
return defaultValue;
} else {
return Boolean.parseBoolean(s);
}
Boolean b = this.perms.getInfoBoolean(world, groupName, node, true);
return (b == null) ? defaultValue : b;
}
@Override
public void setGroupInfoBoolean(String world, String groupName, String node, boolean value) {
try {
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setGroupInfo(world, groupName, node, value);
}
@Override
public String getGroupInfoString(String world, String groupName, String node, String defaultValue) {
String s = this.permission.getHandler().getInfoString(world, groupName, node, true);
if(s == null) {
return defaultValue;
} else {
return s;
}
return (s == null) ? defaultValue : s;
}
@Override
public void setGroupInfoString(String world, String groupName, String node, String value) {
try {
this.permission.getHandler().safeGetGroup(world, groupName).setData(node, value);
} catch(Exception e) {
// lolwut?
}
setGroupInfo(world, groupName, node, value);
}
@Override
public boolean groupHas(String worldName, String groupName, String permission) {
try {
Group group = this.permission.getHandler().safeGetGroup(worldName, groupName);
Group group = this.perms.safeGetGroup(worldName, groupName);
return group.hasPermission(permission);
} catch (Exception e) {
// lowut?
@ -331,30 +261,30 @@ public class Permission_Permissions extends Permission {
@Override
public String[] getPlayerGroups(String world, String playerName) {
return this.permission.getHandler().getGroups(world, playerName);
return this.perms.getGroups(world, playerName);
}
public String getPrimaryGroup(String world, String playerName) {
return this.permission.getHandler().getPrimaryGroup(world, playerName);
return this.perms.getPrimaryGroup(world, playerName);
}
@Override
public boolean playerHas(String worldName, String playerName, String permission) {
return this.permission.getHandler().has(worldName, playerName, permission);
return this.perms.has(worldName, playerName, permission);
}
@Override
public String getPlayerPrefix(String world, String playerName) {
return this.permission.getHandler().getUserPrefix(world, playerName);
return this.perms.getUserPrefix(world, playerName);
}
@Override
public String getPlayerSuffix(String world, String playerName) {
return this.permission.getHandler().getUserSuffix(world, playerName);
return this.perms.getUserSuffix(world, playerName);
}
@Override
public void setPlayerSuffix(Player player, String suffix) {
this.permission.getHandler().addUserInfo(player.getWorld().getName(), player.getName(), "suffix", suffix);
this.perms.addUserInfo(player.getWorld().getName(), player.getName(), "suffix", suffix);
}
}