    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                        if (var11.worldObj != var3.worldObj)
    062                        {
    063                            notifyAdmins(par1ICommandSender, "commands.tp.notSameDimension", new Object[0]);
    064                            return;
    065                        }
    066
    067                        var3.playerNetServerHandler.setPlayerLocation(var11.posX, var11.posY, var11.posZ, var11.rotationYaw, var11.rotationPitch);
    068                        notifyAdmins(par1ICommandSender, "commands.tp.success", new Object[] {var3.getEntityName(), var11.getEntityName()});
    069                    }
    070                }
    071                else if (var3.worldObj != null)
    072                {
    073                    int var4 = par2ArrayOfStr.length - 3;
    074                    double var5 = this.func_82368_a(par1ICommandSender, var3.posX, par2ArrayOfStr[var4++]);
    075                    double var7 = this.func_82367_a(par1ICommandSender, var3.posY, par2ArrayOfStr[var4++], 0, 0);
    076                    double var9 = this.func_82368_a(par1ICommandSender, var3.posZ, par2ArrayOfStr[var4++]);
    077                    var3.setPositionAndUpdate(var5, var7, var9);
    078                    notifyAdmins(par1ICommandSender, "commands.tp.success.coordinates", new Object[] {var3.getEntityName(), Double.valueOf(var5), Double.valueOf(var7), Double.valueOf(var9)});
    079                }
    080            }
    081        }
    082
    083        private double func_82368_a(ICommandSender par1ICommandSender, double par2, String par4Str)
    084        {
    085            return this.func_82367_a(par1ICommandSender, par2, par4Str, -30000000, 30000000);
    086        }
    087
    088        private double func_82367_a(ICommandSender par1ICommandSender, double par2, String par4Str, int par5, int par6)
    089        {
    090            boolean var7 = par4Str.startsWith("~");
    091            double var8 = var7 ? par2 : 0.0D;
    092
    093            if (!var7 || par4Str.length() > 1)
    094            {
    095                boolean var10 = par4Str.contains(".");
    096
    097                if (var7)
    098                {
    099                    par4Str = par4Str.substring(1);
    100                }
    101
    102                var8 += func_82363_b(par1ICommandSender, par4Str);
    103
    104                if (!var10 && !var7)
    105                {
    106                    var8 += 0.5D;
    107                }
    108            }
    109
    110            if (par5 != 0 || par6 != 0)
    111            {
    112                if (var8 < (double)par5)
    113                {
    114                    throw new NumberInvalidException("commands.generic.double.tooSmall", new Object[] {Double.valueOf(var8), Integer.valueOf(par5)});
    115                }
    116
    117                if (var8 > (double)par6)
    118                {
    119                    throw new NumberInvalidException("commands.generic.double.tooBig", new Object[] {Double.valueOf(var8), Integer.valueOf(par6)});
    120                }
    121            }
    122
    123            return var8;
    124        }
    125
    126        /**
    127         * Adds the strings available in this command to the given list of tab completion options.
    128         */
    129        public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    130        {
    131            return par2ArrayOfStr.length != 1 && par2ArrayOfStr.length != 2 ? null : getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    132        }
    133
    134        /**
    135         * Return whether the specified command parameter index is a username parameter.
    136         */
    137        public boolean isUsernameIndex(int par1)
    138        {
    139            return par1 == 0;
    140        }
    141    }