From cea080e7c76a1e567e6c99e96ef50564f12156bb Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sun, 7 Aug 2011 01:00:48 -0700 Subject: [PATCH] Added Nijiperms bridge detection, allowing DinnerPerms to no longer conflict with everything else by default. --- .../bukkit/migration/DinnerPermsResolver.java | 6 +----- .../migration/NijiPermissionsResolver.java | 17 ++++++++++++++++- .../migration/PermissionsResolverManager.java | 10 ++++++++-- .../PermissionsResolverServerListener.java | 10 ++++++---- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java b/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java index 00de147c9..e07f08191 100644 --- a/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/DinnerPermsResolver.java @@ -15,12 +15,11 @@ public class DinnerPermsResolver implements PermissionsResolver { public DinnerPermsResolver(Server server) { this.server = server; } - @Override + public void load() { // Permissions are already loaded } - @Override public boolean hasPermission(String name, String permission) { Player player = server.getPlayer(name); if (player == null) @@ -41,12 +40,10 @@ public class DinnerPermsResolver implements PermissionsResolver { return false; } - @Override public boolean hasPermission(String worldName, String name, String permission) { return hasPermission(name, permission); // no per-world ability to check permissions in dinnerperms } - @Override public boolean inGroup(String name, String group) { Player player = server.getPlayer(name); if (player == null) @@ -54,7 +51,6 @@ public class DinnerPermsResolver implements PermissionsResolver { return player.hasPermission(GROUP_PREFIX + group); } - @Override public String[] getGroups(String name) { Player player = server.getPlayer(name); if (player == null) diff --git a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java index 0eea7df66..99a0b1b17 100644 --- a/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java +++ b/src/main/java/com/sk89q/bukkit/migration/NijiPermissionsResolver.java @@ -19,7 +19,9 @@ package com.sk89q.bukkit.migration; +import com.sun.xml.internal.fastinfoset.algorithm.BooleanEncodingAlgorithm; import org.bukkit.Server; +import org.bukkit.command.PluginCommand; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; @@ -33,7 +35,7 @@ public class NijiPermissionsResolver implements PermissionsResolver { } - public NijiPermissionsResolver(Server server) + public NijiPermissionsResolver(Server server, boolean ignoreBridges) throws PluginAccessException, MissingPluginException { this.server = server; PluginManager manager = server.getPluginManager(); @@ -42,6 +44,8 @@ public class NijiPermissionsResolver implements PermissionsResolver { if (plugin == null) { throw new MissingPluginException(); } + if (!checkRealNijiPerms(plugin, ignoreBridges)) + throw new MissingPluginException(); try { api = (Permissions)plugin; @@ -126,4 +130,15 @@ public class NijiPermissionsResolver implements PermissionsResolver { public static class MissingPluginException extends Exception { private static final long serialVersionUID = 7044832912491608706L; } + + public static boolean checkRealNijiPerms(Plugin plugin, boolean ignoreBridges) { + if (!ignoreBridges) + return true; + PluginCommand permsCommand = plugin.getServer().getPluginCommand("permissions"); + if (permsCommand == null) + return false; + if (!permsCommand.getPlugin().getDescription().getName().equals("Permissions")) + return false; + return true; + } } diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java index 0ec366f11..3dc8dd336 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverManager.java @@ -56,6 +56,7 @@ public class PermissionsResolverManager implements PermissionsResolver { private Configuration permsConfig; private String name; private Logger logger; + protected boolean ignoreNijiPermsBridges; public PermissionsResolverManager(Configuration config, Server server, String name, Logger logger) { this.server = server; @@ -65,9 +66,9 @@ public class PermissionsResolverManager implements PermissionsResolver { findResolver(); } public void findResolver() { - if (tryDinnerPerms()) return; if (tryPluginPermissionsResolver()) return; if (tryNijiPermissions()) return; + if (tryDinnerPerms()) return; if (tryFlatFilePermissions()) return; perms = new ConfigurationPermissionsResolver(permsConfig); @@ -76,7 +77,7 @@ public class PermissionsResolverManager implements PermissionsResolver { private boolean tryNijiPermissions() { try { - perms = new NijiPermissionsResolver(server); + perms = new NijiPermissionsResolver(server, ignoreNijiPermsBridges); logger.info(name + ": Permissions plugin detected! Using Permissions plugin for permissions."); return true; } catch (Throwable e) { @@ -164,6 +165,11 @@ public class PermissionsResolverManager implements PermissionsResolver { permsConfig.setProperty("dinnerperms", permsConfig.getBoolean("dinner-perms", true)); isUpdated = true; } + if (!keys.contains("ignore-nijiperms-bridges")) { + permsConfig.setProperty("ignore-nijiperms-bridges", true); + isUpdated = true; + } + ignoreNijiPermsBridges = permsConfig.getBoolean("ignore-nijiperms-bridges", true); if (keys.contains("dinner-perms")) { permsConfig.removeProperty("dinner-perms"); isUpdated = true; diff --git a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java index 92890e662..47b188d22 100644 --- a/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java +++ b/src/main/java/com/sk89q/bukkit/migration/PermissionsResolverServerListener.java @@ -26,6 +26,8 @@ import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.ServerListener; import org.bukkit.plugin.Plugin; +import java.util.Map; + public class PermissionsResolverServerListener extends ServerListener { private PermissionsResolverManager manager; @@ -42,10 +44,10 @@ public class PermissionsResolverServerListener extends ServerListener { public void onPluginEnable(PluginEnableEvent event) { Plugin plugin = event.getPlugin(); String name = plugin.getDescription().getName(); - if (plugin instanceof PermissionsProvider) { manager.setPluginPermissionsResolver(plugin); - } else if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) { + } else if (name.equalsIgnoreCase("Permissions") && + NijiPermissionsResolver.checkRealNijiPerms(plugin, manager.ignoreNijiPermsBridges)) { manager.findResolver(); manager.load(); } @@ -62,8 +64,8 @@ public class PermissionsResolverServerListener extends ServerListener { String name = plugin.getDescription().getName(); if (plugin instanceof PermissionsProvider - || name.equalsIgnoreCase("GroupUsers") - || name.equalsIgnoreCase("Permissions")) { + || (name.equalsIgnoreCase("Permissions") && + NijiPermissionsResolver.checkRealNijiPerms(plugin, manager.ignoreNijiPermsBridges))) { manager.findResolver(); manager.load(); }