From 4effff9145a7c0174ddf267dbd52947c3940528c Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Sun, 26 Jun 2011 16:25:53 -0600 Subject: [PATCH] Allow players to mvtp other players Added permissions node: multiverse.world.tp.other/self --- .../command/commands/SpawnCommand.java | 2 +- .../command/commands/TeleportCommand.java | 62 ++++++++++++++----- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java index 6e2e54b2..e196c10f 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/SpawnCommand.java @@ -29,7 +29,7 @@ public class SpawnCommand extends BaseCommand { } // If a persons name was passed in, you must be A. the console, or B have permissions if (args.length == 1) { - if(commandSender != null && !this.plugin.ph.hasPermission(commandSender, "multiverse.world.spawn.self", true)) { + if(commandSender != null && !this.plugin.ph.hasPermission(commandSender, "multiverse.world.spawn.other", true)) { sender.sendMessage("You don't have permission to teleport another player to spawn."); return; } diff --git a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java index 0a69e792..24813660 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java @@ -30,26 +30,58 @@ public class TeleportCommand extends BaseCommand { @Override public void execute(CommandSender sender, String[] args) { // Check if the command was sent from a Player. + Player teleporter = null; + Player teleportee = null; if (sender instanceof Player) { - Player p = (Player) sender; - Destination d = Destination.parseDestination(args[0], this.plugin); - if (d.getType() == DestinationType.World) { - if (!this.plugin.ph.canEnterWorld(p, this.plugin.getServer().getWorld(d.getName()))) { - p.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there..."); - return; - } else if (!this.plugin.ph.canTravelFromWorld(p, this.plugin.getServer().getWorld(d.getName()))) { - p.sendMessage("DOH! Doesn't look like you can get to " + ChatColor.RED + d.getName() + " from " + ChatColor.GREEN + p.getWorld().getName()); - return; - } - Location l = this.playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation()); - p.teleport(l); - } else { - p.sendMessage("That was not a valid world."); + teleporter = (Player) sender; + } + + String worldName; + + if (args.length == 2) { + if (teleporter != null && !this.plugin.ph.hasPermission(sender, "multiverse.world.tp.other", true)) { + sender.sendMessage("You don't have permission to teleport another player."); + return; } + teleportee = this.plugin.getServer().getPlayer(args[0]); + if (teleportee == null) { + sender.sendMessage("Sorry, I couldn't find player: " + args[0]); + return; + } + worldName = args[1]; } else { - sender.sendMessage(this.IN_GAME_COMMAND_MSG); + worldName = args[0]; + + if (!(sender instanceof Player)) { + sender.sendMessage("You can only teleport other players from the command line."); + return; + } + teleporter = (Player) sender; + teleportee = (Player) sender; } + + Destination d = Destination.parseDestination(worldName, this.plugin); + if (!(d.getType() == DestinationType.World)) { + sender.sendMessage("Multiverse does not know about this world: " + worldName); + return; + } + + if (teleporter != null && !this.plugin.ph.canEnterWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { + if (teleportee.equals(teleporter)) { + teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there..."); + } else { + teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD + teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there..."); + } + } else if (teleporter != null && !this.plugin.ph.canTravelFromWorld(teleporter, this.plugin.getServer().getWorld(d.getName()))) { + if (teleportee.equals(teleporter)) { + teleporter.sendMessage("DOH! Doesn't look like you can get to " + ChatColor.RED + d.getName() + " from " + ChatColor.GREEN + teleporter.getWorld().getName()); + } else { + teleporter.sendMessage("DOH! Doesn't look like " + ChatColor.GREEN + teleporter.getWorld().getName() + " can get to " + ChatColor.RED + d.getName() + " from where they are..."); + } + } + Location l = this.playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation()); + teleporter.teleport(l); } }