Added Nijiperms bridge detection, allowing DinnerPerms to no longer conflict with everything else by default.

This commit is contained in:
zml2008 2011-08-07 01:00:48 -07:00
parent 0040ba9867
commit cea080e7c7
4 changed files with 31 additions and 12 deletions

View File

@ -15,12 +15,11 @@ public class DinnerPermsResolver implements PermissionsResolver {
public DinnerPermsResolver(Server server) { public DinnerPermsResolver(Server server) {
this.server = server; this.server = server;
} }
@Override
public void load() { public void load() {
// Permissions are already loaded // Permissions are already loaded
} }
@Override
public boolean hasPermission(String name, String permission) { public boolean hasPermission(String name, String permission) {
Player player = server.getPlayer(name); Player player = server.getPlayer(name);
if (player == null) if (player == null)
@ -41,12 +40,10 @@ public class DinnerPermsResolver implements PermissionsResolver {
return false; return false;
} }
@Override
public boolean hasPermission(String worldName, String name, String permission) { public boolean hasPermission(String worldName, String name, String permission) {
return hasPermission(name, permission); // no per-world ability to check permissions in dinnerperms return hasPermission(name, permission); // no per-world ability to check permissions in dinnerperms
} }
@Override
public boolean inGroup(String name, String group) { public boolean inGroup(String name, String group) {
Player player = server.getPlayer(name); Player player = server.getPlayer(name);
if (player == null) if (player == null)
@ -54,7 +51,6 @@ public class DinnerPermsResolver implements PermissionsResolver {
return player.hasPermission(GROUP_PREFIX + group); return player.hasPermission(GROUP_PREFIX + group);
} }
@Override
public String[] getGroups(String name) { public String[] getGroups(String name) {
Player player = server.getPlayer(name); Player player = server.getPlayer(name);
if (player == null) if (player == null)

View File

@ -19,7 +19,9 @@
package com.sk89q.bukkit.migration; package com.sk89q.bukkit.migration;
import com.sun.xml.internal.fastinfoset.algorithm.BooleanEncodingAlgorithm;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; 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 { throws PluginAccessException, MissingPluginException {
this.server = server; this.server = server;
PluginManager manager = server.getPluginManager(); PluginManager manager = server.getPluginManager();
@ -42,6 +44,8 @@ public class NijiPermissionsResolver implements PermissionsResolver {
if (plugin == null) { if (plugin == null) {
throw new MissingPluginException(); throw new MissingPluginException();
} }
if (!checkRealNijiPerms(plugin, ignoreBridges))
throw new MissingPluginException();
try { try {
api = (Permissions)plugin; api = (Permissions)plugin;
@ -126,4 +130,15 @@ public class NijiPermissionsResolver implements PermissionsResolver {
public static class MissingPluginException extends Exception { public static class MissingPluginException extends Exception {
private static final long serialVersionUID = 7044832912491608706L; 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;
}
} }

View File

@ -56,6 +56,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
private Configuration permsConfig; private Configuration permsConfig;
private String name; private String name;
private Logger logger; private Logger logger;
protected boolean ignoreNijiPermsBridges;
public PermissionsResolverManager(Configuration config, Server server, String name, Logger logger) { public PermissionsResolverManager(Configuration config, Server server, String name, Logger logger) {
this.server = server; this.server = server;
@ -65,9 +66,9 @@ public class PermissionsResolverManager implements PermissionsResolver {
findResolver(); findResolver();
} }
public void findResolver() { public void findResolver() {
if (tryDinnerPerms()) return;
if (tryPluginPermissionsResolver()) return; if (tryPluginPermissionsResolver()) return;
if (tryNijiPermissions()) return; if (tryNijiPermissions()) return;
if (tryDinnerPerms()) return;
if (tryFlatFilePermissions()) return; if (tryFlatFilePermissions()) return;
perms = new ConfigurationPermissionsResolver(permsConfig); perms = new ConfigurationPermissionsResolver(permsConfig);
@ -76,7 +77,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
private boolean tryNijiPermissions() { private boolean tryNijiPermissions() {
try { try {
perms = new NijiPermissionsResolver(server); perms = new NijiPermissionsResolver(server, ignoreNijiPermsBridges);
logger.info(name + ": Permissions plugin detected! Using Permissions plugin for permissions."); logger.info(name + ": Permissions plugin detected! Using Permissions plugin for permissions.");
return true; return true;
} catch (Throwable e) { } catch (Throwable e) {
@ -164,6 +165,11 @@ public class PermissionsResolverManager implements PermissionsResolver {
permsConfig.setProperty("dinnerperms", permsConfig.getBoolean("dinner-perms", true)); permsConfig.setProperty("dinnerperms", permsConfig.getBoolean("dinner-perms", true));
isUpdated = 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")) { if (keys.contains("dinner-perms")) {
permsConfig.removeProperty("dinner-perms"); permsConfig.removeProperty("dinner-perms");
isUpdated = true; isUpdated = true;

View File

@ -26,6 +26,8 @@ import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener; import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.util.Map;
public class PermissionsResolverServerListener extends ServerListener { public class PermissionsResolverServerListener extends ServerListener {
private PermissionsResolverManager manager; private PermissionsResolverManager manager;
@ -42,10 +44,10 @@ public class PermissionsResolverServerListener extends ServerListener {
public void onPluginEnable(PluginEnableEvent event) { public void onPluginEnable(PluginEnableEvent event) {
Plugin plugin = event.getPlugin(); Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName(); String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider) { if (plugin instanceof PermissionsProvider) {
manager.setPluginPermissionsResolver(plugin); manager.setPluginPermissionsResolver(plugin);
} else if (name.equalsIgnoreCase("GroupUsers") || name.equalsIgnoreCase("Permissions")) { } else if (name.equalsIgnoreCase("Permissions") &&
NijiPermissionsResolver.checkRealNijiPerms(plugin, manager.ignoreNijiPermsBridges)) {
manager.findResolver(); manager.findResolver();
manager.load(); manager.load();
} }
@ -62,8 +64,8 @@ public class PermissionsResolverServerListener extends ServerListener {
String name = plugin.getDescription().getName(); String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider if (plugin instanceof PermissionsProvider
|| name.equalsIgnoreCase("GroupUsers") || (name.equalsIgnoreCase("Permissions") &&
|| name.equalsIgnoreCase("Permissions")) { NijiPermissionsResolver.checkRealNijiPerms(plugin, manager.ignoreNijiPermsBridges))) {
manager.findResolver(); manager.findResolver();
manager.load(); manager.load();
} }