Node based permissions

This commit is contained in:
Eric Stokes 2011-07-17 11:01:44 -06:00
parent 96fa18eab3
commit bf51adaa3e
4 changed files with 34 additions and 64 deletions

View File

@ -18,7 +18,7 @@ public class MVPermissions implements PermissionsInterface {
/**
* Constructor FTW
*
*
* @param plugin Pass along the Core Plugin.
*/
public MVPermissions(MultiverseCore plugin) {
@ -32,7 +32,7 @@ public class MVPermissions implements PermissionsInterface {
/**
* Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist
*
*
* @param p
* @param w
* @return
@ -42,10 +42,6 @@ public class MVPermissions implements PermissionsInterface {
boolean returnValue = true;
if (blackList.size() == 0) {
returnValue = true;
}
for (String s : blackList) {
if (s.equalsIgnoreCase(p.getWorld().getName())) {
returnValue = false;
@ -58,61 +54,34 @@ public class MVPermissions implements PermissionsInterface {
/**
* Check if the Player has the permissions to enter this world.
*
*
* @param p
* @param w
* @return
*/
public Boolean canEnterWorld(Player p, MVWorld w) {
List<String> whiteList = w.getPlayerWhitelist();
List<String> blackList = w.getPlayerBlacklist();
boolean returnValue = true;
// If there's anyone in the whitelist, then the whitelist is ACTIVE, anyone not in it is blacklisted.
if (whiteList.size() > 0) {
returnValue = false;
}
for (String bls : blackList) {
if (bls.toLowerCase().contains("g:") && this.inGroup(p, w.getAlias(), bls.split(":")[1])) {
returnValue = false;
break;
}
if (bls.equalsIgnoreCase(p.getName())) {
returnValue = false;
break;
}
}
for (String wls : whiteList) {
if (wls.toLowerCase().contains("g:") && this.inGroup(p, w.getAlias(), wls.split(":")[1])) {
returnValue = true;
break;
}
if (wls.equalsIgnoreCase(p.getName())) {
returnValue = true;
break;
}
}
return returnValue;
return this.hasPermission(p, "multiverse.access." + w.getName(), false);
}
/**
* Returns true if a player is in a group.
*
* @param player The player to check
* Returns true if a player is in a group. DEPRECATED: We're moving away from groups. Use permissions nodes in the groups instead.
*
* @param player The player to check
* @param worldName The world to check in
* @param group The group are we checking
* @param group The group are we checking
* @return True if the player is in the group, false if not.
*/
@Deprecated
private boolean inGroup(Player player, String worldName, String group) {
if (this.permissions != null) {
return this.permissions.inGroup(worldName, player.getName(), group);
} else {
return player.isOp();
}
}
@Deprecated
public List<String> getGroups(String worldName, String name) {
return Arrays.asList(this.permissions.getGroups(worldName, name));
}

View File

@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import com.onarandombox.MultiverseCore.event.MVRespawnEvent;
@ -122,4 +123,24 @@ public class MVPlayerListener extends PlayerListener {
public void onPlayerQuit(PlayerQuitEvent event) {
}
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
MVWorld fromWorld = this.plugin.getMVWorld(event.getTo().getWorld().getName());
MVWorld toWorld = this.plugin.getMVWorld(event.getTo().getWorld().getName());
if (toWorld != null) {
if (!this.plugin.getPermissions().canEnterWorld(event.getPlayer(), toWorld)) {
event.getPlayer().sendMessage("You don't have access to go here...");
event.setCancelled(true);
return;
}
}
if (fromWorld != null) {
if (fromWorld.getWorldBlacklist().contains(toWorld.getName())) {
event.getPlayer().sendMessage("You don't have access to go to " + toWorld.getColoredWorldString() + " from " + fromWorld.getColoredWorldString());
event.setCancelled(true);
return;
}
}
}
}

View File

@ -123,8 +123,6 @@ public class MVWorld {
this.setMonsters(config.getBoolean("worlds." + this.name + ".monsters.spawn", true));
this.getMobExceptions();
this.getPlayerWhitelist().addAll(config.getStringList("worlds." + this.name + ".playerwhitelist", new ArrayList<String>()));
this.getPlayerBlacklist().addAll(config.getStringList("worlds." + this.name + ".playerblacklist", new ArrayList<String>()));
this.getWorldBlacklist().addAll(config.getStringList("worlds." + this.name + ".worldblacklist", new ArrayList<String>()));
this.getBlockBlacklist().addAll(config.getIntList("worlds." + this.name + ".blockblacklist", new ArrayList<Integer>()));
this.translateTempSpawn(config);
@ -196,8 +194,6 @@ public class MVWorld {
this.masterList = new HashMap<String, List<String>>();
this.blockBlacklist = new ArrayList<Integer>();
// Only int list, we don't need to add it to the masterlist
this.masterList.put("playerwhitelist", new ArrayList<String>());
this.masterList.put("playerblacklist", new ArrayList<String>());
this.masterList.put("worldblacklist", new ArrayList<String>());
this.masterList.put("animals", new ArrayList<String>());
this.masterList.put("monsters", new ArrayList<String>());
@ -210,20 +206,12 @@ public class MVWorld {
this.blockBlacklist.add(49);
this.getPlayerWhitelist().add("fernferret");
this.getPlayerBlacklist().add("g:Admins");
this.getPlayerBlacklist().add("Rigby90");
this.getPlayerBlacklist().add("g:Banned");
this.getWorldBlacklist().add("world5");
this.getWorldBlacklist().add("A world with spaces");
this.config.setProperty("worlds." + this.name + ".animals.exceptions", this.getAnimalList());
this.config.setProperty("worlds." + this.name + ".monsters.exceptions", this.getMonsterList());
this.config.setProperty("worlds." + this.name + ".blockblacklist", this.getBlockBlacklist());
this.config.setProperty("worlds." + this.name + ".playerwhitelist", this.getPlayerWhitelist());
this.config.setProperty("worlds." + this.name + ".playerblacklist", this.getPlayerBlacklist());
this.config.setProperty("worlds." + this.name + ".worldblacklist", this.getWorldBlacklist());
this.config.save();
}
@ -470,14 +458,6 @@ public class MVWorld {
return this.blockBlacklist;
}
public List<String> getPlayerWhitelist() {
return this.masterList.get("playerwhitelist");
}
public List<String> getPlayerBlacklist() {
return this.masterList.get("playerblacklist");
}
public List<String> getWorldBlacklist() {
return this.masterList.get("worldblacklist");
}

View File

@ -61,7 +61,7 @@ public class TeleportCommand extends MultiverseCommand {
}
if (!(sender instanceof Player)) {
sender.sendMessage("You can only teleport other players from the command line.");
sender.sendMessage("From the console, you must specifiy a player to teleport");
return;
}
teleporter = (Player) sender;