Fix White/Blacklisting

Add more permissions support
This commit is contained in:
Eric Stokes 2011-06-18 20:57:24 -06:00
parent cdc858a1e3
commit eab4067c7d
7 changed files with 76 additions and 51 deletions

View File

@ -5,40 +5,42 @@ import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.nijiko.permissions.Group;
public class MVPermissions {
private MultiverseCore plugin;
/**
* Constructor FTW
*
* @param plugin Pass along the Core Plugin.
*/
public MVPermissions(MultiverseCore plugin) {
this.plugin = plugin;
}
/**
* Check if the player has the following Permission node, if a Permissions plugin
* is not installed then we default to isOp()
* Check if the player has the following Permission node, if a Permissions plugin is not installed then we default to isOp()
*
* @param p The player instance.
* @param node The permission node we are checking against.
* @return
*/
public boolean has(Player p, String node) {
boolean result = false;
if (MultiverseCore.Permissions != null) {
result = MultiverseCore.Permissions.has(p, node);
} else if (p.isOp()) {
result = true;
}
return result;
}
/**
* Check if a Player can teleport to the Destination world from there
* current world. This checks against the Worlds Blacklist
* Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist
*
* @param p
* @param w
@ -46,74 +48,83 @@ public class MVPermissions {
*/
public Boolean canTravelFromWorld(Player p, World w) {
List<String> blackList = this.plugin.worlds.get(w.getName()).worldBlacklist;
boolean returnValue = true;
if (blackList.size() == 0) {
returnValue = true;
}
for (int i = 0; i < blackList.size(); i++) {
if (blackList.get(i).equalsIgnoreCase(p.getWorld().getName())) {
returnValue = false;
break;
}
}
return returnValue;
}
/**
* Check if the Player has the permissions to enter this world.
*
* @param p
* @param w
* @return
*/
public Boolean canEnterWorld(Player p, World w) {
String group = "";
if (MultiverseCore.Permissions != null) {
group = MultiverseCore.Permissions.getGroup(p.getName(), p.getWorld().getName());
}
List<String> whiteList = this.plugin.worlds.get(w.getName()).joinWhitelist;
List<String> blackList = this.plugin.worlds.get(w.getName()).joinBlacklist;
boolean returnValue = true;
// TODO: Not sure if I want this.
if (whiteList.size() > 0) {
returnValue = false;
}
for (int i = 0; i < whiteList.size(); i++) {
if (whiteList.get(i).contains("g:") && group.equalsIgnoreCase(whiteList.get(i).split(":")[1])) {
returnValue = true;
// if (whiteList.size() > 0) {
// returnValue = false;
// }
for (String bls : blackList) {
System.out.print(w.getName() + " has " + bls + " BLACKlisted");
if (bls.contains("g:") && inGroup(p, w.getName(), bls.split(":")[1])) {
System.out.print(p.getName() + " Is on the BLACKlist for " + w.getName());
returnValue = false;
break;
}
}
for (int i = 0; i < blackList.size(); i++) {
if (blackList.get(i).contains("g:") && group.equalsIgnoreCase(blackList.get(i).split(":")[1])) {
if (bls.equalsIgnoreCase(p.getName())) {
System.out.print(p.getName() + " Is on the BLACKlist for " + w.getName());
returnValue = false;
break;
}
}
for (int i = 0; i < whiteList.size(); i++) {
if (whiteList.get(i).equalsIgnoreCase(p.getName())) {
for (String wls : whiteList) {
System.out.print(w.getName() + " has " + wls + " WHTIElisted");
if (wls.contains("g:") && inGroup(p, w.getName(), wls.split(":")[1])) {
System.out.print(p.getName() + " Is on the WHITElist for " + w.getName());
returnValue = true;
break;
}
if (wls.equalsIgnoreCase(p.getName())) {
System.out.print(p.getName() + " Is on the WHITElist for " + w.getName());
returnValue = true;
break;
}
}
for (int i = 0; i < blackList.size(); i++) {
if (blackList.get(i).equalsIgnoreCase(p.getName())) {
returnValue = false;
break;
}
}
return returnValue;
}
/**
* Returns true if a player is in a group.
*
* @param player The player to check
* @param worldName The world to check in
* @param group The group are we checking
* @return True if the player is in the group, false if not.
*/
private boolean inGroup(Player player, String worldName, String group) {
if (MultiverseCore.Permissions != null) {
return MultiverseCore.Permissions.inGroup(worldName, player.getName(), group);
} else {
return player.isOp();
}
}
}

View File

@ -44,7 +44,7 @@ public class CreateCommand extends BaseCommand {
if(environment == null) {
return;
}
sender.sendMessage(ChatColor.AQUA + "Starting world creation...");
if (hasSeed) {
try {
plugin.addWorld(worldName, environment, Long.parseLong(seed));
@ -54,6 +54,7 @@ public class CreateCommand extends BaseCommand {
} else {
plugin.addWorld(worldName, environment);
}
sender.sendMessage(ChatColor.GREEN + "Complete!");
return;
}

View File

@ -34,7 +34,7 @@ public class ImportCommand extends BaseCommand {
if (new File(worldName).exists() && env != null) {
sender.sendMessage(ChatColor.AQUA + "Starting world import...");
plugin.addWorld(worldName, env);
sender.sendMessage(ChatColor.GREEN + "Complete!");
sender.sendMessage(ChatColor.GREEN + "Complete!");
return;
}
}

View File

@ -33,9 +33,8 @@ public class ListCommand extends BaseCommand {
}
String output = ChatColor.LIGHT_PURPLE + "Worlds which you can view:\n";
for (int i = 0; i < plugin.getServer().getWorlds().size(); i++) {
for (World world : plugin.getServer().getWorlds()) {
World world = plugin.getServer().getWorlds().get(i);
if (!(plugin.worlds.containsKey(world.getName()))) {
continue;

View File

@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.command.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.command.BaseCommand;
@ -20,6 +21,11 @@ public class RemoveCommand extends BaseCommand {
@Override
public void execute(CommandSender sender, String[] args) {
if(sender instanceof Player) {
if(!plugin.ph.has((Player)sender,"multiverse.world.remove")) {
return;
}
}
if (plugin.removeWorld(args[0])) {
sender.sendMessage("World removed from config!");
} else {

View File

@ -37,7 +37,7 @@ public class TeleportCommand extends BaseCommand {
}
Destination d = Destination.parseDestination(args[0], this.plugin);
// TODO: Support portals, but I didn't see the portals list --FF
if (d.getType() == DestinationType.World) {
if (d.getType() == DestinationType.World && plugin.ph.canEnterWorld(p, plugin.getServer().getWorld(d.getName()))) {
Location l = playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation());
p.teleport(l);
} else {

View File

@ -27,8 +27,10 @@ public class WhoCommand extends BaseCommand {
@Override
public void execute(CommandSender sender, String[] args) {
// If this command was sent from a Player then we need to check Permissions
Player p = null;
if (sender instanceof Player) {
if (!(plugin.ph.has(((Player) sender), "multiverse.who"))) {
p = (Player) sender;
if (!(plugin.ph.has(p, "multiverse.world.who"))) {
sender.sendMessage("You do not have access to this command.");
return;
}
@ -49,6 +51,12 @@ public class WhoCommand extends BaseCommand {
}
for (World world : worlds) {
if (!(plugin.worlds.containsKey(world.getName()))) {
continue;
}
if (p != null && (!plugin.ph.canEnterWorld(p, world))) {
continue;
}
ChatColor color = ChatColor.BLUE;
if (world.getEnvironment() == Environment.NETHER) {
color = ChatColor.RED;