    001package net.minecraft.command;
    002
    003import java.util.List;
    004import net.minecraft.entity.player.EntityPlayerMP;
    005import net.minecraft.server.MinecraftServer;
    006import net.minecraft.util.ChunkCoordinates;
    007
    008public class CommandSetSpawnpoint extends CommandBase
    009{
    010    public String getCommandName()
    011    {
    012        return "spawnpoint";
    013    }
    014
    015    /**
    016     * Return the required permission level for this command.
    017     */
    018    public int getRequiredPermissionLevel()
    019    {
    020        return 2;
    021    }
    022
    023    public String getCommandUsage(ICommandSender par1ICommandSender)
    024    {
    025        return par1ICommandSender.translateString("commands.spawnpoint.usage", new Object[0]);
    026    }
    027
    028    public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    029    {
    030        EntityPlayerMP entityplayermp = par2ArrayOfStr.length == 0 ? getCommandSenderAsPlayer(par1ICommandSender) : func_82359_c(par1ICommandSender, par2ArrayOfStr[0]);
    031
    032        if (par2ArrayOfStr.length == 4)
    033        {
    034            if (entityplayermp.worldObj != null)
    035            {
    036                byte b0 = 1;
    037                int i = 30000000;
    038                int j = b0 + 1;
    039                int k = parseIntBounded(par1ICommandSender, par2ArrayOfStr[b0], -i, i);
    040                int l = parseIntBounded(par1ICommandSender, par2ArrayOfStr[j++], 0, 256);
    041                int i1 = parseIntBounded(par1ICommandSender, par2ArrayOfStr[j++], -i, i);
    042                entityplayermp.setSpawnChunk(new ChunkCoordinates(k, l, i1), true);
    043                notifyAdmins(par1ICommandSender, "commands.spawnpoint.success", new Object[] {entityplayermp.getEntityName(), Integer.valueOf(k), Integer.valueOf(l), Integer.valueOf(i1)});
    044            }
    045        }
    046        else
    047        {
    048            if (par2ArrayOfStr.length > 1)
    049            {
    050                throw new WrongUsageException("commands.spawnpoint.usage", new Object[0]);
    051            }
    052
    053            ChunkCoordinates chunkcoordinates = entityplayermp.getPlayerCoordinates();
    054            entityplayermp.setSpawnChunk(chunkcoordinates, true);
    055            notifyAdmins(par1ICommandSender, "commands.spawnpoint.success", new Object[] {entityplayermp.getEntityName(), Integer.valueOf(chunkcoordinates.posX), Integer.valueOf(chunkcoordinates.posY), Integer.valueOf(chunkcoordinates.posZ)});
    056        }
    057    }
    058
    059    /**
    060     * Adds the strings available in this command to the given list of tab completion options.
    061     */
    062    public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr)
    063    {
    064        return par2ArrayOfStr.length != 1 && par2ArrayOfStr.length != 2 ? null : getListOfStringsMatchingLastWord(par2ArrayOfStr, MinecraftServer.getServer().getAllUsernames());
    065    }
    066
    067    /**
    068     * Return whether the specified command parameter index is a username parameter.
    069     */
    070    public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2)
    071    {
    072        return par2 == 0;
    073    }
    074}