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