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.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.nijiko.permissions.Group;
public class MVPermissions { public class MVPermissions {
private MultiverseCore plugin; private MultiverseCore plugin;
/** /**
* Constructor FTW * Constructor FTW
*
* @param plugin Pass along the Core Plugin. * @param plugin Pass along the Core Plugin.
*/ */
public MVPermissions(MultiverseCore plugin) { public MVPermissions(MultiverseCore plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/** /**
* Check if the player has the following Permission node, if a Permissions plugin * Check if the player has the following Permission node, if a Permissions plugin is not installed then we default to isOp()
* is not installed then we default to isOp() *
* @param p The player instance. * @param p The player instance.
* @param node The permission node we are checking against. * @param node The permission node we are checking against.
* @return * @return
*/ */
public boolean has(Player p, String node) { public boolean has(Player p, String node) {
boolean result = false; boolean result = false;
if (MultiverseCore.Permissions != null) { if (MultiverseCore.Permissions != null) {
result = MultiverseCore.Permissions.has(p, node); result = MultiverseCore.Permissions.has(p, node);
} else if (p.isOp()) { } else if (p.isOp()) {
result = true; result = true;
} }
return result; return result;
} }
/** /**
* Check if a Player can teleport to the Destination world from there * Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist
* current world. This checks against the Worlds Blacklist
* *
* @param p * @param p
* @param w * @param w
@ -46,74 +48,83 @@ public class MVPermissions {
*/ */
public Boolean canTravelFromWorld(Player p, World w) { public Boolean canTravelFromWorld(Player p, World w) {
List<String> blackList = this.plugin.worlds.get(w.getName()).worldBlacklist; List<String> blackList = this.plugin.worlds.get(w.getName()).worldBlacklist;
boolean returnValue = true; boolean returnValue = true;
if (blackList.size() == 0) { if (blackList.size() == 0) {
returnValue = true; returnValue = true;
} }
for (int i = 0; i < blackList.size(); i++) { for (int i = 0; i < blackList.size(); i++) {
if (blackList.get(i).equalsIgnoreCase(p.getWorld().getName())) { if (blackList.get(i).equalsIgnoreCase(p.getWorld().getName())) {
returnValue = false; returnValue = false;
break; break;
} }
} }
return returnValue; return returnValue;
} }
/** /**
* Check if the Player has the permissions to enter this world. * Check if the Player has the permissions to enter this world.
*
* @param p * @param p
* @param w * @param w
* @return * @return
*/ */
public Boolean canEnterWorld(Player p, World w) { 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> whiteList = this.plugin.worlds.get(w.getName()).joinWhitelist;
List<String> blackList = this.plugin.worlds.get(w.getName()).joinBlacklist; List<String> blackList = this.plugin.worlds.get(w.getName()).joinBlacklist;
boolean returnValue = true; boolean returnValue = true;
// TODO: Not sure if I want this. // TODO: Not sure if I want this.
if (whiteList.size() > 0) { // if (whiteList.size() > 0) {
returnValue = false; // returnValue = false;
} // }
for (String bls : blackList) {
for (int i = 0; i < whiteList.size(); i++) { System.out.print(w.getName() + " has " + bls + " BLACKlisted");
if (whiteList.get(i).contains("g:") && group.equalsIgnoreCase(whiteList.get(i).split(":")[1])) { if (bls.contains("g:") && inGroup(p, w.getName(), bls.split(":")[1])) {
returnValue = true; System.out.print(p.getName() + " Is on the BLACKlist for " + w.getName());
returnValue = false;
break; break;
} }
} if (bls.equalsIgnoreCase(p.getName())) {
System.out.print(p.getName() + " Is on the BLACKlist for " + w.getName());
for (int i = 0; i < blackList.size(); i++) {
if (blackList.get(i).contains("g:") && group.equalsIgnoreCase(blackList.get(i).split(":")[1])) {
returnValue = false; returnValue = false;
break; break;
} }
} }
for (String wls : whiteList) {
for (int i = 0; i < whiteList.size(); i++) { System.out.print(w.getName() + " has " + wls + " WHTIElisted");
if (whiteList.get(i).equalsIgnoreCase(p.getName())) { 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; returnValue = true;
break; break;
} }
} }
for (int i = 0; i < blackList.size(); i++) {
if (blackList.get(i).equalsIgnoreCase(p.getName())) {
returnValue = false;
break;
}
}
return returnValue; 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) { if(environment == null) {
return; return;
} }
sender.sendMessage(ChatColor.AQUA + "Starting world creation...");
if (hasSeed) { if (hasSeed) {
try { try {
plugin.addWorld(worldName, environment, Long.parseLong(seed)); plugin.addWorld(worldName, environment, Long.parseLong(seed));
@ -54,6 +54,7 @@ public class CreateCommand extends BaseCommand {
} else { } else {
plugin.addWorld(worldName, environment); plugin.addWorld(worldName, environment);
} }
sender.sendMessage(ChatColor.GREEN + "Complete!");
return; return;
} }

View File

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

View File

@ -33,9 +33,8 @@ public class ListCommand extends BaseCommand {
} }
String output = ChatColor.LIGHT_PURPLE + "Worlds which you can view:\n"; 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()))) { if (!(plugin.worlds.containsKey(world.getName()))) {
continue; continue;

View File

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

View File

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

View File

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