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