diff --git a/src/de/craftinc/gates/commands/BaseCommand.java b/src/de/craftinc/gates/commands/BaseCommand.java index 1b13ba9..d3c1634 100644 --- a/src/de/craftinc/gates/commands/BaseCommand.java +++ b/src/de/craftinc/gates/commands/BaseCommand.java @@ -2,7 +2,6 @@ package de.craftinc.gates.commands; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -157,8 +156,8 @@ public abstract class BaseCommand } else { - Plugin.log(Level.FINE, "Command sender is no player! Switching to bukki for checking permissions!"); - return this.sender.hasPermission(this.requiredPermission); + // sender is no player Ð there is no information about the senders locations + return Plugin.permission.has(this.sender, this.requiredPermission); } @@ -166,7 +165,14 @@ public abstract class BaseCommand if (this.requiredPermission.equals(Plugin.permissionInfo)) { - hasPermission = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission); + if (this.hasGateParam) + { + hasPermission = this.hasPermissionAtGateLocationAndExit(p); + } + else + { + hasPermission = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission); + } } else if (this.requiredPermission.equals(Plugin.permissionUse) ) { @@ -174,7 +180,6 @@ public abstract class BaseCommand } else if (this.requiredPermission.equals(Plugin.permissionManage)) { - if (this.needsPermissionAtCurrentLocation && this.hasGateParam) { boolean hasPersmissionAtCurrentLocation = Plugin.permission.has(p.getWorld(), p.getName(), this.requiredPermission); diff --git a/src/de/craftinc/gates/commands/CommandList.java b/src/de/craftinc/gates/commands/CommandList.java index 2f551ab..4f4fe3e 100644 --- a/src/de/craftinc/gates/commands/CommandList.java +++ b/src/de/craftinc/gates/commands/CommandList.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.List; import org.bukkit.ChatColor; +import org.bukkit.entity.Player; import de.craftinc.gates.Gate; import de.craftinc.gates.Plugin; @@ -45,12 +46,42 @@ public class CommandList extends BaseCommand } + /** + * Method for returning a collection of gates the player is allowed to see. + */ + protected Collection getAllGates() + { + Collection gates = Gate.getAll(); + + + if (this.sender instanceof Player && Plugin.permission != null) + { + Player p = (Player)this.sender; + Collection gatesCopy = new ArrayList(gates); // create a copy since we cannot iterate over a collection while modifying it! + + for (Gate gate : gatesCopy) { + + if (!Plugin.permission.has(gate.getLocation().getWorld(), p.getName(), this.requiredPermission)) + { + gates.remove(gate); + } + else if (gate.getExit() != null && !Plugin.permission.has(gate.getExit().getWorld(), p.getName(), this.requiredPermission)) + { + gates.remove(gate); + } + } + } + + return gates; + } + + // pages start at 1 // will return null if requested page not availible protected List message(int page) { - Collection gates = Gate.getAll(); + Collection gates = this.getAllGates(); if (gates.size() == 0) { return null; @@ -163,12 +194,13 @@ public class CommandList extends BaseCommand currentPage++; } - if (pageMessages.isEmpty()) { + if (pageMessages.isEmpty()) + { return null; } else { ArrayList retVal = new ArrayList(); - retVal.add(TextUtil.titleize("List of all gates (" + page + "/" + + --currentPage + ")")); + retVal.add(TextUtil.titleize("List of all gates (" + page + "/" + --currentPage + ")")); retVal.addAll(pageMessages); return retVal; @@ -176,30 +208,41 @@ public class CommandList extends BaseCommand } + protected int getPageParameter() + { + int page = 1; + + try { + page = new Integer(parameters.get(0)); + } + catch (Exception e) { } + + return page; + } + + public void perform() { - Collection gates = Gate.getAll(); + int page = this.getPageParameter(); - if (gates.size() == 0) { - sendMessage(ChatColor.RED + "There are no gates yet."); - } - else { - int page = 1; - - try { - page = new Integer(parameters.get(0)); - } - catch (Exception e) { + List messages = message(page); + + if (messages == null) + { + if (page == 1) // no gates exist + { + sendMessage(ChatColor.RED + "There are no gates yet. " + ChatColor.RESET + + "(Note that you might not be allowed to get information about certain gates)"); } - - List messages = message(page); - - if (messages == null) { + else // the requested page does not exist + { sendMessage(ChatColor.RED + "The requested page is not availible"); } - else { - sendMessage(messages); - } + + } + else + { + sendMessage(messages); } } }