mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-27 19:47:42 +01:00
Minor rewrite of Permissions package, all the stuff is now in one place.
This commit is contained in:
parent
ecc1a0acea
commit
057c9cb3f5
@ -30,6 +30,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||||
import com.earth2me.essentials.commands.NoChargeException;
|
import com.earth2me.essentials.commands.NoChargeException;
|
||||||
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
|
||||||
|
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
import com.earth2me.essentials.register.payment.Methods;
|
||||||
import com.earth2me.essentials.signs.SignBlockListener;
|
import com.earth2me.essentials.signs.SignBlockListener;
|
||||||
import com.earth2me.essentials.signs.SignEntityListener;
|
import com.earth2me.essentials.signs.SignEntityListener;
|
||||||
@ -65,7 +66,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
private transient final Methods paymentMethod = new Methods();
|
private transient final Methods paymentMethod = new Methods();
|
||||||
private transient final static boolean enableErrorLogging = false;
|
private transient final static boolean enableErrorLogging = false;
|
||||||
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
||||||
private transient IPermissionsHandler permissionsHandler;
|
private transient PermissionsHandler permissionsHandler;
|
||||||
private transient UserMap userMap;
|
private transient UserMap userMap;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,7 +91,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
|
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
|
||||||
settings = new Settings(this);
|
settings = new Settings(this);
|
||||||
userMap = new UserMap(this);
|
userMap = new UserMap(this);
|
||||||
permissionsHandler = new ConfigPermissionsHandler(this);
|
permissionsHandler = new PermissionsHandler(this, false);
|
||||||
Economy.setEss(this);
|
Economy.setEss(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,6 +152,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
LOGGER.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
|
LOGGER.log(Level.INFO, Util.i18n("bukkitFormatChanged"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
permissionsHandler = new PermissionsHandler(this, settings.useBukkitPermissions());
|
||||||
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
final EssentialsPluginListener serverListener = new EssentialsPluginListener(this);
|
||||||
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this);
|
pm.registerEvent(Type.PLUGIN_ENABLE, serverListener, Priority.Low, this);
|
||||||
pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this);
|
pm.registerEvent(Type.PLUGIN_DISABLE, serverListener, Priority.Low, this);
|
||||||
@ -665,17 +667,11 @@ public class Essentials extends JavaPlugin implements IEssentials
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPermissionsHandler getPermissionsHandler()
|
public PermissionsHandler getPermissionsHandler()
|
||||||
{
|
{
|
||||||
return permissionsHandler;
|
return permissionsHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPermissionsHandler(final IPermissionsHandler handler)
|
|
||||||
{
|
|
||||||
this.permissionsHandler = handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BanWorkaround getBans()
|
public BanWorkaround getBans()
|
||||||
{
|
{
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.perm.BPermissionsHandler;
|
|
||||||
import com.earth2me.essentials.perm.ConfigPermissionsHandler;
|
|
||||||
import com.earth2me.essentials.perm.Permissions3Handler;
|
|
||||||
import com.earth2me.essentials.perm.Permissions2Handler;
|
|
||||||
import com.earth2me.essentials.perm.PermissionsBukkitHandler;
|
|
||||||
import com.earth2me.essentials.perm.PermissionsExHandler;
|
|
||||||
import com.earth2me.essentials.perm.SuperpermsHandler;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
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.PluginManager;
|
|
||||||
|
|
||||||
|
|
||||||
public class EssentialsPluginListener extends ServerListener implements IConf
|
public class EssentialsPluginListener extends ServerListener implements IConf
|
||||||
@ -29,7 +20,7 @@ public class EssentialsPluginListener extends ServerListener implements IConf
|
|||||||
@Override
|
@Override
|
||||||
public void onPluginEnable(final PluginEnableEvent event)
|
public void onPluginEnable(final PluginEnableEvent event)
|
||||||
{
|
{
|
||||||
checkPermissions();
|
ess.getPermissionsHandler().checkPermissions();
|
||||||
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(event.getPlugin()))
|
if (!ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().setMethod(event.getPlugin()))
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.INFO, "[Essentials] Payment method found (" + ess.getPaymentMethod().getMethod().getName() + " version: " + ess.getPaymentMethod().getMethod().getVersion() + ")");
|
LOGGER.log(Level.INFO, "[Essentials] Payment method found (" + ess.getPaymentMethod().getMethod().getName() + " version: " + ess.getPaymentMethod().getMethod().getVersion() + ")");
|
||||||
@ -38,9 +29,9 @@ public class EssentialsPluginListener extends ServerListener implements IConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginDisable(PluginDisableEvent event)
|
public void onPluginDisable(final PluginDisableEvent event)
|
||||||
{
|
{
|
||||||
checkPermissions();
|
ess.getPermissionsHandler().checkPermissions();
|
||||||
// Check to see if the plugin thats being disabled is the one we are using
|
// Check to see if the plugin thats being disabled is the one we are using
|
||||||
if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin()))
|
if (ess.getPaymentMethod() != null && ess.getPaymentMethod().hasMethod() && ess.getPaymentMethod().checkDisabled(event.getPlugin()))
|
||||||
{
|
{
|
||||||
@ -48,84 +39,10 @@ public class EssentialsPluginListener extends ServerListener implements IConf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPermissions()
|
|
||||||
{
|
|
||||||
final PluginManager pm = ess.getServer().getPluginManager();
|
|
||||||
final Plugin permissionsExPlugin = pm.getPlugin("PermissionsEx");
|
|
||||||
|
|
||||||
if (permissionsExPlugin == null || !permissionsExPlugin.isEnabled())
|
|
||||||
{
|
|
||||||
final Plugin permissionsPlugin = pm.getPlugin("Permissions");
|
|
||||||
if (permissionsPlugin == null || !permissionsPlugin.isEnabled())
|
|
||||||
{
|
|
||||||
final Plugin permissionsBukkitPlugin = pm.getPlugin("PermissionsBukkit");
|
|
||||||
final Plugin bPermissionsPlugin = pm.getPlugin("bPermissions");
|
|
||||||
if (permissionsBukkitPlugin != null && permissionsBukkitPlugin.isEnabled())
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof PermissionsBukkitHandler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using PermissionsBukkit based permissions.");
|
|
||||||
ess.setPermissionsHandler(new PermissionsBukkitHandler(permissionsBukkitPlugin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (bPermissionsPlugin != null && bPermissionsPlugin.isEnabled())
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof BPermissionsHandler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using bPermissions based permissions.");
|
|
||||||
ess.setPermissionsHandler(new BPermissionsHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ess.getSettings().useBukkitPermissions())
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof SuperpermsHandler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using superperms based permissions.");
|
|
||||||
ess.setPermissionsHandler(new SuperpermsHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof ConfigPermissionsHandler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using config based permissions. Enable superperms in config.");
|
|
||||||
ess.setPermissionsHandler(new ConfigPermissionsHandler(ess));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (permissionsPlugin.getDescription().getVersion().charAt(0) == '3')
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof Permissions3Handler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using Permissions 3 based permissions.");
|
|
||||||
ess.setPermissionsHandler(new Permissions3Handler(permissionsPlugin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof Permissions2Handler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using Permissions 2 based permissions.");
|
|
||||||
ess.setPermissionsHandler(new Permissions2Handler(permissionsPlugin));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!(ess.getPermissionsHandler() instanceof PermissionsExHandler))
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.INFO, "Essentials: Using PermissionsEx based permissions.");
|
|
||||||
ess.setPermissionsHandler(new PermissionsExHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig()
|
public void reloadConfig()
|
||||||
{
|
{
|
||||||
checkPermissions();
|
ess.getPermissionsHandler().setUseSuperperms(ess.getSettings().useBukkitPermissions());
|
||||||
|
ess.getPermissionsHandler().checkPermissions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
import com.earth2me.essentials.perm.IPermissionsHandler;
|
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||||
import com.earth2me.essentials.register.payment.Methods;
|
import com.earth2me.essentials.register.payment.Methods;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -57,9 +57,7 @@ public interface IEssentials extends Plugin
|
|||||||
|
|
||||||
TNTExplodeListener getTNTListener();
|
TNTExplodeListener getTNTListener();
|
||||||
|
|
||||||
IPermissionsHandler getPermissionsHandler();
|
PermissionsHandler getPermissionsHandler();
|
||||||
|
|
||||||
void setPermissionsHandler(IPermissionsHandler handler);
|
|
||||||
|
|
||||||
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
|
void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
|
||||||
|
|
||||||
|
@ -19,28 +19,29 @@ public class BPermissionsHandler extends SuperpermsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getGroup(final Player base)
|
public String getGroup(final Player base)
|
||||||
{
|
{
|
||||||
final PermissionSet pset = wpm.getPermissionSet(base.getWorld());
|
final List<String> groups = getGroups(base);
|
||||||
if (pset == null)
|
|
||||||
{
|
|
||||||
return "default";
|
|
||||||
}
|
|
||||||
final List<String> groups = pset.getGroups(base);
|
|
||||||
if (groups == null || groups.isEmpty())
|
if (groups == null || groups.isEmpty())
|
||||||
{
|
{
|
||||||
return "default";
|
return null;
|
||||||
}
|
}
|
||||||
return groups.get(0);
|
return groups.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inGroup(final Player base, final String group)
|
public List<String> getGroups(final Player base)
|
||||||
{
|
{
|
||||||
final PermissionSet pset = wpm.getPermissionSet(base.getWorld());
|
final PermissionSet pset = wpm.getPermissionSet(base.getWorld());
|
||||||
if (pset == null)
|
if (pset == null)
|
||||||
{
|
{
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
final List<String> groups = pset.getGroups(base);
|
return pset.getGroups(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(final Player base, final String group)
|
||||||
|
{
|
||||||
|
final List<String> groups = getGroups(base);
|
||||||
if (groups == null || groups.isEmpty())
|
if (groups == null || groups.isEmpty())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,22 +1,30 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
public class ConfigPermissionsHandler implements IPermissionsHandler
|
public class ConfigPermissionsHandler implements IPermissionsHandler
|
||||||
{
|
{
|
||||||
private final transient IEssentials ess;
|
private final transient IEssentials ess;
|
||||||
|
|
||||||
public ConfigPermissionsHandler(final IEssentials ess)
|
public ConfigPermissionsHandler(final Plugin ess)
|
||||||
{
|
{
|
||||||
this.ess = ess;
|
this.ess = (IEssentials)ess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGroup(final Player base)
|
public String getGroup(final Player base)
|
||||||
{
|
{
|
||||||
return "default";
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -42,12 +50,12 @@ public class ConfigPermissionsHandler implements IPermissionsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getPrefix(final Player base)
|
public String getPrefix(final Player base)
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSuffix(final Player base)
|
public String getSuffix(final Player base)
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
public interface IPermissionsHandler
|
public interface IPermissionsHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
String getGroup(Player base);
|
String getGroup(Player base);
|
||||||
|
|
||||||
|
List<String> getGroups(Player base);
|
||||||
|
|
||||||
boolean canBuild(Player base, String group);
|
boolean canBuild(Player base, String group);
|
||||||
|
|
||||||
boolean inGroup(Player base, String group);
|
boolean inGroup(Player base, String group);
|
||||||
@ -17,5 +19,4 @@ public interface IPermissionsHandler
|
|||||||
String getPrefix(Player base);
|
String getPrefix(Player base);
|
||||||
|
|
||||||
String getSuffix(Player base);
|
String getSuffix(Player base);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
|
public class NullPermissionsHandler implements IPermissionsHandler
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public String getGroup(final Player base)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBuild(final Player base, final String group)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(final Player base, final String group)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(final Player base, final String node)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix(final Player base)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuffix(final Player base)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ package com.earth2me.essentials.perm;
|
|||||||
|
|
||||||
import com.nijiko.permissions.PermissionHandler;
|
import com.nijiko.permissions.PermissionHandler;
|
||||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
@ -18,8 +20,13 @@ public class Permissions2Handler implements IPermissionsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getGroup(final Player base)
|
public String getGroup(final Player base)
|
||||||
{
|
{
|
||||||
final String group = permissionHandler.getGroup(base.getWorld().getName(), base.getName());
|
return permissionHandler.getGroup(base.getWorld().getName(), base.getName());
|
||||||
return group == null ? "default" : group;
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
return Arrays.asList(permissionHandler.getGroups(base.getWorld().getName(), base.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -43,14 +50,12 @@ public class Permissions2Handler implements IPermissionsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getPrefix(final Player base)
|
public String getPrefix(final Player base)
|
||||||
{
|
{
|
||||||
final String prefix = permissionHandler.getGroupPrefix(base.getWorld().getName(), getGroup(base));
|
return permissionHandler.getGroupPrefix(base.getWorld().getName(), getGroup(base));
|
||||||
return prefix == null ? "" : prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSuffix(final Player base)
|
public String getSuffix(final Player base)
|
||||||
{
|
{
|
||||||
final String suffix = permissionHandler.getGroupSuffix(base.getWorld().getName(), getGroup(base));
|
return permissionHandler.getGroupSuffix(base.getWorld().getName(), getGroup(base));
|
||||||
return suffix == null ? "" : suffix;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package com.earth2me.essentials.perm;
|
|||||||
|
|
||||||
import com.nijiko.permissions.PermissionHandler;
|
import com.nijiko.permissions.PermissionHandler;
|
||||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
@ -21,6 +23,12 @@ public class Permissions3Handler implements IPermissionsHandler
|
|||||||
return permissionHandler.getPrimaryGroup(base.getWorld().getName(), base.getName());
|
return permissionHandler.getPrimaryGroup(base.getWorld().getName(), base.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
return Arrays.asList(permissionHandler.getGroups(base.getWorld().getName(), base.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(final Player base, final String group)
|
public boolean canBuild(final Player base, final String group)
|
||||||
{
|
{
|
||||||
@ -50,5 +58,4 @@ public class Permissions3Handler implements IPermissionsHandler
|
|||||||
{
|
{
|
||||||
return permissionHandler.getUserSuffix(base.getWorld().getName(), base.getName());
|
return permissionHandler.getUserSuffix(base.getWorld().getName(), base.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package com.earth2me.essentials.perm;
|
|||||||
import com.platymuus.bukkit.permissions.Group;
|
import com.platymuus.bukkit.permissions.Group;
|
||||||
import com.platymuus.bukkit.permissions.PermissionInfo;
|
import com.platymuus.bukkit.permissions.PermissionInfo;
|
||||||
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@ -20,32 +22,49 @@ public class PermissionsBukkitHandler extends SuperpermsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getGroup(final Player base)
|
public String getGroup(final Player base)
|
||||||
{
|
{
|
||||||
final PermissionInfo info = plugin.getPlayerInfo(base.getName());
|
final List<Group> groups = getPBGroups(base);
|
||||||
if (info == null)
|
|
||||||
{
|
|
||||||
return "default";
|
|
||||||
}
|
|
||||||
final List<Group> groups = info.getGroups();
|
|
||||||
if (groups == null || groups.isEmpty())
|
if (groups == null || groups.isEmpty())
|
||||||
{
|
{
|
||||||
return "default";
|
return null;
|
||||||
}
|
}
|
||||||
return groups.get(0).getName();
|
return groups.get(0).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean inGroup(final Player base, final String group)
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
final List<Group> groups = getPBGroups(base);
|
||||||
|
if (groups.size() == 1)
|
||||||
|
{
|
||||||
|
return Collections.singletonList(groups.get(0).getName());
|
||||||
|
}
|
||||||
|
final List<String> groupNames = new ArrayList<String>(groups.size());
|
||||||
|
for (Group group : groups)
|
||||||
|
{
|
||||||
|
groupNames.add(group.getName());
|
||||||
|
}
|
||||||
|
return groupNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Group> getPBGroups(final Player base)
|
||||||
{
|
{
|
||||||
final PermissionInfo info = plugin.getPlayerInfo(base.getName());
|
final PermissionInfo info = plugin.getPlayerInfo(base.getName());
|
||||||
if (info == null)
|
if (info == null)
|
||||||
{
|
{
|
||||||
return false;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
final List<Group> groups = info.getGroups();
|
final List<Group> groups = info.getGroups();
|
||||||
if (groups == null || groups.isEmpty())
|
if (groups == null || groups.isEmpty())
|
||||||
{
|
{
|
||||||
return false;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(final Player base, final String group)
|
||||||
|
{
|
||||||
|
final List<Group> groups = getPBGroups(base);
|
||||||
for (Group group1 : groups)
|
for (Group group1 : groups)
|
||||||
{
|
{
|
||||||
if (group1.getName().equalsIgnoreCase(group))
|
if (group1.getName().equalsIgnoreCase(group))
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import ru.tehkode.permissions.PermissionManager;
|
import ru.tehkode.permissions.PermissionManager;
|
||||||
import ru.tehkode.permissions.PermissionUser;
|
import ru.tehkode.permissions.PermissionUser;
|
||||||
@ -21,11 +23,22 @@ public class PermissionsExHandler implements IPermissionsHandler
|
|||||||
final PermissionUser user = manager.getUser(base.getName());
|
final PermissionUser user = manager.getUser(base.getName());
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return "default";
|
return null;
|
||||||
}
|
}
|
||||||
return user.getGroupsNames()[0];
|
return user.getGroupsNames()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
final PermissionUser user = manager.getUser(base.getName());
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return Arrays.asList(user.getGroupsNames());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBuild(final Player base, final String group)
|
public boolean canBuild(final Player base, final String group)
|
||||||
{
|
{
|
||||||
@ -62,7 +75,7 @@ public class PermissionsExHandler implements IPermissionsHandler
|
|||||||
final PermissionUser user = manager.getUser(base.getName());
|
final PermissionUser user = manager.getUser(base.getName());
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
return user.getPrefix();
|
return user.getPrefix();
|
||||||
}
|
}
|
||||||
@ -73,7 +86,7 @@ public class PermissionsExHandler implements IPermissionsHandler
|
|||||||
final PermissionUser user = manager.getUser(base.getName());
|
final PermissionUser user = manager.getUser(base.getName());
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
return user.getSuffix();
|
return user.getSuffix();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,179 @@
|
|||||||
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
|
|
||||||
|
public class PermissionsHandler implements IPermissionsHandler
|
||||||
|
{
|
||||||
|
private transient IPermissionsHandler handler = new NullPermissionsHandler();
|
||||||
|
private transient String defaultGroup = "default";
|
||||||
|
private final transient Plugin plugin;
|
||||||
|
private final static Logger LOGGER = Logger.getLogger("Minecraft");
|
||||||
|
private transient boolean useSuperperms = false;
|
||||||
|
|
||||||
|
public PermissionsHandler(final Plugin plugin)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionsHandler(final Plugin plugin, final boolean useSuperperms)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.useSuperperms = useSuperperms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionsHandler(final Plugin plugin, final String defaultGroup)
|
||||||
|
{
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.defaultGroup = defaultGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getGroup(final Player base)
|
||||||
|
{
|
||||||
|
String group = handler.getGroup(base);
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
group = defaultGroup;
|
||||||
|
}
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
List<String> groups = handler.getGroups(base);
|
||||||
|
if (groups == null || groups.isEmpty())
|
||||||
|
{
|
||||||
|
groups = Collections.singletonList(defaultGroup);
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBuild(final Player base, final String group)
|
||||||
|
{
|
||||||
|
return handler.canBuild(base, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(final Player base, final String group)
|
||||||
|
{
|
||||||
|
return handler.inGroup(base, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(final Player base, final String node)
|
||||||
|
{
|
||||||
|
return handler.inGroup(base, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrefix(final Player base)
|
||||||
|
{
|
||||||
|
String prefix = handler.getPrefix(base);
|
||||||
|
if (prefix == null)
|
||||||
|
{
|
||||||
|
prefix = "";
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuffix(final Player base)
|
||||||
|
{
|
||||||
|
String suffix = handler.getSuffix(base);
|
||||||
|
if (suffix == null)
|
||||||
|
{
|
||||||
|
suffix = "";
|
||||||
|
}
|
||||||
|
return suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkPermissions()
|
||||||
|
{
|
||||||
|
final PluginManager pluginManager = plugin.getServer().getPluginManager();
|
||||||
|
final Plugin permExPlugin = pluginManager.getPlugin("PermissionsEx");
|
||||||
|
|
||||||
|
if (permExPlugin == null || !permExPlugin.isEnabled())
|
||||||
|
{
|
||||||
|
final Plugin permBukkitPlugin = pluginManager.getPlugin("PermissionsBukkit");
|
||||||
|
final Plugin bPermPlugin = pluginManager.getPlugin("bPermissions");
|
||||||
|
final Plugin permPlugin = pluginManager.getPlugin("Permissions");
|
||||||
|
|
||||||
|
if (permBukkitPlugin != null && permBukkitPlugin.isEnabled())
|
||||||
|
{
|
||||||
|
if (!(handler instanceof PermissionsBukkitHandler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using PermissionsBukkit based permissions.");
|
||||||
|
handler = new PermissionsBukkitHandler(permBukkitPlugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (bPermPlugin != null && bPermPlugin.isEnabled())
|
||||||
|
{
|
||||||
|
if (!(handler instanceof BPermissionsHandler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using bPermissions based permissions.");
|
||||||
|
handler = new BPermissionsHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (permPlugin == null || !permPlugin.isEnabled())
|
||||||
|
{
|
||||||
|
if (useSuperperms)
|
||||||
|
{
|
||||||
|
if (!(handler instanceof SuperpermsHandler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using superperms based permissions.");
|
||||||
|
handler = new SuperpermsHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(handler instanceof ConfigPermissionsHandler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using config based permissions. Enable superperms in config.");
|
||||||
|
handler = new ConfigPermissionsHandler(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (permPlugin.getDescription().getVersion().charAt(0) == '3')
|
||||||
|
{
|
||||||
|
if (!(handler instanceof Permissions3Handler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using Permissions 3 based permissions.");
|
||||||
|
handler = new Permissions3Handler(permPlugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(handler instanceof Permissions2Handler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using Permissions 2 based permissions.");
|
||||||
|
handler = new Permissions2Handler(permPlugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(handler instanceof PermissionsExHandler))
|
||||||
|
{
|
||||||
|
LOGGER.log(Level.INFO, "Essentials: Using PermissionsEx based permissions.");
|
||||||
|
handler = new PermissionsExHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseSuperperms(final boolean useSuperperms)
|
||||||
|
{
|
||||||
|
this.useSuperperms = useSuperperms;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials.perm;
|
package com.earth2me.essentials.perm;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
||||||
@ -8,7 +9,13 @@ public class SuperpermsHandler implements IPermissionsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getGroup(final Player base)
|
public String getGroup(final Player base)
|
||||||
{
|
{
|
||||||
return "default";
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getGroups(final Player base)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -31,14 +38,16 @@ public class SuperpermsHandler implements IPermissionsHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String[] parts = node.split("\\.");
|
final String[] parts = node.split("\\.");
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder builder = new StringBuilder(node.length());
|
||||||
for (String part : parts)
|
for (String part : parts)
|
||||||
{
|
{
|
||||||
if (base.hasPermission(sb.toString() + "*"))
|
builder.append('*');
|
||||||
|
if (base.hasPermission(builder.toString()))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
sb.append(part).append(".");
|
builder.deleteCharAt(builder.length() - 1);
|
||||||
|
builder.append(part).append('.');
|
||||||
}
|
}
|
||||||
return base.hasPermission(node);
|
return base.hasPermission(node);
|
||||||
}
|
}
|
||||||
@ -46,12 +55,12 @@ public class SuperpermsHandler implements IPermissionsHandler
|
|||||||
@Override
|
@Override
|
||||||
public String getPrefix(final Player base)
|
public String getPrefix(final Player base)
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSuffix(final Player base)
|
public String getSuffix(final Player base)
|
||||||
{
|
{
|
||||||
return "";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user