Delay asking for PermissionHandler - might help PEX not freak out

This commit is contained in:
Mike Primm 2011-11-28 00:06:23 +08:00 committed by mikeprimm
parent 97f5d0c715
commit bd03b36c0e

View File

@ -12,11 +12,13 @@ import com.nijikokun.bukkit.Permissions.Permissions;
public class NijikokunPermissions implements PermissionProvider { public class NijikokunPermissions implements PermissionProvider {
String name; String name;
PermissionHandler permissions; PermissionHandler permissions;
Plugin plugin;
public static NijikokunPermissions create(Server server, String name) { public static NijikokunPermissions create(Server server, String name) {
Plugin permissionsPlugin = server.getPluginManager().getPlugin("Permissions"); Plugin permissionsPlugin = server.getPluginManager().getPlugin("Permissions");
if (permissionsPlugin == null) if (permissionsPlugin == null)
return null; return null;
server.getPluginManager().enablePlugin(permissionsPlugin); server.getPluginManager().enablePlugin(permissionsPlugin);
Log.info("Using Permissions " + permissionsPlugin.getDescription().getVersion() + " for access control"); Log.info("Using Permissions " + permissionsPlugin.getDescription().getVersion() + " for access control");
return new NijikokunPermissions(permissionsPlugin, name); return new NijikokunPermissions(permissionsPlugin, name);
@ -24,11 +26,13 @@ public class NijikokunPermissions implements PermissionProvider {
public NijikokunPermissions(Plugin permissionsPlugin, String name) { public NijikokunPermissions(Plugin permissionsPlugin, String name) {
this.name = name; this.name = name;
permissions = ((Permissions) permissionsPlugin).getHandler(); plugin = permissionsPlugin;
} }
@Override @Override
public boolean has(CommandSender sender, String permission) { public boolean has(CommandSender sender, String permission) {
if(permissions == null)
permissions = ((Permissions)plugin).getHandler();
Player player = sender instanceof Player ? (Player) sender : null; Player player = sender instanceof Player ? (Player) sender : null;
return player != null return player != null
? permissions.has(player, name + "." + permission) || permissions.has(player, name + ".*") ? permissions.has(player, name + "." + permission) || permissions.has(player, name + ".*")