    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 int func_82362_a()
    014        {
    015            return 2;
    016        }
    017
    018        public String getCommandUsage(ICommandSender par1ICommandSender)
    019        {
    020            return par1ICommandSender.translateString("commands.tp.usage", new Object[0]);
    021        }
    022
    023        public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    024        {
    025            if (par2ArrayOfStr.length < 1)
    026            {
    027                throw new WrongUsageException("commands.tp.usage", new Object[0]);
    028            }
    029            else
    030            {
    031                EntityPlayerMP var3;
    032
    033                if (par2ArrayOfStr.length != 2 && par2ArrayOfStr.length != 4)
    034                {
    035                    var3 = getCommandSenderAsPlayer(par1ICommandSender);
    036                }
    037                else
    038                {
    039                    var3 = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    040
    041                    if (var3 == null)
    042                    {
    043                        throw new PlayerNotFoundException();
    044                    }
    045                }
    046
    047                if (par2ArrayOfStr.length != 3 && par2ArrayOfStr.length != 4)
    048                {
    049                    if (par2ArrayOfStr.length == 1 || par2ArrayOfStr.length == 2)
    050                    {
    051                        EntityPlayerMP var11 = func_82359_c(par1ICommandSender, par2ArrayOfStr[par2ArrayOfStr.length - 1]);
    052
    053                        if (var11 == null)
    054                        {
    055                            throw new PlayerNotFoundException();
    056                        }
    057
    058                        var3.playerNetServerHandler.setPlayerLocation(var11.posX, var11.posY, var11.posZ, var11.rotationYaw, var11.rotationPitch);
    059                        notifyAdmins(par1ICommandSender, "commands.tp.success", new Object[] {var3.getEntityName(), var11.getEntityName()});
    060                    }
    061                }
    062                else if (var3.worldObj != null)
    063                {
    064                    int var4 = par2ArrayOfStr.length - 3;
    065                    double var5 = this.func_82368_a(par1ICommandSender, var3.posX, par2ArrayOfStr[var4++]);
    066                    double var7 = this.func_82367_a(par1ICommandSender, var3.posY, par2ArrayOfStr[var4++], 0, 0);
    067                    double var9 = this.func_82368_a(par1ICommandSender, var3.posZ, par2ArrayOfStr[var4++]);
    068                    var3.setPositionAndUpdate(var5, var7, var9);
    069                    notifyAdmins(par1ICommandSender, "commands.tp.success.coordinates", new Object[] {var3.getEntityName(), Double.valueOf(var5), Double.valueOf(var7), Double.valueOf(var9)});
    070                }
    071            }
    072        }
    073
    074        private double func_82368_a(ICommandSender par1ICommandSender, double par2, String par4Str)
    075        {
    076            return this.func_82367_a(par1ICommandSender, par2, par4Str, -30000000, 30000000);
    077        }
    078
    079        private double func_82367_a(ICommandSender par1ICommandSender, double par2, String par4Str, int par5, int par6)
    080        {
    081            boolean var7 = par4Str.startsWith("~");
    082            double var8 = var7 ? par2 : 0.0D;
    083
    084            if (!var7 || par4Str.length() > 1)
    085            {
    086                boolean var10 = par4Str.contains(".");
    087
    088                if (var7)
    089                {
    090                    par4Str = par4Str.substring(1);
    091                }
    092
    093                var8 += func_82363_b(par1ICommandSender, par4Str);
    094
    095                if (!var10 && !var7)
    096                {
    097                    var8 += 0.5D;
    098                }
    099            }
    100
    101            if (par5 != 0 || par6 != 0)
    102            {
    103                if (var8 < (double)par5)
    104                {
    105                    throw new NumberInvalidException("commands.generic.double.tooSmall", new Object[] {Double.valueOf(var8), Integer.valueOf(par5)});
    106                }
    107
    108                if (var8 > (double)par6)
    109                {
    110                    throw new NumberInvalidException("commands.generic.double.tooBig", new Object[] {Double.valueOf(var8), Integer.valueOf(par6)});
    111                }
    112            }
    113
    114            return var8;
    115        }
    116
    117        /**
    118         * Adds the strings available in this command to the given list of tab completion options.
    119         */
    120        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    121        {
    122            return par2ArrayOfStr.length != 1 && par2ArrayOfStr.length != 2 ? null : getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    123        }
    124
    125        public boolean func_82358_a(int par1)
    126        {
    127            return par1 == 0;
    128        }
    129    }