Implement permissions

This commit is contained in:
Eric Stokes 2011-07-09 20:21:22 -06:00
parent a8999ee5a1
commit 8adf06f247
2 changed files with 41 additions and 40 deletions

View File

@ -10,11 +10,11 @@ import org.bukkit.entity.Player;
import com.nijiko.permissions.PermissionHandler;
import com.pneumaticraft.commandhandler.PermissionsInterface;
public class MVPermissions implements PermissionsInterface{
public class MVPermissions implements PermissionsInterface {
private MultiverseCore plugin;
public PermissionHandler permissions = null;
/**
* Constructor FTW
*
@ -23,12 +23,12 @@ public class MVPermissions implements PermissionsInterface{
public MVPermissions(MultiverseCore plugin) {
this.plugin = plugin;
// We have to see if permissions was loaded before MV was
if(this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) {
this.setPermissions(((com.nijikokun.bukkit.Permissions.Permissions)this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler());
if (this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) {
this.setPermissions(((com.nijikokun.bukkit.Permissions.Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler());
this.plugin.log(Level.INFO, "- Attached to Permissions");
}
}
/**
* Use hasPermission() Now
*
@ -39,38 +39,16 @@ public class MVPermissions implements PermissionsInterface{
@Deprecated
public boolean has(Player p, String node) {
boolean result = false;
if (this.permissions != null) {
result = this.permissions.has(p, node);
} else if (p.isOp()) {
result = true;
}
return result;
}
public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) {
if (!(sender instanceof Player)) {
return true;
}
Player player = (Player) sender;
boolean opFallback = this.plugin.configMV.getBoolean("opfallback", true);
if (player.isOp() && opFallback) {
// If Player is Op we always let them use it if they have the fallback enabled!
return true;
} else if (this.permissions != null && this.permissions.has(player, node)) {
// If Permissions is enabled we check against them.
return true;
}
// If the Player doesn't have Permissions and isn't an Op then
// we return true if OP is not required, otherwise we return false
// This allows us to act as a default permission guidance
// If they have the op fallback disabled, NO commands will work without a permissions plugin.
return !isOpRequired && opFallback;
}
/**
* Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist
*
@ -80,23 +58,23 @@ public class MVPermissions implements PermissionsInterface{
*/
public Boolean canTravelFromWorld(Player p, World w) {
List<String> blackList = this.plugin.getMVWorld(w.getName()).getWorldBlacklist();
boolean returnValue = true;
if (blackList.size() == 0) {
returnValue = true;
}
for (String s : blackList) {
if (s.equalsIgnoreCase(p.getWorld().getName())) {
returnValue = false;
break;
}
}
return returnValue;
}
/**
* Check if the Player has the permissions to enter this world.
*
@ -105,14 +83,14 @@ public class MVPermissions implements PermissionsInterface{
* @return
*/
public Boolean canEnterWorld(Player p, World w) {
if (!this.plugin.isMVWorld(w.getName())) {
return false;
}
List<String> whiteList = this.plugin.getMVWorld(w.getName()).getPlayerWhitelist();
List<String> blackList = this.plugin.getMVWorld(w.getName()).getPlayerBlacklist();
boolean returnValue = true;
// I lied. You definitely want this. Sorry Rigby :( You were right. --FF
// If there's anyone in the whitelist, then the whitelist is ACTIVE, anyone not in it is blacklisted.
if (whiteList.size() > 0) {
@ -140,7 +118,7 @@ public class MVPermissions implements PermissionsInterface{
}
return returnValue;
}
/**
* Returns true if a player is in a group.
*
@ -160,4 +138,27 @@ public class MVPermissions implements PermissionsInterface{
public void setPermissions(PermissionHandler handler) {
this.permissions = handler;
}
public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) {
if (!(sender instanceof Player)) {
return true;
}
Player player = (Player) sender;
boolean opFallback = this.plugin.configMV.getBoolean("opfallback", true);
if (player.isOp() && opFallback) {
// If Player is Op we always let them use it if they have the fallback enabled!
return true;
} else if (this.permissions != null && this.permissions.has(player, node)) {
// If Permissions is enabled we check against them.
return true;
}
// If the Player doesn't have Permissions and isn't an Op then
// we return true if OP is not required, otherwise we return false
// This allows us to act as a default permission guidance
// If they have the op fallback disabled, NO commands will work without a permissions plugin.
return !isOpRequired && opFallback;
}
}

View File

@ -92,7 +92,7 @@ public class MultiverseCore extends JavaPlugin {
this.bank = this.banker.loadEconPlugin();
// Setup the command manager
this.commandHandler = new CommandHandler(this);
this.commandHandler = new CommandHandler(this,this.ph);
// Setup the world purger
this.worldPurger = new PurgeWorlds(this);
// Call the Function to assign all the Commands to their Class.