    001    package net.minecraft.src;
    002
    003    import java.util.List;
    004    import net.minecraft.server.MinecraftServer;
    005
    006    public class CommandServerTp extends CommandBase
    007    {
    008        public String getCommandName()
    009        {
    010            return "tp";
    011        }
    012
    013        public String getCommandUsage(ICommandSender par1ICommandSender)
    014        {
    015            return par1ICommandSender.translateString("commands.tp.usage", new Object[0]);
    016        }
    017
    018        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    019        {
    020            if (par2ArrayOfStr.length < 1)
    021            {
    022                throw new WrongUsageException("commands.tp.usage", new Object[0]);
    023            }
    024            else
    025            {
    026                MinecraftServer var3 = MinecraftServer.getServer();
    027                EntityPlayerMP var4;
    028
    029                if (par2ArrayOfStr.length != 2 && par2ArrayOfStr.length != 4)
    030                {
    031                    var4 = (EntityPlayerMP)getCommandSenderAsPlayer(par1ICommandSender);
    032                }
    033                else
    034                {
    035                    var4 = var3.getConfigurationManager().getPlayerForUsername(par2ArrayOfStr[0]);
    036
    037                    if (var4 == null)
    038                    {
    039                        throw new PlayerNotFoundException();
    040                    }
    041                }
    042
    043                if (par2ArrayOfStr.length != 3 && par2ArrayOfStr.length != 4)
    044                {
    045                    if (par2ArrayOfStr.length == 1 || par2ArrayOfStr.length == 2)
    046                    {
    047                        EntityPlayerMP var10 = var3.getConfigurationManager().getPlayerForUsername(par2ArrayOfStr[par2ArrayOfStr.length - 1]);
    048
    049                        if (var10 == null)
    050                        {
    051                            throw new PlayerNotFoundException();
    052                        }
    053
    054                        var4.playerNetServerHandler.setPlayerLocation(var10.posX, var10.posY, var10.posZ, var10.rotationYaw, var10.rotationPitch);
    055                        notifyAdmins(par1ICommandSender, "commands.tp.success", new Object[] {var4.getEntityName(), var10.getEntityName()});
    056                    }
    057                }
    058                else if (var4.worldObj != null)
    059                {
    060                    int var5 = par2ArrayOfStr.length - 3;
    061                    int var6 = 30000000;
    062                    int var7 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[var5++], -var6, var6);
    063                    int var8 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[var5++], 0, 256);
    064                    int var9 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[var5++], -var6, var6);
    065                    var4.setPositionAndUpdate((double)((float)var7 + 0.5F), (double)var8, (double)((float)var9 + 0.5F));
    066                    notifyAdmins(par1ICommandSender, "commands.tp.coordinates", new Object[] {var4.getEntityName(), Integer.valueOf(var7), Integer.valueOf(var8), Integer.valueOf(var9)});
    067                }
    068            }
    069        }
    070
    071        /**
    072         * Adds the strings available in this command to the given list of tab completion options.
    073         */
    074        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    075        {
    076            return par2ArrayOfStr.length != 1 && par2ArrayOfStr.length != 2 ? null : getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    077        }
    078    }