diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java index 94d02313..c4e64de8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java @@ -45,7 +45,7 @@ public interface MVDestination { boolean isThisType(JavaPlugin plugin, String destination); /** - * Returns the location a specific entity will spawn at. + * Returns the location a specific entity will spawn at when being teleported to this Destination. *

* To just retrieve the location as it is stored you can just pass null, but be warned some destinations may return * null back to you if you do this. It is always safer to pass an actual entity. This is used so things like diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java index 9a91013e..474308c6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java @@ -45,18 +45,13 @@ public class CheckCommand extends MultiverseCommand { } MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1)); if (dest instanceof InvalidDestination) { - sender.sendMessage("You asked if '" + args.get(0) + "' could go to " + ChatColor.GREEN + args.get(0) + ChatColor.WHITE + ","); + sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,", + args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE)); sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?"); return; } MVPermissions perms = this.plugin.getMVPerms(); - if (perms.canEnterDestination(p, dest)) { - sender.sendMessage(ChatColor.GREEN + args.get(0) + ChatColor.WHITE + " can travel to " + ChatColor.GREEN + args.get(1)); - } else { - sender.sendMessage(ChatColor.AQUA + args.get(0) + ChatColor.RED + " CANNOT travel to " + ChatColor.AQUA + args.get(1)); - sender.sendMessage("Please turn debug mode to 3 then watch the console to find out why!"); - sender.sendMessage("Use: " + ChatColor.GREEN + "/mv debug 3"); - } + perms.tellMeWhyICantDoThis(sender, p, dest); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java index 6fca03b0..105aeb78 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java @@ -12,6 +12,7 @@ import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.pneumaticraft.commandhandler.PermissionsInterface; +import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -139,6 +140,81 @@ public class MVPermissions implements PermissionsInterface { return this.hasPermission(p, d.getRequiredPermission(), false); } + public void tellMeWhyICantDoThis(CommandSender asker, CommandSender playerInQuestion, MVDestination d) { + boolean cango = true; + if (!(playerInQuestion instanceof Player)) { + asker.sendMessage(String.format("The console can do %severything%s.", ChatColor.RED, ChatColor.WHITE)); + return; + } + Player p = (Player) playerInQuestion; + if (d == null) { + asker.sendMessage(String.format("The provided Destination is %sNULL%s, and therefore %sNVALID%s.", + ChatColor.RED, ChatColor.WHITE, ChatColor.RED, ChatColor.WHITE)); + cango = false; + } + // We know it'll be a player here due to the first line of this method. + if (d.getLocation(p) == null) { + asker.sendMessage(String.format( + "The player will spawn at an %sindeterminate location%s. Talk to the MV Devs if you see this", + ChatColor.RED, ChatColor.WHITE)); + cango = false; + } + String worldName = d.getLocation(p).getWorld().getName(); + if (!this.worldMgr.isMVWorld(worldName)) { + asker.sendMessage(String.format("The destination resides in a world(%s%s%s) that is not managed by Multiverse.", + ChatColor.AQUA, worldName, ChatColor.WHITE)); + asker.sendMessage(String.format("Type %s/mv import ?%s to see the import command's help page.", + ChatColor.DARK_AQUA, ChatColor.WHITE)); + cango = false; + } + if (!this.hasPermission(p, "multiverse.access." + worldName, false)) { + asker.sendMessage(String.format("The player (%s%s%s) does not have the required world entry permission (%s%s%s) to go to the destination (%s%s%s).", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.GREEN, "multiverse.access." + worldName, ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + cango = false; + } + if (!this.hasPermission(p, d.getRequiredPermission(), false)) { + asker.sendMessage(String.format("The player (%s%s%s) does not have the required entry permission (%s%s%s) to go to the destination (%s%s%s).", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.GREEN, d.getRequiredPermission(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + cango = false; + } + if (cango) { + asker.sendMessage(String.format("The player (%s%s%s) CAN go to the destination (%s%s%s).", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + } else { + asker.sendMessage(String.format("The player (%s%s%s) cannot access the destination %s%s%s. Therefore they can't use mvtp at all for this.", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + return; + } + if (!this.hasPermission(p, "multiverse.teleport.self." + d.getIdentifier(), false)) { + asker.sendMessage(String.format("The player (%s%s%s) does not have the required teleport permission (%s%s%s) to use %s/mvtp %s%s.", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.GREEN, "multiverse.teleport.self." + d.getIdentifier(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + } else { + asker.sendMessage(String.format("The player (%s%s%s) has the required teleport permission (%s%s%s) to use %s/mvtp %s%s.", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.GREEN, "multiverse.teleport.self." + d.getIdentifier(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + } + if (!this.hasPermission(p, "multiverse.teleport.other." + d.getIdentifier(), false)) { + asker.sendMessage(String.format("The player (%s%s%s) does not have the required teleport permission (%s%s%s) to send others to %s%s%s via mvtp.", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.GREEN, "multiverse.teleport.other." + d.getIdentifier(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + } else { + asker.sendMessage(String.format("The player (%s%s%s) has required teleport permission (%s%s%s) to send others to %s%s%s via mvtp.", + ChatColor.AQUA, p.getDisplayName(), ChatColor.WHITE, + ChatColor.GREEN, "multiverse.teleport.other." + d.getIdentifier(), ChatColor.WHITE, + ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE)); + } + } + /** * Check to see if a player has a permission. * @@ -160,17 +236,8 @@ public class MVPermissions implements PermissionsInterface { if (node.equals("")) { return true; } - boolean hasPermission = checkActualPermission(sender, node); - // I consider this a workaround. At the moment, when we add a node AND recalc the permissions, until the perms - // plugin reloads, when MV asks the API if a player has a perm, it reports that they do NOT. - // For the moment, we're going to check all of this node's parents to see if the user has those. It stops - // when if finds a true or there are no more parents. --FF -// if (!hasPermission) { -// hasPermission = this.hasAnyParentPermission(sender, node); -// } - - return hasPermission; + return checkActualPermission(sender, node); } // TODO: Better player checks, most likely not needed, but safer.