From 599bbcd16c0a8b78eed2761db3d0a67f3685dbca Mon Sep 17 00:00:00 2001 From: Eric Stokes Date: Thu, 2 Jun 2011 10:10:20 -0400 Subject: [PATCH] Made DestinationType enum public --- .../command/commands/TeleportCommand.java | 39 ++++++++++++------- src/com/onarandombox/utils/Destination.java | 14 ++++--- .../onarandombox/utils/DestinationType.java | 5 +++ 3 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 src/com/onarandombox/utils/DestinationType.java diff --git a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java index 2f21910d..e4394488 100644 --- a/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java +++ b/src/com/onarandombox/MultiverseCore/command/commands/TeleportCommand.java @@ -6,9 +6,11 @@ import org.bukkit.entity.Player; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.command.BaseCommand; +import com.onarandombox.utils.Destination; +import com.onarandombox.utils.DestinationType; public class TeleportCommand extends BaseCommand { - + public TeleportCommand(MultiverseCore plugin) { super(plugin); name = "Teleport"; @@ -18,22 +20,31 @@ public class TeleportCommand extends BaseCommand { maxArgs = 1; identifiers.add("mvtp"); } - - @Override - public void execute(CommandSender sender, String[] args) { - // Check if the command was sent from a Player. - if(sender instanceof Player) { - Player p = (Player) sender; + + @Override + public void execute(CommandSender sender, String[] args) { + // Check if the command was sent from a Player. + if (sender instanceof Player) { + Player p = (Player) sender; // If this command was sent from a Player then we need to check Permissions if (!(plugin.ph.has((p), "multiverse.tp"))) { - sender.sendMessage("You do not have access to this command."); + p.sendMessage("You do not have access to this command."); return; } + Destination d = Destination.parseDestination(args[1]); + // TODO: I'd like to find a way to do these next bits inside Destination, so we're always valid --FF + // TODO: Support portals, but I didn't see the portals list --FF + if (this.plugin.worlds.containsKey(d.getName().toLowerCase())) { + if(d.getType() == DestinationType.World) { + + } + } else { + p.sendMessage("That was not a valid world (portals aren't yet supported)"); + } - - } else { - sender.sendMessage("This command needs to be used from a Player."); - } - } - + } else { + sender.sendMessage("This command needs to be used from a Player."); + } + } + } diff --git a/src/com/onarandombox/utils/Destination.java b/src/com/onarandombox/utils/Destination.java index df829fa4..a881534b 100644 --- a/src/com/onarandombox/utils/Destination.java +++ b/src/com/onarandombox/utils/Destination.java @@ -1,10 +1,7 @@ package com.onarandombox.utils; -enum DestinationType { - World, Portal, Invalid -} - public class Destination { + private String name; private DestinationType type; @@ -31,9 +28,16 @@ public class Destination { } String[] items = dest.split(":"); - if (items.length != 2) { + if (items.length > 1) { return getBadDestination(); } + + // If we only found one param, assume world + // TODO: Check for a valid world + if (items.length == 0) { + return new Destination(items[0], DestinationType.World); + } + if (items[0].equalsIgnoreCase("w")) { return new Destination(items[1], DestinationType.World); } else if (items[0].equalsIgnoreCase("p")) { diff --git a/src/com/onarandombox/utils/DestinationType.java b/src/com/onarandombox/utils/DestinationType.java new file mode 100644 index 00000000..a9f92534 --- /dev/null +++ b/src/com/onarandombox/utils/DestinationType.java @@ -0,0 +1,5 @@ +package com.onarandombox.utils; + +public enum DestinationType { + World, Portal, Invalid +}